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>
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>
Sourcepub fn keygen_from_os_rng() -> Result<(PK, SK), SignatureError>
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>
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>
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
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>
fn keygen_from_seed(seed: &KeyMaterial<32>) -> Result<(PK, SK), SignatureError>
Source§fn keygen_from_seed_and_encoded(
seed: &KeyMaterial<32>,
encoded_sk: &[u8; SK_LEN],
) -> Result<(PK, SK), SignatureError>
fn keygen_from_seed_and_encoded( seed: &KeyMaterial<32>, encoded_sk: &[u8; SK_LEN], ) -> Result<(PK, SK), SignatureError>
Source§fn keypair_consistency_check(pk: &PK, sk: &SK) -> Result<(), SignatureError>
fn keypair_consistency_check(pk: &PK, sk: &SK) -> Result<(), SignatureError>
Source§fn compute_mu_from_tr(
tr: &[u8; 64],
msg: &[u8],
ctx: Option<&[u8]>,
) -> Result<[u8; 64], SignatureError>
fn compute_mu_from_tr( tr: &[u8; 64], msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>
Source§fn compute_mu_from_pk(
pk: &impl MLDSAPublicKeyTrait<k, l, PK_LEN>,
msg: &[u8],
ctx: Option<&[u8]>,
) -> Result<[u8; 64], SignatureError>
fn compute_mu_from_pk( pk: &impl MLDSAPublicKeyTrait<k, l, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>
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>
fn compute_mu_from_sk( sk: &impl MLDSAPrivateKeyTrait<k, l, ETA, SK_LEN, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; 64], SignatureError>
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>
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>
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>
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>
Source§fn sign_mu(
sk: &SK,
A_hat: Option<&Matrix<k, l>>,
mu: &[u8; 64],
) -> Result<[u8; SIG_LEN], SignatureError>
fn sign_mu( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], ) -> Result<[u8; SIG_LEN], SignatureError>
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>
fn sign_mu_out( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], output: &mut [u8; SIG_LEN], ) -> Result<usize, SignatureError>
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 moreSource§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>
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>
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>
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>
Source§fn sign_mu_deterministic(
sk: &SK,
A_hat: Option<&Matrix<k, l>>,
mu: &[u8; 64],
rnd: [u8; 32],
) -> Result<[u8; SIG_LEN], SignatureError>
fn sign_mu_deterministic( sk: &SK, A_hat: Option<&Matrix<k, l>>, mu: &[u8; 64], rnd: [u8; 32], ) -> Result<[u8; SIG_LEN], SignatureError>
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>
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>
Source§fn sign_mu_deterministic_from_seed(
seed: &KeyMaterial<32>,
mu: &[u8; 64],
rnd: [u8; 32],
) -> Result<[u8; SIG_LEN], SignatureError>
fn sign_mu_deterministic_from_seed( seed: &KeyMaterial<32>, mu: &[u8; 64], rnd: [u8; 32], ) -> Result<[u8; SIG_LEN], SignatureError>
Source§fn set_signer_rnd(&mut self, rnd: [u8; 32])
fn set_signer_rnd(&mut self, rnd: [u8; 32])
Source§fn sign_init_from_seed(
seed: &KeyMaterial<32>,
ctx: Option<&[u8]>,
) -> Result<Self, SignatureError>
fn sign_init_from_seed( seed: &KeyMaterial<32>, ctx: Option<&[u8]>, ) -> Result<Self, SignatureError>
Source§fn verify_with_expanded_key(
pk: &MLDSAPublicKeyExpanded<k, l, PK, PK_LEN>,
msg: &[u8],
ctx: Option<&[u8]>,
sig: &[u8],
) -> Result<(), SignatureError>
fn verify_with_expanded_key( pk: &MLDSAPublicKeyExpanded<k, l, PK, PK_LEN>, msg: &[u8], ctx: Option<&[u8]>, sig: &[u8], ) -> Result<(), SignatureError>
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>
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>
fn keygen() -> Result<(PK, SK), SignatureError>
Source§fn sign(
sk: &SK,
msg: &[u8],
ctx: Option<&[u8]>,
) -> Result<[u8; SIG_LEN], SignatureError>
fn sign( sk: &SK, msg: &[u8], ctx: Option<&[u8]>, ) -> Result<[u8; SIG_LEN], SignatureError>
msg and ctx accept zero-length byte arrays. Read more