#![no_std]
#![deny(missing_docs)]
#![deny(unsafe_code)]
pub mod auth;
pub mod cast;
pub mod csp;
pub mod error;
pub mod integrity;
pub mod integrity_data;
#[cfg(feature = "fips_140_3")]
pub mod kat;
pub mod pct;
pub mod preop;
pub mod state;
#[cfg(feature = "ml-dsa")]
pub mod ml_dsa;
#[cfg(feature = "ml-kem")]
pub mod ml_kem;
#[cfg(feature = "ml-kem")]
pub use ml_kem::{
decapsulate as kyber_decapsulate_internal, encapsulate as kyber_encapsulate_internal,
generate_key_pair as kyber_generate_key_pair_internal, KyberCiphertext, KyberKeypair,
KyberPrivateKey, KyberPublicKey, KyberSharedSecret,
};
#[cfg(any(feature = "ml-kem", feature = "ml-dsa"))]
use auth::{check_authority, Role};
#[cfg(feature = "ml-kem")]
pub fn kyber_generate_key_pair(seed: [u8; 64]) -> Result<KyberKeypair> {
check_authority(Role::User)?;
Ok(kyber_generate_key_pair_internal(seed))
}
#[cfg(feature = "ml-kem")]
pub fn encapsulate(
pk: &KyberPublicKey,
randomness: [u8; 32],
) -> Result<(KyberCiphertext, KyberSharedSecret)> {
check_authority(Role::User)?;
Ok(kyber_encapsulate_internal(pk, randomness))
}
#[cfg(feature = "ml-kem")]
pub fn decapsulate(sk: &KyberPrivateKey, ct: &KyberCiphertext) -> Result<KyberSharedSecret> {
check_authority(Role::User)?;
Ok(kyber_decapsulate_internal(sk, ct))
}
#[cfg(feature = "ml-dsa")]
pub use ml_dsa::{
generate_key_pair as dilithium_generate_key_pair_internal, sign as dilithium_sign_internal,
verify as dilithium_verify_internal, DilithiumKeypair, DilithiumSignature, DilithiumSigningKey,
DilithiumVerifyingKey, FIPS_CONTEXT,
};
#[cfg(feature = "ml-dsa")]
pub fn dilithium_generate_key_pair(seed: [u8; 32]) -> Result<DilithiumKeypair> {
check_authority(Role::User)?;
Ok(dilithium_generate_key_pair_internal(seed))
}
#[cfg(feature = "ml-dsa")]
pub fn dilithium_sign(
sk: &DilithiumSigningKey,
msg: &[u8],
ctx: &[u8],
randomness: [u8; 32],
) -> Result<DilithiumSignature> {
check_authority(Role::User)?;
dilithium_sign_internal(sk, msg, ctx, randomness).map_err(|_| PqcError::FipsErrorState)
}
#[cfg(feature = "ml-dsa")]
pub fn dilithium_verify(
pk: &DilithiumVerifyingKey,
msg: &[u8],
ctx: &[u8],
sig: &DilithiumSignature,
) -> Result<()> {
check_authority(Role::User)?;
dilithium_verify_internal(pk, msg, ctx, sig).map_err(|_| PqcError::FipsErrorState)
}
pub const ML_KEM_1024_PK_BYTES: usize = 1568;
pub const ML_KEM_1024_SK_BYTES: usize = 3168;
pub const ML_KEM_1024_CT_BYTES: usize = 1568;
pub const ML_KEM_1024_SS_BYTES: usize = 32;
pub const ML_DSA_65_PK_BYTES: usize = 1952;
pub const ML_DSA_65_SK_BYTES: usize = 4032;
pub const ML_DSA_65_SIG_BYTES: usize = 3309;
pub use error::{PqcError, Result};
#[cfg(feature = "ml-kem")]
pub use pct::kyber_pct;
#[cfg(feature = "ml-dsa")]
pub use pct::dilithium_pct;
pub use preop::{run_post, run_post_or_panic};
pub use state::{get_fips_state, is_operational, FipsState};
#[cfg(feature = "ml-kem")]
pub use KyberPrivateKey as KyberSecretKey;