Skip to main content

MLDSA

Struct MLDSA 

Source
pub struct MLDSA<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK: MLDSAPublicKeyTrait<k, l, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>, SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> { /* private fields */ }
Expand description

The core internal implementation of the ML-DSA algorithm. This needs to be public for the compiler to be able to find it, but you shouldn’t ever need to use this directly. Please use the named public types.

Implementations§

Source§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK: MLDSAPublicKeyTrait<k, l, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>, SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_Z_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_Z_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>

Source

pub fn keygen_from_os_rng() -> Result<(PK, SK), SignatureError>

Should still be ok in FIPS mode

Trait Implementations§

Source§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK: MLDSAPublicKeyTrait<k, l, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>, SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_Z_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> MLDSATrait<PK_LEN, SK_LEN, SIG_LEN, PK, SK, k, l, ETA> for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_Z_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>

Source§

fn sign_mu_deterministic_from_seed_out( seed: &KeyMaterial<32>, mu: &[u8; 64], rnd: [u8; 32], output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

This function is a mash-up of keyGen (Algorithm 6) and sign (Algorithm 7) Although, while this algorithm is a precursor to the lowmemory implementation, I’m not sure that it actually gains you anything over a keygen_from_seed() followed by a sign(), and maybe I should change its implementation to that.

Source§

fn verify_mu_internal( pk: &PK, A_hat: &Matrix<k, l>, mu: &[u8; 64], sig: &[u8; SIG_LEN], ) -> bool

Algorithm 8 ML-DSA.Verify_internal(𝑝𝑘, 𝑀′, 𝜎) Internal function to verify a signature 𝜎 for a formatted message 𝑀′ . Input: Public key 𝑝𝑘 ∈ 𝔹32+32𝑘(bitlen (𝑞−1)−𝑑) and message 𝑀′ ∈ {0, 1}∗ . Input: Signature 𝜎 ∈ 𝔹𝜆/4+ℓ⋅32⋅(1+bitlen (𝛾1−1))+𝜔+𝑘.

Source§

fn keygen_from_seed(seed: &KeyMaterial<32>) -> Result<(PK, SK), SignatureError>

Imports a secret key from a seed.
Source§

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

Imports a secret key from both a seed and an encoded_sk. Read more
Source§

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

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. Read more
Source§

fn compute_mu_from_tr( tr: &[u8; 64], msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>

This provides the first half of the “External Mu” interface to ML-DSA which is described in, and allowed under, NIST’s FAQ that accompanies FIPS 204. Read more
Source§

fn compute_mu_from_pk( pk: &impl MLDSAPublicKeyTrait<k, l, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>

Same as MLDSATrait::compute_mu_from_tr, but extracts tr from the public key.
Source§

fn compute_mu_from_sk( sk: &impl MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>

Same as MLDSATrait::compute_mu_from_tr, but extracts tr from the private key.
Source§

fn sign_with_expanded_key( sk: &MLDSAPrivateKeyExpanded<k, l, ETA, PK, SK, SK_LEN, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; SIG_LEN], SignatureError>

Same as Signature::sign, but signs from an MLDSAPrivateKeyExpanded.
Source§

fn sign_with_expanded_key_out( sk: &MLDSAPrivateKeyExpanded<k, l, ETA, PK, SK, SK_LEN, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, out: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Same as MLDSATrait::sign_with_expanded_key, but takes an output array.
Source§

fn sign_mu( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], ) -> Result<[u8; SIG_LEN], SignatureError>

Performs an ML-DSA signature using the provided external message representative mu. This implements FIPS 204 Algorithm 7 with line 6 removed; a modification that is allowed by both FIPS 204 itself, as well as subsequent FAQ documents. This mode uses randomized signing (called “hedged mode” in FIPS 204) using an internal RNG.
Source§

fn sign_mu_out( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Performs an ML-DSA signature using the provided external message representative mu. This implements FIPS 204 Algorithm 7 with line 6 removed; a modification that is allowed by both FIPS 204 itself, as well as subsequent FAQ documents. This mode uses randomized signing (called “hedged mode” in FIPS 204) using an internal RNG. Read more
Source§

fn sign_mu_with_expanded_key( sk: &MLDSAPrivateKeyExpanded<k, l, ETA, PK, SK, SK_LEN, PK_LEN>, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], ) -> Result<[u8; SIG_LEN], SignatureError>

Same as [Signature::sign_mu], but signs from an MLDSAPrivateKeyExpanded.
Source§

fn sign_mu_with_expanded_key_out( sk: &MLDSAPrivateKeyExpanded<k, l, ETA, PK, SK, SK_LEN, PK_LEN>, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], out: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Same as [Signature::sign_mu_out], but signs from an MLDSAPrivateKeyExpanded.
Source§

fn sign_mu_deterministic( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], rnd: [u8; 32], ) -> Result<[u8; SIG_LEN], SignatureError>

Algorithm 7 ML-DSA.Sign_internal(𝑠𝑘, 𝑀′, 𝑟𝑛𝑑) (modified to take an externally-computed mu instead of M’) Read more
Source§

fn sign_mu_deterministic_out( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], rnd: [u8; 32], output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Algorithm 7 ML-DSA.Sign_internal(𝑠𝑘, 𝑀′, 𝑟𝑛𝑑) (modified to take an externally-computed mu instead of M’) Read more
Source§

fn sign_mu_deterministic_from_seed( seed: &KeyMaterial<32>, mu: &[u8; 64], rnd: [u8; 32], ) -> Result<[u8; SIG_LEN], SignatureError>

This contains a heavily-optimized combined keygen() and sign() which greatly reduces peak memory usage by never having the full secret key in memory at the same time, and by deriving intermediate values piece-wise as needed.
Source§

fn set_signer_rnd(&mut self, rnd: [u8; 32])

To be used for deterministic signing in conjunction with the MLDSA44::sign_init, MLDSA44::sign_update, and MLDSA44::sign_final flow. Can be set anywhere after MLDSA44::sign_init and before MLDSA44::sign_final.
Source§

fn sign_init_from_seed( seed: &KeyMaterial<32>, ctx: Option<&[u8]>, ) -> Result<Self, SignatureError>

Alternative initialization of the streaming signer where you have your private key as a seed and you want to delay its expansion as late as possible for memory-usage reasons.
Source§

fn verify_with_expanded_key( pk: &MLDSAPublicKeyExpanded<k, l, PK, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, sig: &[u8], ) -> Result<(), SignatureError>

Same as Signature::verify, but signs from an expanded key object.
Source§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK: MLDSAPublicKeyTrait<k, l, PK_LEN> + MLDSAPublicKeyInternalTrait<k, PK_LEN>, SK: MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN> + MLDSAPrivateKeyInternalTrait<k, l, ETA, SK_LEN, PK_LEN>, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_Z_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> Signature<PK, SK, PK_LEN, SK_LEN, SIG_LEN> for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_Z_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>

Source§

fn keygen() -> Result<(PK, SK), SignatureError>

Generate a keypair. Error condition: Basically only on RNG failures
Source§

fn sign( sk: &SK, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; SIG_LEN], SignatureError>

Produce a signature for the provided message and context. Both the msg and ctx accept zero-length byte arrays. Read more
Source§

fn sign_out( sk: &SK, msg: &[u8], ctx: Option<&[u8]>, output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Returns the number of bytes written to the output buffer. Can be called with an oversized buffer.
Source§

fn sign_init(sk: &SK, ctx: Option<&[u8]>) -> Result<Self, SignatureError>

Initialize a signer for streaming mode with the provided private key.
Source§

fn sign_update(&mut self, msg_chunk: &[u8])

Update the signer with the next chunk of data. This can be called multiple times.
Source§

fn sign_final(self) -> Result<[u8; SIG_LEN], SignatureError>

Complete the signing operation. Consumes self.
Source§

fn sign_final_out( self, output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>

Returns the number of bytes written to the output buffer. Can be called with an oversized buffer.
Source§

fn verify( pk: &PK, msg: &[u8], ctx: Option<&[u8]>, sig: &[u8], ) -> Result<(), SignatureError>

On success, returns Ok(()) On failure, returns Err(SignatureError::SignatureVerificationFailed); may also return other types of SignatureError as appropriate (such as for invalid-length inputs).
Source§

fn verify_init(pk: &PK, ctx: Option<&[u8]>) -> Result<Self, SignatureError>

Source§

fn verify_update(&mut self, msg_chunk: &[u8])

Update the verifier with the next chunk of data. This can be called multiple times.
Source§

fn verify_final(self, sig: &[u8]) -> Result<(), SignatureError>

On success, returns Ok(()) On failure, returns Err(SignatureError::SignatureVerificationFailed); may also return other types of SignatureError as appropriate (such as for invalid-length inputs).

Auto Trait Implementations§

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> Freeze for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: Freeze, PK: Freeze,

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> RefUnwindSafe for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> Send for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: Send, PK: Send,

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> Sync for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: Sync, PK: Sync,

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> Unpin for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: Unpin, PK: Unpin,

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> UnsafeUnpin for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: UnsafeUnpin, PK: UnsafeUnpin,

§

impl<const PK_LEN: usize, const SK_LEN: usize, const SIG_LEN: usize, PK, SK, const TAU: i32, const LAMBDA: i32, const GAMMA1: i32, const GAMMA2: i32, const k: usize, const l: usize, const ETA: usize, const BETA: i32, const OMEGA: i32, const C_TILDE: usize, const POLY_VEC_H_PACKED_LEN: usize, const POLY_W1_PACKED_LEN: usize, const LAMBDA_over_4: usize, const GAMMA1_MASK_LEN: usize, const GAMMA1_MINUS_BETA: i32, const GAMMA2_MINUS_BETA: i32> UnwindSafe for MLDSA<PK_LEN, SK_LEN, SIG_LEN, PK, SK, TAU, LAMBDA, GAMMA1, GAMMA2, k, l, ETA, BETA, OMEGA, C_TILDE, POLY_VEC_H_PACKED_LEN, POLY_W1_PACKED_LEN, LAMBDA_over_4, GAMMA1_MASK_LEN, GAMMA1_MINUS_BETA, GAMMA2_MINUS_BETA>
where SK: UnwindSafe, PK: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.