pub struct SecretKey1024 { /* private fields */ }Expand description
ML-KEM-1024 decapsulation key (secret key) as defined in FIPS 203.
A key is created with SecretKey1024::generate (fresh random key) or
SecretKey1024::generate_derand (deterministic, for test vectors).
§Example
use crypto::mlkem::SecretKey1024;
let (secret_key, public_key) = SecretKey1024::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 SecretKey1024
impl SecretKey1024
Sourcepub fn from_bytes(bytes: &[u8; 3168]) -> Self
pub fn from_bytes(bytes: &[u8; 3168]) -> Self
Creates a decapsulation key from its FIPS 203 encoding.
The key is not validated here; use SecretKey1024::decapsulate, which
performs the FIPS 203 decapsulation-key check.
Sourcepub fn generate() -> Result<(Self, PublicKey1024), MlKemError>
pub fn generate() -> Result<(Self, PublicKey1024), MlKemError>
Generates a fresh random keypair.
Returns MlKemError::Random when the operating system’s random
number generator is unavailable or fails.
Sourcepub fn generate_derand(coins: &[u8; 64]) -> (Self, PublicKey1024)
pub fn generate_derand(coins: &[u8; 64]) -> (Self, PublicKey1024)
Generates a keypair deterministically from 64 bytes of coins.
The first 32 bytes seed the key generation matrix and the last 32 bytes
become the implicit-rejection secret. Useful for reproducing FIPS 203 /
ACVP test vectors; the same coins must not be reused for a real key.
Sourcepub fn decapsulate(
&self,
ciphertext: &[u8; 1568],
) -> Result<[u8; 32], MlKemError>
pub fn decapsulate( &self, ciphertext: &[u8; 1568], ) -> 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.
Sourcepub fn public_key(&self) -> PublicKey1024
pub fn public_key(&self) -> PublicKey1024
Returns the encapsulation key embedded in this decapsulation key.