Skip to main content

MlDsa87SecretKey

Struct MlDsa87SecretKey 

Source
pub struct MlDsa87SecretKey { /* private fields */ }
Expand description

An expanded ML-DSA-87 secret key.

This is the only way to sign. Key generation runs once, in MlDsa87SecretKey::new or MlDsa87SecretKey::generate, and the resulting matrix A and secret vectors in the NTT domain are cached, so signing does not repeat the expensive key generation.

The key is a plain fixed-size value (about ML_DSA_87_SECRET_KEY_SIZE bytes) that never allocates, which makes it usable on no_std and embedded targets.

Secrets are zeroized on drop when the zeroize feature is enabled.

Implementations§

Source§

impl MlDsa87SecretKey

Source

pub fn new(seed: &[u8; 32]) -> Self

Expands seed into a secret key, running the full FIPS 204 key generation and caching the NTT-domain matrix and secret vectors.

Source

pub fn generate() -> Self

Generates a random secret key.

The seed can be retrieved afterwards with MlDsa87SecretKey::seed so it can be persisted.

Source

pub fn public_key(&self) -> MlDsa87PublicKey

Returns the public key for this secret key.

Source

pub fn seed(&self) -> &[u8; 32]

Returns the 32-byte seed this key was initialized from.

Source

pub fn sign(&self, message: &[u8], ctx: &[u8]) -> Result<[u8; 4627], MlDsaError>

Signs message with a fresh random nonce.

ctx is the optional FIPS 204 context string and must be at most 255 bytes; it returns MlDsaError::ContextTooLong otherwise.

Source

pub fn sign_derand( &self, message: &[u8], ctx: &[u8], rnd: &[u8; 32], ) -> Result<[u8; 4627], MlDsaError>

Signs message deterministically for a fixed 32-byte rnd.

Passing rnd = [0u8; 32] gives the deterministic FIPS 204 variant; any other value gives the hedged/randomized variant. ctx must be at most 255 bytes, returning MlDsaError::ContextTooLong otherwise.

Source

pub fn sign_external_mu(&self, mu: &[u8; 64]) -> [u8; 4627]

Signs a precomputed 64-byte message representative mu (FIPS 204 “external mu” signing) with a fresh random nonce.

mu must be the output of the FIPS 204 message-representative computation; this function performs no domain separation or hashing.

Source

pub fn sign_external_mu_derand( &self, mu: &[u8; 64], rnd: &[u8; 32], ) -> [u8; 4627]

Signs a precomputed 64-byte message representative mu (FIPS 204 “external mu” signing) deterministically for a fixed rnd.

Trait Implementations§

Source§

impl Debug for MlDsa87SecretKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.