Class MLDsa65
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Dsa
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
ML-DSA-65 digital signature algorithm (NIST security category 3).
public sealed class MLDsa65 : IDsa, IDisposable
- Inheritance
-
MLDsa65
- Implements
- Inherited Members
Remarks
ML-DSA-65 is a post-quantum digital signature scheme standardized in FIPS 204, derived from CRYSTALS-Dilithium and based on the Module-LWE problem.
Parameters (FIPS 204 Table 1): (k, ℓ) = (6, 5), η = 4, τ = 49, γ₁ = 2¹⁹. Public key: 1952 bytes, secret key: 4032 bytes, signature: 3309 bytes.
Example usage:
using var dsa = MLDsa65.Create();
byte[] pk = new byte[MLDsa65.PublicKeySizeBytesConst];
byte[] sk = new byte[MLDsa65.SecretKeySizeBytesConst];
dsa.GenerateKeyPair(pk, sk);
byte[] signature = new byte[MLDsa65.SignatureSizeBytesConst];
dsa.Sign(sk, message, context: default, signature);
bool valid = dsa.Verify(pk, message, context: default, signature);
Constructors
MLDsa65()
Initializes a new instance of the MLDsa65 class.
public MLDsa65()
Fields
KeyGenSeedSizeBytesConst
The key generation seed size in bytes (32 bytes).
public const int KeyGenSeedSizeBytesConst = 32
Field Value
PublicKeySizeBytesConst
The public key size in bytes (1952 bytes).
public const int PublicKeySizeBytesConst = 1952
Field Value
SecretKeySizeBytesConst
The secret key size in bytes (4032 bytes).
public const int SecretKeySizeBytesConst = 4032
Field Value
SignatureSizeBytesConst
The signature size in bytes (3309 bytes).
public const int SignatureSizeBytesConst = 3309
Field Value
Properties
AlgorithmName
Gets the algorithm name.
public string AlgorithmName { get; }
Property Value
PublicKeySizeBytes
Gets the public key size in bytes.
public int PublicKeySizeBytes { get; }
Property Value
SecretKeySizeBytes
Gets the secret key size in bytes.
public int SecretKeySizeBytes { get; }
Property Value
SignatureSizeBytes
Gets the signature size in bytes.
public int SignatureSizeBytes { get; }
Property Value
Methods
Create()
Creates a new ML-DSA-65 instance.
public static MLDsa65 Create()
Returns
- MLDsa65
A new ML-DSA-65 instance.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GenerateKeyPair(ReadOnlySpan<byte>, Span<byte>, Span<byte>)
Generates a key pair deterministically from the provided 32-byte seed ξ.
public void GenerateKeyPair(ReadOnlySpan<byte> seed, Span<byte> publicKey, Span<byte> secretKey)
Parameters
seedReadOnlySpan<byte>The 32-byte key generation seed.
publicKeySpan<byte>The buffer to receive the public key.
secretKeySpan<byte>The buffer to receive the secret key.
Exceptions
- ArgumentException
A parameter has an invalid size.
GenerateKeyPair(ReadOnlySpan<byte>, Span<byte>, Span<byte>, bool)
Generates a key pair from a seed, optionally skipping the pairwise consistency test.
public void GenerateKeyPair(ReadOnlySpan<byte> seed, Span<byte> publicKey, Span<byte> secretKey, bool pairwiseConsistencyTest)
Parameters
seedReadOnlySpan<byte>The 32-byte key generation seed ξ.
publicKeySpan<byte>The buffer to receive the public key.
secretKeySpan<byte>The buffer to receive the secret key.
pairwiseConsistencyTestbool
Exceptions
- ArgumentException
A parameter has an invalid size.
GenerateKeyPair(Span<byte>, Span<byte>)
Generates a new key pair using the OS random number generator.
public void GenerateKeyPair(Span<byte> publicKey, Span<byte> secretKey)
Parameters
publicKeySpan<byte>The buffer to receive the public key.
secretKeySpan<byte>The buffer to receive the secret key.
Exceptions
- ArgumentException
A buffer is too small.
GenerateKeyPair(Span<byte>, Span<byte>, bool)
Generates a key pair, optionally skipping the pairwise consistency test.
public void GenerateKeyPair(Span<byte> publicKey, Span<byte> secretKey, bool pairwiseConsistencyTest)
Parameters
publicKeySpan<byte>The buffer to receive the public key.
secretKeySpan<byte>The buffer to receive the secret key.
pairwiseConsistencyTestbooltrue to verify the generated key pair with a sign/verify round trip; false to skip it. See the remarks on the signature type.
Exceptions
- ArgumentException
A buffer is too small.
Sign(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Signs a message using the hedged (randomized) variant of ML-DSA.
public void Sign(ReadOnlySpan<byte> secretKey, ReadOnlySpan<byte> message, ReadOnlySpan<byte> context, Span<byte> signature)
Parameters
secretKeyReadOnlySpan<byte>The secret key.
messageReadOnlySpan<byte>The message to sign.
contextReadOnlySpan<byte>The optional context string (at most 255 bytes).
signatureSpan<byte>The buffer to receive the signature.
Exceptions
- ArgumentException
A parameter has an invalid size.
SignDeterministic(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Signs a message using the deterministic variant of ML-DSA (rnd = 0³²).
public void SignDeterministic(ReadOnlySpan<byte> secretKey, ReadOnlySpan<byte> message, ReadOnlySpan<byte> context, Span<byte> signature)
Parameters
secretKeyReadOnlySpan<byte>The secret key.
messageReadOnlySpan<byte>The message to sign.
contextReadOnlySpan<byte>The optional context string (at most 255 bytes).
signatureSpan<byte>The buffer to receive the signature.
Remarks
Hedged signing (see Sign(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)) is the FIPS 204 default and should be preferred; the deterministic variant exists for reproducibility requirements and known-answer testing.
Exceptions
- ArgumentException
A parameter has an invalid size.
Verify(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Verifies a signature over a message.
public bool Verify(ReadOnlySpan<byte> publicKey, ReadOnlySpan<byte> message, ReadOnlySpan<byte> context, ReadOnlySpan<byte> signature)
Parameters
publicKeyReadOnlySpan<byte>The public key.
messageReadOnlySpan<byte>The signed message.
contextReadOnlySpan<byte>The context string used when signing (at most 255 bytes).
signatureReadOnlySpan<byte>The signature to verify.
Returns
- bool
True when the signature is valid for the message, key, and context.
Exceptions
- ArgumentException
A parameter has an invalid size.