From b6d962350dceb09fc5d3ae73320132bab836d8ed Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 9 Jun 2026 13:47:49 -0400 Subject: [PATCH] Rust wrapper: rename dilithium to mldsa --- wrapper/rust/include.am | 4 +- wrapper/rust/wolfssl-wolfcrypt/build.rs | 26 +- wrapper/rust/wolfssl-wolfcrypt/headers.h | 2 +- wrapper/rust/wolfssl-wolfcrypt/src/lib.rs | 2 +- .../src/{dilithium.rs => mldsa.rs} | 488 +++++++++--------- .../{test_dilithium.rs => test_mldsa.rs} | 142 ++--- 6 files changed, 332 insertions(+), 332 deletions(-) rename wrapper/rust/wolfssl-wolfcrypt/src/{dilithium.rs => mldsa.rs} (70%) rename wrapper/rust/wolfssl-wolfcrypt/tests/{test_dilithium.rs => test_mldsa.rs} (75%) diff --git a/wrapper/rust/include.am b/wrapper/rust/include.am index 4c3df1d122a..e54f520c8c1 100644 --- a/wrapper/rust/include.am +++ b/wrapper/rust/include.am @@ -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 diff --git a/wrapper/rust/wolfssl-wolfcrypt/build.rs b/wrapper/rust/wolfssl-wolfcrypt/build.rs index 646932366bf..e67528897a1 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/build.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/build.rs @@ -469,19 +469,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"); diff --git a/wrapper/rust/wolfssl-wolfcrypt/headers.h b/wrapper/rust/wolfssl-wolfcrypt/headers.h index 719c2f01f0b..30bb34bdfc6 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/headers.h +++ b/wrapper/rust/wolfssl-wolfcrypt/headers.h @@ -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" diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs b/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs index f25e42a5745..1e6a709a401 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/lib.rs @@ -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; diff --git a/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs b/wrapper/rust/wolfssl-wolfcrypt/src/mldsa.rs similarity index 70% rename from wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs rename to wrapper/rust/wolfssl-wolfcrypt/src/mldsa.rs index 6e1ac0564c9..b5ad884faf6 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/src/mldsa.rs @@ -20,30 +20,30 @@ /*! This module provides a Rust wrapper for the wolfCrypt library's ML-DSA -(Dilithium) post-quantum digital signature functionality. +post-quantum digital signature functionality. -The primary component is the [`Dilithium`] struct, which manages the lifecycle -of a wolfSSL `dilithium_key` object. It ensures proper initialization and +The primary component is the [`MlDsa`] struct, which manages the lifecycle +of a wolfSSL `wc_MlDsaKey` object. It ensures proper initialization and deallocation. Three security parameter sets are supported, selected via -[`Dilithium::set_level()`]: +[`MlDsa::set_level()`]: | Constant | Level | NIST PQC Level | |-----------------|-------|----------------| -| [`Dilithium::LEVEL_44`] | 2 | 2 (ML-DSA-44) | -| [`Dilithium::LEVEL_65`] | 3 | 3 (ML-DSA-65) | -| [`Dilithium::LEVEL_87`] | 5 | 5 (ML-DSA-87) | +| [`MlDsa::LEVEL_44`] | 2 | 2 (ML-DSA-44) | +| [`MlDsa::LEVEL_65`] | 3 | 3 (ML-DSA-65) | +| [`MlDsa::LEVEL_87`] | 5 | 5 (ML-DSA-87) | # Examples ```rust -#[cfg(all(dilithium, dilithium_make_key, dilithium_sign, dilithium_verify, random))] +#[cfg(all(mldsa, mldsa_make_key, mldsa_sign, mldsa_verify, random))] { use wolfssl_wolfcrypt::random::RNG; -use wolfssl_wolfcrypt::dilithium::Dilithium; +use wolfssl_wolfcrypt::mldsa::MlDsa; let mut rng = RNG::new().expect("RNG creation failed"); -let mut key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng) +let mut key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng) .expect("Key generation failed"); let message = b"Hello, ML-DSA!"; let mut sig = vec![0u8; key.sig_size().expect("sig_size failed")]; @@ -56,25 +56,25 @@ assert!(valid); ``` */ -#![cfg(dilithium)] +#![cfg(mldsa)] use crate::sys; -#[cfg(all(random, any(dilithium_make_key, dilithium_sign)))] +#[cfg(all(random, any(mldsa_make_key, mldsa_sign)))] use crate::random::RNG; use core::mem::MaybeUninit; -/// Rust wrapper for a wolfSSL `dilithium_key` object. +/// Rust wrapper for a wolfSSL `wc_MlDsaKey` object. /// /// Manages the lifecycle of the underlying key, including initialization and /// deallocation via the [`Drop`] trait. /// -/// An instance is created with [`Dilithium::generate()`], -/// [`Dilithium::generate_from_seed()`], or [`Dilithium::new()`]. -pub struct Dilithium { - ws_key: sys::dilithium_key, +/// An instance is created with [`MlDsa::generate()`], +/// [`MlDsa::generate_from_seed()`], or [`MlDsa::new()`]. +pub struct MlDsa { + ws_key: sys::wc_MlDsaKey, } -impl Dilithium { +impl MlDsa { /// ML-DSA-44 security parameter set (NIST Level 2). pub const LEVEL_44: u8 = sys::WC_ML_DSA_44 as u8; /// ML-DSA-65 security parameter set (NIST Level 3). @@ -83,114 +83,114 @@ impl Dilithium { pub const LEVEL_87: u8 = sys::WC_ML_DSA_87 as u8; /// Required size in bytes of the seed passed to - /// [`Dilithium::generate_from_seed()`] (`DILITHIUM_SEED_SZ`). - pub const DILITHIUM_SEED_SZ: usize = sys::DILITHIUM_SEED_SZ as usize; + /// [`MlDsa::generate_from_seed()`] (`MLDSA_SEED_SZ`). + pub const MLDSA_SEED_SZ: usize = sys::MLDSA_SEED_SZ as usize; /// Required size in bytes of the seed passed to signing-with-seed - /// functions such as [`Dilithium::sign_msg_with_seed()`] - /// (`DILITHIUM_RND_SZ`). - pub const SIGN_SEED_SIZE: usize = sys::DILITHIUM_RND_SZ as usize; + /// functions such as [`MlDsa::sign_msg_with_seed()`] + /// (`MLDSA_RND_SZ`). + pub const SIGN_SEED_SIZE: usize = sys::MLDSA_RND_SZ as usize; /// Private (secret) key size in bytes for ML-DSA-44. - #[cfg(dilithium_level2)] - pub const LEVEL2_KEY_SIZE: usize = sys::DILITHIUM_LEVEL2_KEY_SIZE as usize; + #[cfg(mldsa_level2)] + pub const LEVEL2_KEY_SIZE: usize = sys::WC_MLDSA_44_KEY_SIZE as usize; /// Signature size in bytes for ML-DSA-44. - #[cfg(dilithium_level2)] - pub const LEVEL2_SIG_SIZE: usize = sys::DILITHIUM_LEVEL2_SIG_SIZE as usize; + #[cfg(mldsa_level2)] + pub const LEVEL2_SIG_SIZE: usize = sys::WC_MLDSA_44_SIG_SIZE as usize; /// Public key size in bytes for ML-DSA-44. - #[cfg(dilithium_level2)] - pub const LEVEL2_PUB_KEY_SIZE: usize = sys::DILITHIUM_LEVEL2_PUB_KEY_SIZE as usize; + #[cfg(mldsa_level2)] + pub const LEVEL2_PUB_KEY_SIZE: usize = sys::WC_MLDSA_44_PUB_KEY_SIZE as usize; /// Combined private-plus-public key size in bytes for ML-DSA-44. - #[cfg(dilithium_level2)] + #[cfg(mldsa_level2)] pub const LEVEL2_PRV_KEY_SIZE: usize = - sys::DILITHIUM_LEVEL2_PUB_KEY_SIZE as usize + sys::DILITHIUM_LEVEL2_KEY_SIZE as usize; + sys::WC_MLDSA_44_PUB_KEY_SIZE as usize + sys::WC_MLDSA_44_KEY_SIZE as usize; /// Private (secret) key size in bytes for ML-DSA-65. - #[cfg(dilithium_level3)] - pub const LEVEL3_KEY_SIZE: usize = sys::DILITHIUM_LEVEL3_KEY_SIZE as usize; + #[cfg(mldsa_level3)] + pub const LEVEL3_KEY_SIZE: usize = sys::WC_MLDSA_65_KEY_SIZE as usize; /// Signature size in bytes for ML-DSA-65. - #[cfg(dilithium_level3)] - pub const LEVEL3_SIG_SIZE: usize = sys::DILITHIUM_LEVEL3_SIG_SIZE as usize; + #[cfg(mldsa_level3)] + pub const LEVEL3_SIG_SIZE: usize = sys::WC_MLDSA_65_SIG_SIZE as usize; /// Public key size in bytes for ML-DSA-65. - #[cfg(dilithium_level3)] - pub const LEVEL3_PUB_KEY_SIZE: usize = sys::DILITHIUM_LEVEL3_PUB_KEY_SIZE as usize; + #[cfg(mldsa_level3)] + pub const LEVEL3_PUB_KEY_SIZE: usize = sys::WC_MLDSA_65_PUB_KEY_SIZE as usize; /// Combined private-plus-public key size in bytes for ML-DSA-65. - #[cfg(dilithium_level3)] + #[cfg(mldsa_level3)] pub const LEVEL3_PRV_KEY_SIZE: usize = - sys::DILITHIUM_LEVEL3_PUB_KEY_SIZE as usize + sys::DILITHIUM_LEVEL3_KEY_SIZE as usize; + sys::WC_MLDSA_65_PUB_KEY_SIZE as usize + sys::WC_MLDSA_65_KEY_SIZE as usize; /// Private (secret) key size in bytes for ML-DSA-87. - #[cfg(dilithium_level5)] - pub const LEVEL5_KEY_SIZE: usize = sys::DILITHIUM_LEVEL5_KEY_SIZE as usize; + #[cfg(mldsa_level5)] + pub const LEVEL5_KEY_SIZE: usize = sys::WC_MLDSA_87_KEY_SIZE as usize; /// Signature size in bytes for ML-DSA-87. - #[cfg(dilithium_level5)] - pub const LEVEL5_SIG_SIZE: usize = sys::DILITHIUM_LEVEL5_SIG_SIZE as usize; + #[cfg(mldsa_level5)] + pub const LEVEL5_SIG_SIZE: usize = sys::WC_MLDSA_87_SIG_SIZE as usize; /// Public key size in bytes for ML-DSA-87. - #[cfg(dilithium_level5)] - pub const LEVEL5_PUB_KEY_SIZE: usize = sys::DILITHIUM_LEVEL5_PUB_KEY_SIZE as usize; + #[cfg(mldsa_level5)] + pub const LEVEL5_PUB_KEY_SIZE: usize = sys::WC_MLDSA_87_PUB_KEY_SIZE as usize; /// Combined private-plus-public key size in bytes for ML-DSA-87. - #[cfg(dilithium_level5)] + #[cfg(mldsa_level5)] pub const LEVEL5_PRV_KEY_SIZE: usize = - sys::DILITHIUM_LEVEL5_PUB_KEY_SIZE as usize + sys::DILITHIUM_LEVEL5_KEY_SIZE as usize; + sys::WC_MLDSA_87_PUB_KEY_SIZE as usize + sys::WC_MLDSA_87_KEY_SIZE as usize; - /// Generate a new Dilithium key pair using a random number generator. + /// Generate a new ML-DSA key pair using a random number generator. /// /// # Parameters /// - /// * `level`: Security parameter set. One of [`Dilithium::LEVEL_44`], - /// [`Dilithium::LEVEL_65`], or [`Dilithium::LEVEL_87`]. + /// * `level`: Security parameter set. One of [`MlDsa::LEVEL_44`], + /// [`MlDsa::LEVEL_65`], or [`MlDsa::LEVEL_87`]. /// * `rng`: `RNG` instance to use for random number generation. /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let key = Dilithium::generate(Dilithium::LEVEL_44, &mut rng) + /// let key = MlDsa::generate(MlDsa::LEVEL_44, &mut rng) /// .expect("Error with generate()"); /// } /// ``` - #[cfg(all(dilithium_make_key, random))] + #[cfg(all(mldsa_make_key, random))] pub fn generate(level: u8, rng: &RNG) -> Result { Self::generate_ex(level, rng, None, None) } - /// Generate a new Dilithium key pair with optional heap hint and device ID. + /// Generate a new ML-DSA key pair with optional heap hint and device ID. /// /// # Parameters /// - /// * `level`: Security parameter set. One of [`Dilithium::LEVEL_44`], - /// [`Dilithium::LEVEL_65`], or [`Dilithium::LEVEL_87`]. + /// * `level`: Security parameter set. One of [`MlDsa::LEVEL_44`], + /// [`MlDsa::LEVEL_65`], or [`MlDsa::LEVEL_87`]. /// * `rng`: `RNG` instance to use for random number generation. /// * `heap`: Optional heap hint. /// * `dev_id`: Optional device ID for crypto callbacks or async hardware. /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// let mut rng = RNG::new().expect("Error creating RNG"); - /// let key = Dilithium::generate_ex(Dilithium::LEVEL_44, &mut rng, None, None) + /// let key = MlDsa::generate_ex(MlDsa::LEVEL_44, &mut rng, None, None) /// .expect("Error with generate_ex()"); /// } /// ``` - #[cfg(all(dilithium_make_key, random))] + #[cfg(all(mldsa_make_key, random))] pub fn generate_ex( level: u8, rng: &RNG, @@ -198,93 +198,93 @@ impl Dilithium { dev_id: Option, ) -> Result { let mut key = Self::new_ex(heap, dev_id)?; - let rc = unsafe { sys::wc_dilithium_set_level(&mut key.ws_key, level) }; + let rc = unsafe { sys::wc_MlDsaKey_SetParams(&mut key.ws_key, level) }; if rc != 0 { return Err(rc); } - let rc = unsafe { sys::wc_dilithium_make_key(&mut key.ws_key, rng.wc_rng) }; + let rc = unsafe { sys::wc_MlDsaKey_MakeKey(&mut key.ws_key, rng.wc_rng) }; if rc != 0 { return Err(rc); } Ok(key) } - /// Generate a Dilithium key pair from a fixed seed. + /// Generate an ML-DSA key pair from a fixed seed. /// /// Produces the same key pair for a given `(level, seed)` pair, enabling /// deterministic key generation. /// /// # Parameters /// - /// * `level`: Security parameter set. One of [`Dilithium::LEVEL_44`], - /// [`Dilithium::LEVEL_65`], or [`Dilithium::LEVEL_87`]. - /// * `seed`: Seed bytes. Must be `DILITHIUM_SEED_SZ` (32) bytes. + /// * `level`: Security parameter set. One of [`MlDsa::LEVEL_44`], + /// [`MlDsa::LEVEL_65`], or [`MlDsa::LEVEL_87`]. + /// * `seed`: Seed bytes. Must be `MLDSA_SEED_SZ` (32) bytes. /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key_from_seed))] + /// #[cfg(all(mldsa, mldsa_make_key_from_seed))] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// let seed = [0x42u8; 32]; - /// let key = Dilithium::generate_from_seed(Dilithium::LEVEL_44, &seed) + /// let key = MlDsa::generate_from_seed(MlDsa::LEVEL_44, &seed) /// .expect("Error with generate_from_seed()"); /// } /// ``` - #[cfg(dilithium_make_key_from_seed)] + #[cfg(mldsa_make_key_from_seed)] pub fn generate_from_seed(level: u8, seed: &[u8]) -> Result { Self::generate_from_seed_ex(level, seed, None, None) } - /// Generate a Dilithium key pair from a fixed seed with optional heap hint + /// Generate an ML-DSA key pair from a fixed seed with optional heap hint /// and device ID. /// /// # Parameters /// - /// * `level`: Security parameter set. One of [`Dilithium::LEVEL_44`], - /// [`Dilithium::LEVEL_65`], or [`Dilithium::LEVEL_87`]. - /// * `seed`: Seed bytes. Must be `DILITHIUM_SEED_SZ` (32) bytes. + /// * `level`: Security parameter set. One of [`MlDsa::LEVEL_44`], + /// [`MlDsa::LEVEL_65`], or [`MlDsa::LEVEL_87`]. + /// * `seed`: Seed bytes. Must be `MLDSA_SEED_SZ` (32) bytes. /// * `heap`: Optional heap hint. /// * `dev_id`: Optional device ID for crypto callbacks or async hardware. /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key_from_seed))] + /// #[cfg(all(mldsa, mldsa_make_key_from_seed))] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// let seed = [0x42u8; 32]; - /// let key = Dilithium::generate_from_seed_ex(Dilithium::LEVEL_44, &seed, None, None) + /// let key = MlDsa::generate_from_seed_ex(MlDsa::LEVEL_44, &seed, None, None) /// .expect("Error with generate_from_seed_ex()"); /// } /// ``` - #[cfg(dilithium_make_key_from_seed)] + #[cfg(mldsa_make_key_from_seed)] pub fn generate_from_seed_ex( level: u8, seed: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option, ) -> Result { - if seed.len() != Self::DILITHIUM_SEED_SZ { + if seed.len() != Self::MLDSA_SEED_SZ { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } let mut key = Self::new_ex(heap, dev_id)?; - let rc = unsafe { sys::wc_dilithium_set_level(&mut key.ws_key, level) }; + let rc = unsafe { sys::wc_MlDsaKey_SetParams(&mut key.ws_key, level) }; if rc != 0 { return Err(rc); } let rc = unsafe { - sys::wc_dilithium_make_key_from_seed(&mut key.ws_key, seed.as_ptr()) + sys::wc_MlDsaKey_MakeKeyFromSeed(&mut key.ws_key, seed.as_ptr()) }; if rc != 0 { return Err(rc); @@ -292,30 +292,30 @@ impl Dilithium { Ok(key) } - /// Create and initialize a new Dilithium key instance without a key. + /// Create and initialize a new ML-DSA key instance without a key. /// /// The security level and key material can be set afterwards using - /// [`Dilithium::set_level()`] and one of the import functions. + /// [`MlDsa::set_level()`] and one of the import functions. /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(dilithium)] + /// #[cfg(mldsa)] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; - /// let key = Dilithium::new().expect("Error with new()"); + /// use wolfssl_wolfcrypt::mldsa::MlDsa; + /// let key = MlDsa::new().expect("Error with new()"); /// } /// ``` pub fn new() -> Result { Self::new_ex(None, None) } - /// Create and initialize a new Dilithium key instance with optional heap + /// Create and initialize a new ML-DSA key instance with optional heap /// hint and device ID. /// /// # Parameters @@ -325,23 +325,23 @@ impl Dilithium { /// /// # Returns /// - /// Returns either Ok(Dilithium) containing the key instance or Err(e) + /// Returns either Ok(MlDsa) containing the key instance or Err(e) /// containing the wolfSSL library error code value. /// /// # Example /// /// ```rust - /// #[cfg(dilithium)] + /// #[cfg(mldsa)] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; - /// let key = Dilithium::new_ex(None, None).expect("Error with new_ex()"); + /// use wolfssl_wolfcrypt::mldsa::MlDsa; + /// let key = MlDsa::new_ex(None, None).expect("Error with new_ex()"); /// } /// ``` pub fn new_ex( heap: Option<*mut core::ffi::c_void>, dev_id: Option, ) -> Result { - let mut ws_key: MaybeUninit = MaybeUninit::uninit(); + let mut ws_key: MaybeUninit = MaybeUninit::uninit(); let heap = match heap { Some(h) => h, None => core::ptr::null_mut(), @@ -350,19 +350,19 @@ impl Dilithium { Some(id) => id, None => sys::INVALID_DEVID, }; - let rc = unsafe { sys::wc_dilithium_init_ex(ws_key.as_mut_ptr(), heap, dev_id) }; + let rc = unsafe { sys::wc_MlDsaKey_Init(ws_key.as_mut_ptr(), heap, dev_id) }; if rc != 0 { return Err(rc); } let ws_key = unsafe { ws_key.assume_init() }; - Ok(Dilithium { ws_key }) + Ok(MlDsa { ws_key }) } /// Set the security parameter level for this key. /// /// Must be called before generating or importing key material. Use one of - /// the level constants: [`Dilithium::LEVEL_44`], [`Dilithium::LEVEL_65`], - /// or [`Dilithium::LEVEL_87`]. + /// the level constants: [`MlDsa::LEVEL_44`], [`MlDsa::LEVEL_65`], + /// or [`MlDsa::LEVEL_87`]. /// /// # Parameters /// @@ -376,15 +376,15 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(dilithium)] + /// #[cfg(mldsa)] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; - /// let mut key = Dilithium::new().expect("Error with new()"); - /// key.set_level(Dilithium::LEVEL_65).expect("Error with set_level()"); + /// use wolfssl_wolfcrypt::mldsa::MlDsa; + /// let mut key = MlDsa::new().expect("Error with new()"); + /// key.set_level(MlDsa::LEVEL_65).expect("Error with set_level()"); /// } /// ``` pub fn set_level(&mut self, level: u8) -> Result<(), i32> { - let rc = unsafe { sys::wc_dilithium_set_level(&mut self.ws_key, level) }; + let rc = unsafe { sys::wc_MlDsaKey_SetParams(&mut self.ws_key, level) }; if rc != 0 { return Err(rc); } @@ -401,18 +401,18 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(dilithium)] + /// #[cfg(mldsa)] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; - /// let mut key = Dilithium::new().expect("Error with new()"); - /// key.set_level(Dilithium::LEVEL_87).expect("Error with set_level()"); + /// use wolfssl_wolfcrypt::mldsa::MlDsa; + /// let mut key = MlDsa::new().expect("Error with new()"); + /// key.set_level(MlDsa::LEVEL_87).expect("Error with set_level()"); /// let level = key.get_level().expect("Error with get_level()"); - /// assert_eq!(level, Dilithium::LEVEL_87); + /// assert_eq!(level, MlDsa::LEVEL_87); /// } /// ``` pub fn get_level(&mut self) -> Result { let mut level = 0u8; - let rc = unsafe { sys::wc_dilithium_get_level(&mut self.ws_key, &mut level) }; + let rc = unsafe { sys::wc_MlDsaKey_GetParams(&mut self.ws_key, &mut level) }; if rc != 0 { return Err(rc); } @@ -429,19 +429,19 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 sz = key.size().expect("Error with size()"); - /// assert_eq!(sz, Dilithium::LEVEL2_KEY_SIZE); + /// assert_eq!(sz, MlDsa::LEVEL2_KEY_SIZE); /// } /// ``` pub fn size(&mut self) -> Result { - let rc = unsafe { sys::wc_dilithium_size(&mut self.ws_key) }; + let rc = unsafe { sys::wc_MlDsaKey_Size(&mut self.ws_key) }; if rc < 0 { return Err(rc); } @@ -459,19 +459,19 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 sz = key.priv_size().expect("Error with priv_size()"); - /// assert_eq!(sz, Dilithium::LEVEL2_PRV_KEY_SIZE); + /// assert_eq!(sz, MlDsa::LEVEL2_PRV_KEY_SIZE); /// } /// ``` pub fn priv_size(&mut self) -> Result { - let rc = unsafe { sys::wc_dilithium_priv_size(&mut self.ws_key) }; + let rc = unsafe { sys::wc_MlDsaKey_PrivSize(&mut self.ws_key) }; if rc < 0 { return Err(rc); } @@ -488,19 +488,19 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 sz = key.pub_size().expect("Error with pub_size()"); - /// assert_eq!(sz, Dilithium::LEVEL2_PUB_KEY_SIZE); + /// assert_eq!(sz, MlDsa::LEVEL2_PUB_KEY_SIZE); /// } /// ``` pub fn pub_size(&mut self) -> Result { - let rc = unsafe { sys::wc_dilithium_pub_size(&mut self.ws_key) }; + let rc = unsafe { sys::wc_MlDsaKey_PubSize(&mut self.ws_key) }; if rc < 0 { return Err(rc); } @@ -517,19 +517,19 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 sz = key.sig_size().expect("Error with sig_size()"); - /// assert_eq!(sz, Dilithium::LEVEL2_SIG_SIZE); + /// assert_eq!(sz, MlDsa::LEVEL2_SIG_SIZE); /// } /// ``` pub fn sig_size(&mut self) -> Result { - let rc = unsafe { sys::wc_dilithium_sig_size(&mut self.ws_key) }; + let rc = unsafe { sys::wc_MlDsaKey_SigSize(&mut self.ws_key) }; if rc < 0 { return Err(rc); } @@ -546,19 +546,19 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_check_key, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_check_key, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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()"); /// } /// ``` - #[cfg(dilithium_check_key)] + #[cfg(mldsa_check_key)] pub fn check_key(&mut self) -> Result<(), i32> { - let rc = unsafe { sys::wc_dilithium_check_key(&mut self.ws_key) }; + let rc = unsafe { sys::wc_MlDsaKey_CheckKey(&mut self.ws_key) }; if rc != 0 { return Err(rc); } @@ -579,25 +579,25 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_import, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut pub_buf = vec![0u8; key.pub_size().unwrap()]; /// key.export_public(&mut pub_buf).expect("Error with export_public()"); - /// 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_public(&pub_buf).expect("Error with import_public()"); /// } /// ``` - #[cfg(dilithium_import)] + #[cfg(mldsa_import)] pub fn import_public(&mut self, public: &[u8]) -> Result<(), i32> { let public_size = crate::buffer_len_to_u32(public.len())?; let rc = unsafe { - sys::wc_dilithium_import_public(public.as_ptr(), public_size, &mut self.ws_key) + sys::wc_MlDsaKey_ImportPubRaw(&mut self.ws_key, public.as_ptr(), public_size) }; if rc != 0 { return Err(rc); @@ -622,25 +622,25 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_import, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut priv_buf = vec![0u8; key.size().unwrap()]; /// key.export_private(&mut priv_buf).expect("Error with export_private()"); - /// 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_private(&priv_buf).expect("Error with import_private()"); /// } /// ``` - #[cfg(dilithium_import)] + #[cfg(mldsa_import)] pub fn import_private(&mut self, private: &[u8]) -> Result<(), i32> { let private_size = crate::buffer_len_to_u32(private.len())?; let rc = unsafe { - sys::wc_dilithium_import_private(private.as_ptr(), private_size, &mut self.ws_key) + sys::wc_MlDsaKey_ImportPrivRaw(&mut self.ws_key, private.as_ptr(), private_size) }; if rc != 0 { return Err(rc); @@ -663,30 +663,30 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_import, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut priv_buf = vec![0u8; key.size().unwrap()]; /// let mut pub_buf = vec![0u8; key.pub_size().unwrap()]; /// 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()"); /// } /// ``` - #[cfg(dilithium_import)] + #[cfg(mldsa_import)] pub fn import_key(&mut self, private: &[u8], public: &[u8]) -> Result<(), i32> { let private_size = crate::buffer_len_to_u32(private.len())?; let public_size = crate::buffer_len_to_u32(public.len())?; let rc = unsafe { - sys::wc_dilithium_import_key( + sys::wc_MlDsaKey_ImportKey( + &mut self.ws_key, private.as_ptr(), private_size, public.as_ptr(), public_size, - &mut self.ws_key, ) }; if rc != 0 { @@ -710,23 +710,23 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut pub_buf = vec![0u8; key.pub_size().unwrap()]; /// let written = key.export_public(&mut pub_buf).expect("Error with export_public()"); - /// assert_eq!(written, Dilithium::LEVEL2_PUB_KEY_SIZE); + /// assert_eq!(written, MlDsa::LEVEL2_PUB_KEY_SIZE); /// } /// ``` - #[cfg(dilithium_export)] + #[cfg(mldsa_export)] pub fn export_public(&mut self, public: &mut [u8]) -> Result { let mut public_size = crate::buffer_len_to_u32(public.len())?; let rc = unsafe { - sys::wc_dilithium_export_public(&mut self.ws_key, public.as_mut_ptr(), &mut public_size) + sys::wc_MlDsaKey_ExportPubRaw(&mut self.ws_key, public.as_mut_ptr(), &mut public_size) }; if rc != 0 { return Err(rc); @@ -749,23 +749,23 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut priv_buf = vec![0u8; key.size().unwrap()]; /// let written = key.export_private(&mut priv_buf).expect("Error with export_private()"); - /// assert_eq!(written, Dilithium::LEVEL2_KEY_SIZE); + /// assert_eq!(written, MlDsa::LEVEL2_KEY_SIZE); /// } /// ``` - #[cfg(dilithium_export)] + #[cfg(mldsa_export)] pub fn export_private(&mut self, private: &mut [u8]) -> Result { let mut private_size = crate::buffer_len_to_u32(private.len())?; let rc = unsafe { - sys::wc_dilithium_export_private( + sys::wc_MlDsaKey_ExportPrivRaw( &mut self.ws_key, private.as_mut_ptr(), &mut private_size, ) }; @@ -793,24 +793,24 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_export, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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 mut priv_buf = vec![0u8; key.size().unwrap()]; /// let mut pub_buf = vec![0u8; key.pub_size().unwrap()]; /// key.export_key(&mut priv_buf, &mut pub_buf).expect("Error with export_key()"); /// } /// ``` - #[cfg(dilithium_export)] + #[cfg(mldsa_export)] pub fn export_key(&mut self, private: &mut [u8], public: &mut [u8]) -> Result<(), i32> { let mut private_size = crate::buffer_len_to_u32(private.len())?; let mut public_size = crate::buffer_len_to_u32(public.len())?; let rc = unsafe { - sys::wc_dilithium_export_key( + sys::wc_MlDsaKey_ExportKey( &mut self.ws_key, private.as_mut_ptr(), &mut private_size, public.as_mut_ptr(), &mut public_size, @@ -830,7 +830,7 @@ impl Dilithium { /// * `sig`: Output buffer to hold the signature. Must be at least /// `sig_size()` bytes. /// * `rng`: RNG instance for hedged signing. For deterministic signing, - /// use [`Dilithium::sign_msg_with_seed()`] instead. + /// use [`MlDsa::sign_msg_with_seed()`] instead. /// /// # Returns /// @@ -840,21 +840,21 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_sign, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_sign, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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!"; /// let mut sig = vec![0u8; key.sig_size().unwrap()]; /// let sig_len = key.sign_msg(message, &mut sig, &mut rng) /// .expect("Error with sign_msg()"); - /// assert_eq!(sig_len, Dilithium::LEVEL2_SIG_SIZE); + /// assert_eq!(sig_len, MlDsa::LEVEL2_SIG_SIZE); /// } /// ``` - #[cfg(all(dilithium_sign, random))] + #[cfg(all(mldsa_sign, random))] pub fn sign_msg( &mut self, msg: &[u8], @@ -864,11 +864,11 @@ impl Dilithium { let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_msg( + sys::wc_MlDsaKey_SignCtx( + &mut self.ws_key, core::ptr::null(), 0, - msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + msg.as_ptr(), msg_len, rng.wc_rng, ) }; @@ -887,7 +887,7 @@ impl Dilithium { /// * `sig`: Output buffer to hold the signature. Must be at least /// `sig_size()` bytes. /// * `rng`: RNG instance for hedged signing. For deterministic signing, - /// use [`Dilithium::sign_ctx_msg_with_seed()`] instead. + /// use [`MlDsa::sign_ctx_msg_with_seed()`] instead. /// /// # Returns /// @@ -897,12 +897,12 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_sign, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_sign, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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!"; /// let ctx = b"my context"; @@ -911,7 +911,7 @@ impl Dilithium { /// .expect("Error with sign_ctx_msg()"); /// } /// ``` - #[cfg(all(dilithium_sign, random))] + #[cfg(all(mldsa_sign, random))] pub fn sign_ctx_msg( &mut self, ctx: &[u8], @@ -926,11 +926,11 @@ impl Dilithium { let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_msg( + sys::wc_MlDsaKey_SignCtx( + &mut self.ws_key, ctx.as_ptr(), ctx_len, - msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + msg.as_ptr(), msg_len, rng.wc_rng, ) }; @@ -953,13 +953,13 @@ impl Dilithium { /// * `sig`: Output buffer to hold the signature. Must be at least /// `sig_size()` bytes. /// * `rng`: RNG instance for hedged signing. For deterministic signing, - /// use [`Dilithium::sign_ctx_hash_with_seed()`] instead. + /// use [`MlDsa::sign_ctx_hash_with_seed()`] instead. /// /// # Returns /// /// Returns either Ok(size) containing the number of bytes written to `sig` /// on success or Err(e) containing the wolfSSL library error code value. - #[cfg(all(dilithium_sign, random))] + #[cfg(all(mldsa_sign, random))] pub fn sign_ctx_hash( &mut self, ctx: &[u8], @@ -975,12 +975,12 @@ impl Dilithium { let hash_len = crate::buffer_len_to_u32(hash.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_hash( + sys::wc_MlDsaKey_SignCtxHash( + &mut self.ws_key, ctx.as_ptr(), ctx_len, - hash_alg, - hash.as_ptr(), hash_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + hash.as_ptr(), hash_len, + hash_alg, rng.wc_rng, ) }; @@ -999,7 +999,7 @@ impl Dilithium { /// /// * `msg`: Message to sign. /// * `sig`: Output buffer to hold the signature. - /// * `seed`: Random seed bytes (`DILITHIUM_RND_SZ` = 32 bytes). + /// * `seed`: Random seed bytes (`MLDSA_RND_SZ` = 32 bytes). /// /// # Returns /// @@ -1009,11 +1009,11 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key_from_seed, dilithium_sign_with_seed))] + /// #[cfg(all(mldsa, mldsa_make_key_from_seed, mldsa_sign_with_seed))] /// { - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// let key_seed = [0x42u8; 32]; - /// 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 message = b"Hello, ML-DSA!"; /// let sign_seed = [0x55u8; 32]; @@ -1022,24 +1022,24 @@ impl Dilithium { /// .expect("Error with sign_msg_with_seed()"); /// } /// ``` - #[cfg(dilithium_sign_with_seed)] + #[cfg(mldsa_sign_with_seed)] pub fn sign_msg_with_seed( &mut self, msg: &[u8], sig: &mut [u8], seed: &[u8], ) -> Result { - if seed.len() != sys::DILITHIUM_RND_SZ as usize { + if seed.len() != sys::MLDSA_RND_SZ as usize { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_msg_with_seed( + sys::wc_MlDsaKey_SignCtxWithSeed( + &mut self.ws_key, core::ptr::null(), 0, - msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + msg.as_ptr(), msg_len, seed.as_ptr(), ) }; @@ -1056,13 +1056,13 @@ impl Dilithium { /// * `ctx`: Context string (at most 255 bytes). /// * `msg`: Message to sign. /// * `sig`: Output buffer to hold the signature. - /// * `seed`: Random seed bytes (`DILITHIUM_RND_SZ` = 32 bytes). + /// * `seed`: Random seed bytes (`MLDSA_RND_SZ` = 32 bytes). /// /// # Returns /// /// Returns either Ok(size) containing the number of bytes written to `sig` /// on success or Err(e) containing the wolfSSL library error code value. - #[cfg(dilithium_sign_with_seed)] + #[cfg(mldsa_sign_with_seed)] pub fn sign_ctx_msg_with_seed( &mut self, ctx: &[u8], @@ -1073,18 +1073,18 @@ impl Dilithium { if ctx.len() > 255 { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } - if seed.len() != sys::DILITHIUM_RND_SZ as usize { + if seed.len() != sys::MLDSA_RND_SZ as usize { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } let ctx_len = ctx.len() as u8; let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_msg_with_seed( + sys::wc_MlDsaKey_SignCtxWithSeed( + &mut self.ws_key, ctx.as_ptr(), ctx_len, - msg.as_ptr(), msg_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + msg.as_ptr(), msg_len, seed.as_ptr(), ) }; @@ -1103,13 +1103,13 @@ impl Dilithium { /// * `hash_alg`: Hash algorithm identifier (e.g. `WC_HASH_TYPE_SHA256`). /// * `hash`: Hash digest of the message to sign. /// * `sig`: Output buffer to hold the signature. - /// * `seed`: Random seed bytes (`DILITHIUM_RND_SZ` = 32 bytes). + /// * `seed`: Random seed bytes (`MLDSA_RND_SZ` = 32 bytes). /// /// # Returns /// /// Returns either Ok(size) containing the number of bytes written to `sig` /// on success or Err(e) containing the wolfSSL library error code value. - #[cfg(dilithium_sign_with_seed)] + #[cfg(mldsa_sign_with_seed)] pub fn sign_ctx_hash_with_seed( &mut self, ctx: &[u8], @@ -1121,19 +1121,19 @@ impl Dilithium { if ctx.len() > 255 { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } - if seed.len() != sys::DILITHIUM_RND_SZ as usize { + if seed.len() != sys::MLDSA_RND_SZ as usize { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); } let ctx_len = ctx.len() as u8; let hash_len = crate::buffer_len_to_u32(hash.len())?; let mut sig_len = crate::buffer_len_to_u32(sig.len())?; let rc = unsafe { - sys::wc_dilithium_sign_ctx_hash_with_seed( + sys::wc_MlDsaKey_SignCtxHashWithSeed( + &mut self.ws_key, ctx.as_ptr(), ctx_len, - hash_alg, - hash.as_ptr(), hash_len, sig.as_mut_ptr(), &mut sig_len, - &mut self.ws_key, + hash.as_ptr(), hash_len, + hash_alg, seed.as_ptr(), ) }; @@ -1158,12 +1158,12 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_sign, dilithium_verify, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_sign, mldsa_verify, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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!"; /// let mut sig = vec![0u8; key.sig_size().unwrap()]; @@ -1174,18 +1174,18 @@ impl Dilithium { /// assert!(valid); /// } /// ``` - #[cfg(dilithium_verify)] + #[cfg(mldsa_verify)] pub fn verify_msg(&mut self, sig: &[u8], msg: &[u8]) -> Result { let sig_len = crate::buffer_len_to_u32(sig.len())?; let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut res = 0i32; let rc = unsafe { - sys::wc_dilithium_verify_ctx_msg( + sys::wc_MlDsaKey_VerifyCtx( + &mut self.ws_key, sig.as_ptr(), sig_len, core::ptr::null(), 0, msg.as_ptr(), msg_len, &mut res, - &mut self.ws_key, ) }; if rc != 0 { @@ -1210,12 +1210,12 @@ impl Dilithium { /// # Example /// /// ```rust - /// #[cfg(all(dilithium, dilithium_make_key, dilithium_sign, dilithium_verify, random))] + /// #[cfg(all(mldsa, mldsa_make_key, mldsa_sign, mldsa_verify, random))] /// { /// use wolfssl_wolfcrypt::random::RNG; - /// use wolfssl_wolfcrypt::dilithium::Dilithium; + /// use wolfssl_wolfcrypt::mldsa::MlDsa; /// 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!"; /// let ctx = b"my context"; @@ -1227,7 +1227,7 @@ impl Dilithium { /// assert!(valid); /// } /// ``` - #[cfg(dilithium_verify)] + #[cfg(mldsa_verify)] pub fn verify_ctx_msg(&mut self, sig: &[u8], ctx: &[u8], msg: &[u8]) -> Result { if ctx.len() > 255 { return Err(sys::wolfCrypt_ErrorCodes_BUFFER_E); @@ -1237,12 +1237,12 @@ impl Dilithium { let msg_len = crate::buffer_len_to_u32(msg.len())?; let mut res = 0i32; let rc = unsafe { - sys::wc_dilithium_verify_ctx_msg( + sys::wc_MlDsaKey_VerifyCtx( + &mut self.ws_key, sig.as_ptr(), sig_len, ctx.as_ptr(), ctx_len, msg.as_ptr(), msg_len, &mut res, - &mut self.ws_key, ) }; if rc != 0 { @@ -1267,7 +1267,7 @@ impl Dilithium { /// /// Returns either Ok(true) if the signature is valid, Ok(false) if it is /// invalid, or Err(e) containing the wolfSSL library error code value. - #[cfg(dilithium_verify)] + #[cfg(mldsa_verify)] pub fn verify_ctx_hash( &mut self, sig: &[u8], @@ -1283,13 +1283,13 @@ impl Dilithium { let hash_len = crate::buffer_len_to_u32(hash.len())?; let mut res = 0i32; let rc = unsafe { - sys::wc_dilithium_verify_ctx_hash( + sys::wc_MlDsaKey_VerifyCtxHash( + &mut self.ws_key, sig.as_ptr(), sig_len, ctx.as_ptr(), ctx_len, - hash_alg, hash.as_ptr(), hash_len, + hash_alg, &mut res, - &mut self.ws_key, ) }; if rc != 0 { @@ -1299,19 +1299,19 @@ impl Dilithium { } } -impl Dilithium { +impl MlDsa { fn zeroize(&mut self) { unsafe { crate::zeroize_raw(&mut self.ws_key); } } } -impl Drop for Dilithium { - /// Safely free the underlying wolfSSL Dilithium key context. +impl Drop for MlDsa { + /// Safely free the underlying wolfSSL ML-DSA key context. /// - /// This calls `wc_dilithium_free()`. The Rust Drop trait guarantees this - /// is called when the `Dilithium` struct goes out of scope. + /// This calls `wc_MlDsaKey_Free()`. The Rust Drop trait guarantees this + /// is called when the `MlDsa` struct goes out of scope. fn drop(&mut self) { - unsafe { sys::wc_dilithium_free(&mut self.ws_key); } + unsafe { sys::wc_MlDsaKey_Free(&mut self.ws_key); } self.zeroize(); } } diff --git a/wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs b/wrapper/rust/wolfssl-wolfcrypt/tests/test_mldsa.rs similarity index 75% rename from wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs rename to wrapper/rust/wolfssl-wolfcrypt/tests/test_mldsa.rs index d8b3b452d09..99ab17b6d55 100644 --- a/wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs +++ b/wrapper/rust/wolfssl-wolfcrypt/tests/test_mldsa.rs @@ -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];