pub struct SecretKey768 { /* private fields */ }Expand description
ML-KEM-768 decapsulation key (secret key) as defined in FIPS 203.
A key is created with SecretKey768::generate (fresh random key) or
SecretKey768::generate_derand (deterministic, for test vectors).
§Example
use crypto::mlkem::SecretKey768;
let (secret_key, public_key) = SecretKey768::generate_derand(&[0u8; 64]);
let (shared_secret, ciphertext) = public_key.encapsulate_derand(&[0u8; 32]);
let decapsulated = secret_key.decapsulate(&ciphertext).unwrap();
assert_eq!(shared_secret, decapsulated);Implementations§
Source§impl SecretKey768
impl SecretKey768
pub fn from_bytes(bytes: &[u8; 2400]) -> Self
pub fn to_bytes(&self) -> [u8; 2400]
Sourcepub fn generate() -> Result<(Self, PublicKey768), MlKemError>
pub fn generate() -> Result<(Self, PublicKey768), MlKemError>
Generates a fresh random keypair.
Returns MlKemError::Random when the operating system’s random
number generator is unavailable or fails.
pub fn generate_derand(coins: &[u8; 64]) -> (Self, PublicKey768)
Sourcepub fn decapsulate(
&self,
ciphertext: &[u8; 1088],
) -> Result<[u8; 32], MlKemError>
pub fn decapsulate( &self, ciphertext: &[u8; 1088], ) -> Result<[u8; 32], MlKemError>
Decapsulates ciphertext, recovering the shared secret encapsulated in it.
Implements the FIPS 203 implicit-rejection transform: a ciphertext that does not re-encrypt to itself does not produce an error, but instead yields a pseudorandom shared secret derived from the key and ciphertext.
Returns MlKemError::InvalidKey if this key fails the FIPS 203
decapsulation-key check, i.e. the hash of its embedded encapsulation key
does not match the hash stored in the key.