Skip to main content

MLKEMTrait

Trait MLKEMTrait 

Source
pub trait MLKEMTrait<const PK_LEN: usize, const SK_LEN: usize, const CT_LEN: usize, const SS_LEN: usize, PK: MLKEMPublicKeyTrait<k, PK_LEN> + MLKEMPublicKeyInternalTrait<k, PK_LEN>, SK: MLKEMPrivateKeyTrait<k, PK, SK_LEN, PK_LEN> + MLKEMPrivateKeyInternalTrait<k, PK, SK_LEN, PK_LEN>, const k: usize, const eta: i16, const du: i16, const dv: i16, const LAMBDA: i16>: Sized {
    // Required methods
    fn keygen_from_seed(seed: &KeyMaterial<64>) -> Result<(PK, SK), KEMError>;
    fn keygen_from_seed_and_encoded(
        seed: &KeyMaterial<64>,
        encoded_sk: &[u8; SK_LEN],
    ) -> Result<(PK, SK), KEMError>;
    fn keypair_consistency_check(pk: &PK, sk: &SK) -> Result<(), KEMError>;
    fn encaps_for_expanded_key(
        pk: &MLKEMPublicKeyExpanded<k, PK, PK_LEN>,
    ) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>;
    fn decaps_with_expanded_key(
        sk: &MLKEMPrivateKeyExpanded<k, PK, SK, SK_LEN, PK_LEN>,
        ct: &[u8],
    ) -> Result<KeyMaterial<SS_LEN>, KEMError>;
}
Expand description

Trait for all three of the ML-DSA algorithm variants.

Required Methods§

Source

fn keygen_from_seed(seed: &KeyMaterial<64>) -> Result<(PK, SK), KEMError>

Imports a secret key from a seed.

Source

fn keygen_from_seed_and_encoded( seed: &KeyMaterial<64>, encoded_sk: &[u8; SK_LEN], ) -> Result<(PK, SK), KEMError>

Imports a secret key from both a seed and an encoded_sk.

This is a convenience function to expand the key from seed and compare it against the provided encoded_sk using a constant-time equality check. If everything checks out, the secret key is returned fully populated with pk and seed. If the provided key and derived key don’t match, an error is returned.

Source

fn keypair_consistency_check(pk: &PK, sk: &SK) -> Result<(), KEMError>

Given a public key and a secret key, check that the public key matches the secret key. This is a sanity check that the public key was generated correctly from the secret key.

At the current time, this is only possible if sk either contains a public key (in which case the two pk’s are encoded and compared for byte equality), or if sk contains a seed (in which case a keygen_from_seed is run and then the pk’s compared).

Returns either () or KEMError::ConsistencyCheckFailed.

Source

fn encaps_for_expanded_key( pk: &MLKEMPublicKeyExpanded<k, PK, PK_LEN>, ) -> Result<(KeyMaterial<SS_LEN>, [u8; CT_LEN]), KEMError>

Same as KEM::encaps, but acts on an MLKEMPublicKeyExpanded.

Source

fn decaps_with_expanded_key( sk: &MLKEMPrivateKeyExpanded<k, PK, SK, SK_LEN, PK_LEN>, ct: &[u8], ) -> Result<KeyMaterial<SS_LEN>, KEMError>

Same as KEM::decaps, but acts on an MLKEMPrivateKeyExpanded.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<const PK_LEN: usize, const SK_LEN: usize, const CT_LEN: usize, const SS_LEN: usize, PK: MLKEMPublicKeyTrait<k, PK_LEN> + MLKEMPublicKeyInternalTrait<k, PK_LEN>, SK: MLKEMPrivateKeyTrait<k, PK, SK_LEN, PK_LEN> + MLKEMPrivateKeyInternalTrait<k, PK, SK_LEN, PK_LEN>, const k: usize, const eta1: i16, const du: i16, const dv: i16, const LAMBDA: i16> MLKEMTrait<PK_LEN, SK_LEN, CT_LEN, SS_LEN, PK, SK, k, eta1, du, dv, LAMBDA> for MLKEM<PK_LEN, SK_LEN, CT_LEN, SS_LEN, PK, SK, k, eta1, du, dv, LAMBDA>