Skip to main content

MLDSAPrivateKeyTrait

Trait MLDSAPrivateKeyTrait 

Source
pub trait MLDSAPrivateKeyTrait<const k: usize, const l: usize, const S1_PACKED_LEN: usize, const S2_PACKED_LEN: usize, const T1_PACKED_LEN: usize, const PK_LEN: usize, const SK_LEN: usize>: SignaturePrivateKey {
    // Required methods
    fn from_keymaterial(
        seed: &KeyMaterialSized<32>,
    ) -> Result<Self, SignatureError>;
    fn seed(&self) -> &KeyMaterialSized<32>;
    fn tr(&self) -> [u8; 64];
    fn derive_pk(&self) -> MLDSAPublicKey<k, T1_PACKED_LEN, PK_LEN>;
    fn sk_encode(&self) -> [u8; SK_LEN];
    fn sk_encode_out(&self, out: &mut [u8; SK_LEN]) -> usize;
    fn sk_decode(sk: &[u8; SK_LEN]) -> Self;
}
Expand description

General trait for all ML-DSA private keys types.

Required MethodsΒ§

Source

fn from_keymaterial(seed: &KeyMaterialSized<32>) -> Result<Self, SignatureError>

New from KeyMaterial. Can throw a SignatureError if the KeyMaterial does not contain sufficient entropy.

Source

fn seed(&self) -> &KeyMaterialSized<32>

Get a ref to the seed, if there is one stored with this private key

Source

fn tr(&self) -> [u8; 64]

Get a copy of the key hash tr. This is computationally intensive as it requires fully re-computing the public key (and then discarding it). It is highly recommended that if you already have a copy of the public key, get tr from that, or else compute tr once and store it.

Source

fn derive_pk(&self) -> MLDSAPublicKey<k, T1_PACKED_LEN, PK_LEN>

Returns the full public key, and has the side-effect of setting the public key hash tr in this MLDSASeedSK object.

Source

fn sk_encode(&self) -> [u8; SK_LEN]

Algorithm 24 skEncode(𝜌, 𝐾, π‘‘π‘Ÿ, 𝐬1, 𝐬2, 𝐭0) Encodes a secret key for ML-DSA into a byte string. Input: 𝜌 ∈ 𝔹32, 𝐾 ∈ 𝔹32, π‘‘π‘Ÿ ∈ 𝔹64 , 𝐬1 ∈ 𝑅ℓ with coefficients in [βˆ’πœ‚, πœ‚], 𝐬2 ∈ π‘…π‘˜ with coefficients in [βˆ’πœ‚, πœ‚], 𝐭0 ∈ π‘…π‘˜ with coefficients in [βˆ’2π‘‘βˆ’1 + 1, 2π‘‘βˆ’1]. Output: Private key π‘ π‘˜ ∈ 𝔹32+32+64+32β‹…((π‘˜+β„“)β‹…bitlen (2πœ‚)+π‘‘π‘˜).

Source

fn sk_encode_out(&self, out: &mut [u8; SK_LEN]) -> usize

Algorithm 24 skEncode(𝜌, 𝐾, π‘‘π‘Ÿ, 𝐬1, 𝐬2, 𝐭0) Encodes a secret key for ML-DSA into a byte string. Input: 𝜌 ∈ 𝔹32, 𝐾 ∈ 𝔹32, π‘‘π‘Ÿ ∈ 𝔹64 , 𝐬1 ∈ 𝑅ℓ with coefficients in [βˆ’πœ‚, πœ‚], 𝐬2 ∈ π‘…π‘˜ with coefficients in [βˆ’πœ‚, πœ‚], 𝐭0 ∈ π‘…π‘˜ with coefficients in [βˆ’2π‘‘βˆ’1 + 1, 2π‘‘βˆ’1]. Output: Private key π‘ π‘˜ ∈ 𝔹32+32+64+32β‹…((π‘˜+β„“)β‹…bitlen (2πœ‚)+π‘‘π‘˜).

Source

fn sk_decode(sk: &[u8; SK_LEN]) -> Self

Algorithm 25 skDecode(π‘ π‘˜) Reverses the procedure skEncode. Input: Private key π‘ π‘˜ ∈ 𝔹32+32+64+32β‹…((β„“+π‘˜)β‹…bitlen (2πœ‚)+π‘‘π‘˜). Output: 𝜌 ∈ 𝔹32, 𝐾 ∈ 𝔹32, π‘‘π‘Ÿ ∈ 𝔹64 , 𝐬1 ∈ 𝑅ℓ , 𝐬2 ∈ π‘…π‘˜ , 𝐭0 ∈ π‘…π‘˜ with coefficients in [βˆ’2π‘‘βˆ’1 + 1, 2π‘‘βˆ’1].

Note: this object contains only the simple decoding routine to unpack a semi-expanded key. See MLDSATrait for key generation functions, including derive-from-seed and consistency-check functions.

Dyn CompatibilityΒ§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

ImplementorsΒ§

SourceΒ§

impl<const LAMBDA: i32, const GAMMA2: i32, const k: usize, const l: usize, const eta: usize, const S1_PACKED_LEN: usize, const S2_PACKED_LEN: usize, const T1_PACKED_LEN: usize, const PK_LEN: usize, const SK_LEN: usize> MLDSAPrivateKeyTrait<k, l, S1_PACKED_LEN, S2_PACKED_LEN, T1_PACKED_LEN, PK_LEN, SK_LEN> for MLDSASeedPrivateKey<LAMBDA, GAMMA2, k, l, eta, S1_PACKED_LEN, S2_PACKED_LEN, T1_PACKED_LEN, PK_LEN, SK_LEN>