Merge pull request #10780 from holtrop-wolfssl/rust-rename-dilithium-mldsa

Rust wrapper: rename dilithium to mldsa
This commit is contained in:
Daniel Pouzzner
2026-07-01 16:30:28 -05:00
committed by GitHub
6 changed files with 338 additions and 338 deletions
+2 -2
View File
@@ -20,7 +20,6 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/cmac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/cmac_mac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/dh.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs
@@ -32,6 +31,7 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/kdf.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/lib.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/lms.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/mldsa.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/mlkem_kem.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/src/pbkdf2_password_hash.rs
@@ -54,7 +54,6 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_cmac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_cmac_mac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_dh.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_ecdsa.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_ed25519.rs
@@ -64,6 +63,7 @@ EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_kdf.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_lms.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_mldsa.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_mlkem.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_mlkem_kem.rs
EXTRA_DIST += wrapper/rust/wolfssl-wolfcrypt/tests/test_pbkdf2_password_hash.rs
+13 -13
View File
@@ -489,19 +489,19 @@ fn scan_cfg() -> Result<()> {
println!("cargo:rustc-cfg=rsa_const_api");
}
/* dilithium / ML-DSA */
check_cfg(&binding, "wc_dilithium_init", "dilithium");
check_cfg(&binding, "wc_dilithium_make_key", "dilithium_make_key");
check_cfg(&binding, "wc_dilithium_make_key_from_seed", "dilithium_make_key_from_seed");
check_cfg(&binding, "wc_dilithium_sign_ctx_msg", "dilithium_sign");
check_cfg(&binding, "wc_dilithium_sign_ctx_msg_with_seed", "dilithium_sign_with_seed");
check_cfg(&binding, "wc_dilithium_verify_ctx_msg", "dilithium_verify");
check_cfg(&binding, "wc_dilithium_import_public", "dilithium_import");
check_cfg(&binding, "wc_dilithium_export_public", "dilithium_export");
check_cfg(&binding, "wc_dilithium_check_key", "dilithium_check_key");
check_cfg(&binding, "DILITHIUM_LEVEL2_KEY_SIZE", "dilithium_level2");
check_cfg(&binding, "DILITHIUM_LEVEL3_KEY_SIZE", "dilithium_level3");
check_cfg(&binding, "DILITHIUM_LEVEL5_KEY_SIZE", "dilithium_level5");
/* mldsa */
check_cfg(&binding, "wc_MlDsaKey_Init", "mldsa");
check_cfg(&binding, "wc_MlDsaKey_MakeKey", "mldsa_make_key");
check_cfg(&binding, "wc_MlDsaKey_MakeKeyFromSeed", "mldsa_make_key_from_seed");
check_cfg(&binding, "wc_MlDsaKey_SignCtx", "mldsa_sign");
check_cfg(&binding, "wc_MlDsaKey_SignCtxWithSeed", "mldsa_sign_with_seed");
check_cfg(&binding, "wc_MlDsaKey_VerifyCtx", "mldsa_verify");
check_cfg(&binding, "wc_MlDsaKey_ImportPubRaw", "mldsa_import");
check_cfg(&binding, "wc_MlDsaKey_ExportPubRaw", "mldsa_export");
check_cfg(&binding, "wc_MlDsaKey_CheckKey", "mldsa_check_key");
check_cfg(&binding, "WC_MLDSA_44_KEY_SIZE", "mldsa_level2");
check_cfg(&binding, "WC_MLDSA_65_KEY_SIZE", "mldsa_level3");
check_cfg(&binding, "WC_MLDSA_87_KEY_SIZE", "mldsa_level5");
/* mlkem / ML-KEM */
check_cfg(&binding, "wc_MlKemKey_Init", "mlkem");
+1 -1
View File
@@ -19,6 +19,6 @@
#include "wolfssl/wolfcrypt/logging.h"
#include "wolfssl/wolfcrypt/aes.h"
#include "wolfssl/wolfcrypt/pwdbased.h"
#include "wolfssl/wolfcrypt/dilithium.h"
#include "wolfssl/wolfcrypt/wc_mldsa.h"
#include "wolfssl/wolfcrypt/wc_mlkem.h"
#include "wolfssl/wolfcrypt/wc_lms.h"
+1 -1
View File
@@ -55,7 +55,6 @@ pub mod cmac;
pub mod cmac_mac;
pub mod curve25519;
pub mod dh;
pub mod dilithium;
pub mod ecc;
#[cfg(feature = "signature")]
pub mod ecdsa;
@@ -68,6 +67,7 @@ pub mod hmac;
pub mod hmac_mac;
pub mod kdf;
pub mod lms;
pub mod mldsa;
pub mod mlkem;
#[cfg(all(feature = "kem", mlkem))]
pub mod mlkem_kem;
@@ -18,21 +18,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#![cfg(dilithium)]
#![cfg(mldsa)]
mod common;
use wolfssl_wolfcrypt::dilithium::Dilithium;
#[cfg(all(random, any(dilithium_make_key, dilithium_sign)))]
use wolfssl_wolfcrypt::mldsa::MlDsa;
#[cfg(all(random, any(mldsa_make_key, mldsa_sign)))]
use wolfssl_wolfcrypt::random::RNG;
/// Verify the level constants have the correct numeric values required by
/// the wolfCrypt API.
#[test]
fn test_level_constants() {
assert_eq!(Dilithium::LEVEL_44, 2);
assert_eq!(Dilithium::LEVEL_65, 3);
assert_eq!(Dilithium::LEVEL_87, 5);
assert_eq!(MlDsa::LEVEL_44, 2);
assert_eq!(MlDsa::LEVEL_65, 3);
assert_eq!(MlDsa::LEVEL_87, 5);
}
/// Verify `new()` + `set_level()` + `get_level()` for all three parameter sets.
@@ -40,101 +40,101 @@ fn test_level_constants() {
fn test_new_and_level() {
common::setup();
let mut key = Dilithium::new().expect("Error with new()");
let mut key = MlDsa::new().expect("Error with new()");
key.set_level(Dilithium::LEVEL_44).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), Dilithium::LEVEL_44);
key.set_level(MlDsa::LEVEL_44).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), MlDsa::LEVEL_44);
key.set_level(Dilithium::LEVEL_65).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), Dilithium::LEVEL_65);
key.set_level(MlDsa::LEVEL_65).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), MlDsa::LEVEL_65);
key.set_level(Dilithium::LEVEL_87).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), Dilithium::LEVEL_87);
key.set_level(MlDsa::LEVEL_87).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), MlDsa::LEVEL_87);
}
/// Verify that `new_ex()` accepts the optional heap and device ID parameters.
#[test]
fn test_new_ex() {
common::setup();
let mut key = Dilithium::new_ex(None, None).expect("Error with new_ex()");
key.set_level(Dilithium::LEVEL_44).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), Dilithium::LEVEL_44);
let mut key = MlDsa::new_ex(None, None).expect("Error with new_ex()");
key.set_level(MlDsa::LEVEL_44).expect("Error with set_level()");
assert_eq!(key.get_level().expect("Error with get_level()"), MlDsa::LEVEL_44);
}
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-44.
#[test]
#[cfg(all(dilithium_make_key, dilithium_level2))]
#[cfg(all(mldsa_make_key, mldsa_level2))]
fn test_sizes_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
assert_eq!(key.size().expect("Error with size()"), Dilithium::LEVEL2_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), Dilithium::LEVEL2_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), Dilithium::LEVEL2_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), Dilithium::LEVEL2_SIG_SIZE);
assert_eq!(key.size().expect("Error with size()"), MlDsa::LEVEL2_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), MlDsa::LEVEL2_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), MlDsa::LEVEL2_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), MlDsa::LEVEL2_SIG_SIZE);
}
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-65.
#[test]
#[cfg(all(dilithium_make_key, dilithium_level3))]
#[cfg(all(mldsa_make_key, mldsa_level3))]
fn test_sizes_level65() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_65, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_65, &mut rng)
.expect("Error with generate()");
assert_eq!(key.size().expect("Error with size()"), Dilithium::LEVEL3_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), Dilithium::LEVEL3_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), Dilithium::LEVEL3_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), Dilithium::LEVEL3_SIG_SIZE);
assert_eq!(key.size().expect("Error with size()"), MlDsa::LEVEL3_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), MlDsa::LEVEL3_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), MlDsa::LEVEL3_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), MlDsa::LEVEL3_SIG_SIZE);
}
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-87.
#[test]
#[cfg(all(dilithium_make_key, dilithium_level5))]
#[cfg(all(mldsa_make_key, mldsa_level5))]
fn test_sizes_level87() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_87, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_87, &mut rng)
.expect("Error with generate()");
assert_eq!(key.size().expect("Error with size()"), Dilithium::LEVEL5_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), Dilithium::LEVEL5_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), Dilithium::LEVEL5_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), Dilithium::LEVEL5_SIG_SIZE);
assert_eq!(key.size().expect("Error with size()"), MlDsa::LEVEL5_KEY_SIZE);
assert_eq!(key.priv_size().expect("Error with priv_size()"), MlDsa::LEVEL5_PRV_KEY_SIZE);
assert_eq!(key.pub_size().expect("Error with pub_size()"), MlDsa::LEVEL5_PUB_KEY_SIZE);
assert_eq!(key.sig_size().expect("Error with sig_size()"), MlDsa::LEVEL5_SIG_SIZE);
}
/// Verify that `check_key()` accepts a freshly generated ML-DSA-44 key pair.
#[test]
#[cfg(all(dilithium_make_key, dilithium_check_key))]
#[cfg(all(mldsa_make_key, mldsa_check_key))]
fn test_check_key_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
key.check_key().expect("Error with check_key()");
}
/// Verify that `check_key()` accepts a freshly generated ML-DSA-65 key pair.
#[test]
#[cfg(all(dilithium_make_key, dilithium_check_key))]
#[cfg(all(mldsa_make_key, mldsa_check_key))]
fn test_check_key_level65() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_65, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_65, &mut rng)
.expect("Error with generate()");
key.check_key().expect("Error with check_key()");
}
/// Verify that `check_key()` accepts a freshly generated ML-DSA-87 key pair.
#[test]
#[cfg(all(dilithium_make_key, dilithium_check_key))]
#[cfg(all(mldsa_make_key, mldsa_check_key))]
fn test_check_key_level87() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_87, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_87, &mut rng)
.expect("Error with generate()");
key.check_key().expect("Error with check_key()");
}
@@ -144,11 +144,11 @@ fn test_check_key_level87() {
/// Also verifies that a tampered message or signature produces a
/// verification failure rather than an error.
#[test]
#[cfg(all(dilithium_make_key, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_sign, mldsa_verify))]
fn test_sign_verify_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
let message = b"Hello, ML-DSA-44!";
let mut sig = vec![0u8; key.sig_size().expect("Error with sig_size()")];
@@ -168,11 +168,11 @@ fn test_sign_verify_level44() {
/// Sign and verify a message round-trip using ML-DSA-65.
#[test]
#[cfg(all(dilithium_make_key, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_sign, mldsa_verify))]
fn test_sign_verify_level65() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_65, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_65, &mut rng)
.expect("Error with generate()");
let message = b"Hello, ML-DSA-65!";
let mut sig = vec![0u8; key.sig_size().expect("Error with sig_size()")];
@@ -187,11 +187,11 @@ fn test_sign_verify_level65() {
/// Sign and verify a message round-trip using ML-DSA-87.
#[test]
#[cfg(all(dilithium_make_key, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_sign, mldsa_verify))]
fn test_sign_verify_level87() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_87, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_87, &mut rng)
.expect("Error with generate()");
let message = b"Hello, ML-DSA-87!";
let mut sig = vec![0u8; key.sig_size().expect("Error with sig_size()")];
@@ -208,11 +208,11 @@ fn test_sign_verify_level87() {
///
/// Also verifies that a mismatched context causes verification to fail.
#[test]
#[cfg(all(dilithium_make_key, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_sign, mldsa_verify))]
fn test_sign_ctx_verify_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
let message = b"Context-bound message";
let ctx = b"my context";
@@ -237,11 +237,11 @@ fn test_sign_ctx_verify_level44() {
/// - the re-imported private key can sign messages that verify with the
/// original public key.
#[test]
#[cfg(all(dilithium_make_key, dilithium_import, dilithium_export, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_import, mldsa_export, mldsa_sign, mldsa_verify))]
fn test_import_export_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
let priv_size = key.size().expect("Error with size()");
@@ -270,16 +270,16 @@ fn test_import_export_level44() {
.expect("Error with sign_msg()");
// Re-import public key only and verify.
let mut pub_key = Dilithium::new().expect("Error with new()");
pub_key.set_level(Dilithium::LEVEL_44).expect("Error with set_level()");
let mut pub_key = MlDsa::new().expect("Error with new()");
pub_key.set_level(MlDsa::LEVEL_44).expect("Error with set_level()");
pub_key.import_public(&pub_buf).expect("Error with import_public()");
let valid = pub_key.verify_msg(&sig[..sig_len], message)
.expect("Error with verify_msg() via imported public key");
assert!(valid, "Imported public key should accept original signature");
// Re-import private key, sign a message, and verify with the original key.
let mut priv_key = Dilithium::new().expect("Error with new()");
priv_key.set_level(Dilithium::LEVEL_44).expect("Error with set_level()");
let mut priv_key = MlDsa::new().expect("Error with new()");
priv_key.set_level(MlDsa::LEVEL_44).expect("Error with set_level()");
priv_key.import_private(&priv_buf).expect("Error with import_private()");
let mut sig2 = vec![0u8; sig_size];
let sig2_len = priv_key.sign_msg(message, &mut sig2, &mut rng)
@@ -292,11 +292,11 @@ fn test_import_export_level44() {
/// Export both keys, import them together via `import_key()`, then sign and
/// verify using the re-imported key pair.
#[test]
#[cfg(all(dilithium_make_key, dilithium_import, dilithium_export, dilithium_sign, dilithium_verify))]
#[cfg(all(mldsa_make_key, mldsa_import, mldsa_export, mldsa_sign, mldsa_verify))]
fn test_import_key_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng)
let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng)
.expect("Error with generate()");
let priv_size = key.size().expect("Error with size()");
@@ -307,8 +307,8 @@ fn test_import_key_level44() {
let mut pub_buf = vec![0u8; pub_size];
key.export_key(&mut priv_buf, &mut pub_buf).expect("Error with export_key()");
let mut key2 = Dilithium::new().expect("Error with new()");
key2.set_level(Dilithium::LEVEL_44).expect("Error with set_level()");
let mut key2 = MlDsa::new().expect("Error with new()");
key2.set_level(MlDsa::LEVEL_44).expect("Error with set_level()");
key2.import_key(&priv_buf, &pub_buf).expect("Error with import_key()");
let message = b"import_key round-trip";
@@ -323,15 +323,15 @@ fn test_import_key_level44() {
/// Verify that `generate_from_seed()` is deterministic: the same seed
/// produces the same key pair on repeated calls.
#[test]
#[cfg(all(dilithium_make_key_from_seed, dilithium_export))]
#[cfg(all(mldsa_make_key_from_seed, mldsa_export))]
fn test_generate_from_seed_determinism() {
common::setup();
// DILITHIUM_SEED_SZ = 32 bytes
// MLDSA_SEED_SZ = 32 bytes
let seed = [0x42u8; 32];
let mut key1 = Dilithium::generate_from_seed(Dilithium::LEVEL_44, &seed)
let mut key1 = MlDsa::generate_from_seed(MlDsa::LEVEL_44, &seed)
.expect("Error with generate_from_seed() first call");
let mut key2 = Dilithium::generate_from_seed(Dilithium::LEVEL_44, &seed)
let mut key2 = MlDsa::generate_from_seed(MlDsa::LEVEL_44, &seed)
.expect("Error with generate_from_seed() second call");
let pub_size = key1.pub_size().expect("Error with pub_size()");
@@ -353,16 +353,16 @@ fn test_generate_from_seed_determinism() {
/// message, and signing seed always produce the same signature bytes, and
/// the signature verifies correctly.
#[test]
#[cfg(all(dilithium_make_key_from_seed, dilithium_sign_with_seed, dilithium_verify))]
#[cfg(all(mldsa_make_key_from_seed, mldsa_sign_with_seed, mldsa_verify))]
fn test_sign_with_seed_determinism() {
common::setup();
// DILITHIUM_SEED_SZ = 32 bytes
// MLDSA_SEED_SZ = 32 bytes
let key_seed = [0x42u8; 32];
// DILITHIUM_RND_SZ = 32 bytes
// MLDSA_RND_SZ = 32 bytes
let sign_seed = [0x55u8; 32];
let message = b"Deterministic ML-DSA signing test";
let mut key = Dilithium::generate_from_seed(Dilithium::LEVEL_44, &key_seed)
let mut key = MlDsa::generate_from_seed(MlDsa::LEVEL_44, &key_seed)
.expect("Error with generate_from_seed()");
let sig_size = key.sig_size().expect("Error with sig_size()");
@@ -385,7 +385,7 @@ fn test_sign_with_seed_determinism() {
/// Verify that `sign_ctx_msg_with_seed()` is deterministic and that the
/// produced signature verifies with `verify_ctx_msg()`.
#[test]
#[cfg(all(dilithium_make_key_from_seed, dilithium_sign_with_seed, dilithium_verify))]
#[cfg(all(mldsa_make_key_from_seed, mldsa_sign_with_seed, mldsa_verify))]
fn test_sign_ctx_with_seed_determinism() {
common::setup();
let key_seed = [0x11u8; 32];
@@ -393,7 +393,7 @@ fn test_sign_ctx_with_seed_determinism() {
let message = b"Context deterministic signing test";
let ctx = b"test-context";
let mut key = Dilithium::generate_from_seed(Dilithium::LEVEL_44, &key_seed)
let mut key = MlDsa::generate_from_seed(MlDsa::LEVEL_44, &key_seed)
.expect("Error with generate_from_seed()");
let sig_size = key.sig_size().expect("Error with sig_size()");
@@ -416,15 +416,15 @@ fn test_sign_ctx_with_seed_determinism() {
/// Verify that `generate_from_seed()` + `sign_msg_with_seed()` +
/// `verify_msg()` work across all three security levels.
#[test]
#[cfg(all(dilithium_make_key_from_seed, dilithium_sign_with_seed, dilithium_verify))]
#[cfg(all(mldsa_make_key_from_seed, mldsa_sign_with_seed, mldsa_verify))]
fn test_seed_sign_verify_all_levels() {
common::setup();
let key_seed = [0xABu8; 32];
let sign_seed = [0xCDu8; 32];
let message = b"All-levels seed sign/verify test";
for level in [Dilithium::LEVEL_44, Dilithium::LEVEL_65, Dilithium::LEVEL_87] {
let mut key = Dilithium::generate_from_seed(level, &key_seed)
for level in [MlDsa::LEVEL_44, MlDsa::LEVEL_65, MlDsa::LEVEL_87] {
let mut key = MlDsa::generate_from_seed(level, &key_seed)
.expect("Error with generate_from_seed()");
let sig_size = key.sig_size().expect("Error with sig_size()");
let mut sig = vec![0u8; sig_size];