pub struct DilithiumKeyPair { /* private fields */ }Expand description
An ML-DSA key pair (private key + public key).
The private key bytes are automatically zeroized on drop (FIPS 204 §7).
Type aliases: MlDsaKeyPair (FIPS 204 naming) = DilithiumKeyPair (legacy).
Implementations§
Source§impl DilithiumKeyPair
impl DilithiumKeyPair
Sourcepub fn generate(mode: DilithiumMode) -> Result<Self, DilithiumError>
pub fn generate(mode: DilithiumMode) -> Result<Self, DilithiumError>
Generate a new key pair using OS entropy (FIPS 204 §6.1 KeyGen).
Requires the std or getrandom feature (enabled by default).
Sourcepub fn generate_deterministic(mode: DilithiumMode, seed: &[u8; 32]) -> Self
pub fn generate_deterministic(mode: DilithiumMode, seed: &[u8; 32]) -> Self
Generate a key pair deterministically from a seed.
Sourcepub fn sign(
&self,
msg: &[u8],
ctx: &[u8],
) -> Result<DilithiumSignature, DilithiumError>
pub fn sign( &self, msg: &[u8], ctx: &[u8], ) -> Result<DilithiumSignature, DilithiumError>
Sign a message using pure ML-DSA (FIPS 204 §6.1 ML-DSA.Sign).
Context string ctx is optional (max 255 bytes).
Requires the std or getrandom feature for randomized signing.
Sourcepub fn sign_prehash(
&self,
msg: &[u8],
ctx: &[u8],
) -> Result<DilithiumSignature, DilithiumError>
pub fn sign_prehash( &self, msg: &[u8], ctx: &[u8], ) -> Result<DilithiumSignature, DilithiumError>
Sign a message using HashML-DSA (FIPS 204 §6.2 HashML-DSA.Sign).
The message is internally hashed with SHA-512 before signing.
Context string ctx is optional (max 255 bytes).
Requires the std or getrandom feature for randomized signing.
Sourcepub fn sign_deterministic(
&self,
msg: &[u8],
ctx: &[u8],
rnd: &[u8; 32],
) -> Result<DilithiumSignature, DilithiumError>
pub fn sign_deterministic( &self, msg: &[u8], ctx: &[u8], rnd: &[u8; 32], ) -> Result<DilithiumSignature, DilithiumError>
Sign deterministically (for testing / reproducibility).
Sourcepub fn verify(
pk: &[u8],
sig: &DilithiumSignature,
msg: &[u8],
ctx: &[u8],
mode: DilithiumMode,
) -> bool
pub fn verify( pk: &[u8], sig: &DilithiumSignature, msg: &[u8], ctx: &[u8], mode: DilithiumMode, ) -> bool
Verify a pure ML-DSA signature (FIPS 204 §6.1 ML-DSA.Verify).
Sourcepub fn verify_prehash(
pk: &[u8],
sig: &DilithiumSignature,
msg: &[u8],
ctx: &[u8],
mode: DilithiumMode,
) -> bool
pub fn verify_prehash( pk: &[u8], sig: &DilithiumSignature, msg: &[u8], ctx: &[u8], mode: DilithiumMode, ) -> bool
Verify a HashML-DSA signature (FIPS 204 §6.2 HashML-DSA.Verify).
Sourcepub fn public_key(&self) -> &[u8] ⓘ
pub fn public_key(&self) -> &[u8] ⓘ
Get the encoded public key bytes.
Sourcepub fn private_key(&self) -> &[u8] ⓘ
pub fn private_key(&self) -> &[u8] ⓘ
Get the encoded private key bytes.
Sourcepub fn mode(&self) -> DilithiumMode
pub fn mode(&self) -> DilithiumMode
Get the security mode.
Sourcepub fn from_keys(
privkey: &[u8],
pubkey: &[u8],
mode: DilithiumMode,
) -> Result<Self, DilithiumError>
pub fn from_keys( privkey: &[u8], pubkey: &[u8], mode: DilithiumMode, ) -> Result<Self, DilithiumError>
Reconstruct from private + public key bytes with validation (FIPS 204 §7.1).
Validates that:
- Key sizes match the expected values for the given mode.
- The public key embedded in the secret key is consistent.
- The secret key’s
tr = H(pk)field is consistent.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize the full key pair to bytes: [mode_tag(1) | pk | sk].
The mode tag encodes the security level so deserialization can automatically select the correct parameters.
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self, DilithiumError>
pub fn from_bytes(data: &[u8]) -> Result<Self, DilithiumError>
Deserialize a key pair from the format produced by to_bytes.
Sourcepub fn public_key_bytes(&self) -> Vec<u8> ⓘ
pub fn public_key_bytes(&self) -> Vec<u8> ⓘ
Export only the public key bytes with a mode tag: [mode_tag(1) | pk].
Sourcepub fn from_public_key(
data: &[u8],
) -> Result<(DilithiumMode, Vec<u8>), DilithiumError>
pub fn from_public_key( data: &[u8], ) -> Result<(DilithiumMode, Vec<u8>), DilithiumError>
Create a verify-only handle from tagged public key bytes.
Trait Implementations§
Source§impl Clone for DilithiumKeyPair
impl Clone for DilithiumKeyPair
Source§fn clone(&self) -> DilithiumKeyPair
fn clone(&self) -> DilithiumKeyPair
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more