pub trait MLKEMPrivateKeyTrait<const k: usize, const SK_LEN: usize, const FULL_SK_LEN: usize, const PK_LEN: usize, const T_PACKED_LEN: usize>: KEMPrivateKey<SK_LEN> {
// Required methods
fn from_keymaterial(seed: &KeyMaterial<64>) -> Result<Self, KEMError>;
fn seed(&self) -> Option<KeyMaterial<64>>;
fn pk(&self) -> MLKEMPublicKey<k, PK_LEN, T_PACKED_LEN>;
fn pk_hash(&mut self) -> &[u8; 32];
fn encode_full_sk(&self) -> [u8; FULL_SK_LEN];
fn full_sk_encode_out(&self, out: &mut [u8; FULL_SK_LEN]) -> usize;
fn sk_decode(sk: &[u8; SK_LEN]) -> Self;
}Expand description
General trait for all ML-KEM private keys types.
Required Methods§
Sourcefn from_keymaterial(seed: &KeyMaterial<64>) -> Result<Self, KEMError>
fn from_keymaterial(seed: &KeyMaterial<64>) -> Result<Self, KEMError>
New from KeyMaterial. Can throw a KEMError if the KeyMaterial does not contain sufficient entropy.
Sourcefn seed(&self) -> Option<KeyMaterial<64>>
fn seed(&self) -> Option<KeyMaterial<64>>
Get a ref to the seed, which there always will be for a MLKEMSeedPrivateKey In this implementation, we always have a seed, so will always return Some.
Sourcefn pk(&self) -> MLKEMPublicKey<k, PK_LEN, T_PACKED_LEN>
fn pk(&self) -> MLKEMPublicKey<k, PK_LEN, T_PACKED_LEN>
Runs essentially a full keygen according to Algorithm 13.
Sourcefn pk_hash(&mut self) -> &[u8; 32]
fn pk_hash(&mut self) -> &[u8; 32]
Get a ref to the stored public key hash. Since in this implementation, this requires running the full keygen, this is a lazy evaluation and will only be computationally heavy the first time it is called for a given key. This requires a mutable copy. If you don’t have then, then you can compute the full public key via MLKEMPrivateKeyTrait::pk and then get the hash of that.
Sourcefn encode_full_sk(&self) -> [u8; FULL_SK_LEN]
fn encode_full_sk(&self) -> [u8; FULL_SK_LEN]
This produces the full private key in the encoding specified in FIPS 203 so that it is compatible with other implementations.
Note that since this encoding does not include the seed, this is a one-way operation; after exporting in this encoding, it will be impossible to re-import it into a MLKEMSeedPrivateKey.
As described on Algorithm 16 line 3: dk ← (dkPKE ‖ ek ‖ H(ek) ‖ 𝑧)
Sourcefn full_sk_encode_out(&self, out: &mut [u8; FULL_SK_LEN]) -> usize
fn full_sk_encode_out(&self, out: &mut [u8; FULL_SK_LEN]) -> usize
This produces the full private key in the encoding specified in FIPS 203 so that it is compatible with other implementations.
Note that since this encoding does not include the seed, this is a one-way operation; after exporting in this encoding, it will be impossible to re-import it into a MLKEMSeedPrivateKey.
As described on Algorithm 16 line 3: dk ← (dkPKE ‖ ek ‖ H(ek) ‖ 𝑧)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".