Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions wrapper/rust/wolfssl-wolfcrypt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,14 @@ fn scan_cfg() -> Result<()> {
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_Size", "mldsa_size");
check_cfg(&binding, "wc_MlDsaKey_PrivSize", "mldsa_priv_size");
check_cfg(&binding, "wc_MlDsaKey_PubSize", "mldsa_pub_size");
check_cfg(&binding, "wc_MlDsaKey_SigSize", "mldsa_sig_size");
check_cfg(&binding, "wc_MlDsaKey_ImportPubRaw", "mldsa_import_public");
check_cfg(&binding, "wc_MlDsaKey_ImportPrivRaw", "mldsa_import_private");
check_cfg(&binding, "wc_MlDsaKey_ExportPubRaw", "mldsa_export_public");
check_cfg(&binding, "wc_MlDsaKey_ExportPrivRaw", "mldsa_export_private");
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");
Expand Down
41 changes: 25 additions & 16 deletions wrapper/rust/wolfssl-wolfcrypt/src/mldsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_size, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -440,6 +440,7 @@ impl MlDsa {
/// assert_eq!(sz, MlDsa::LEVEL2_KEY_SIZE);
/// }
/// ```
#[cfg(mldsa_size)]
pub fn size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_MlDsaKey_Size(&mut self.ws_key) };
if rc < 0 {
Expand All @@ -459,7 +460,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_priv_size, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -470,6 +471,7 @@ impl MlDsa {
/// assert_eq!(sz, MlDsa::LEVEL2_PRV_KEY_SIZE);
/// }
/// ```
#[cfg(mldsa_priv_size)]
pub fn priv_size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_MlDsaKey_PrivSize(&mut self.ws_key) };
if rc < 0 {
Expand All @@ -488,7 +490,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_pub_size, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -499,6 +501,7 @@ impl MlDsa {
/// assert_eq!(sz, MlDsa::LEVEL2_PUB_KEY_SIZE);
/// }
/// ```
#[cfg(mldsa_pub_size)]
pub fn pub_size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_MlDsaKey_PubSize(&mut self.ws_key) };
if rc < 0 {
Expand All @@ -517,7 +520,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_sig_size, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -528,6 +531,7 @@ impl MlDsa {
/// assert_eq!(sz, MlDsa::LEVEL2_SIG_SIZE);
/// }
/// ```
#[cfg(mldsa_sig_size)]
pub fn sig_size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_MlDsaKey_SigSize(&mut self.ws_key) };
if rc < 0 {
Expand Down Expand Up @@ -579,7 +583,8 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_pub_size, mldsa_export_public,
/// mldsa_import_public, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -593,7 +598,7 @@ impl MlDsa {
/// key2.import_public(&pub_buf).expect("Error with import_public()");
/// }
/// ```
#[cfg(mldsa_import)]
#[cfg(mldsa_import_public)]
pub fn import_public(&mut self, public: &[u8]) -> Result<(), i32> {
let public_size = crate::buffer_len_to_u32(public.len())?;
let rc = unsafe {
Expand Down Expand Up @@ -622,7 +627,8 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_size, mldsa_export_private,
/// mldsa_import_private, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -636,7 +642,7 @@ impl MlDsa {
/// key2.import_private(&priv_buf).expect("Error with import_private()");
/// }
/// ```
#[cfg(mldsa_import)]
#[cfg(mldsa_import_private)]
pub fn import_private(&mut self, private: &[u8]) -> Result<(), i32> {
let private_size = crate::buffer_len_to_u32(private.len())?;
let rc = unsafe {
Expand All @@ -663,7 +669,9 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_import, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_size, mldsa_pub_size,
/// mldsa_export_private, mldsa_import_private,
/// mldsa_import_public, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -678,7 +686,7 @@ impl MlDsa {
/// key2.import_key(&priv_buf, &pub_buf).expect("Error with import_key()");
/// }
/// ```
#[cfg(mldsa_import)]
#[cfg(all(mldsa_import_private, mldsa_import_public))]
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())?;
Expand Down Expand Up @@ -710,7 +718,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_pub_size, mldsa_export_public, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -722,7 +730,7 @@ impl MlDsa {
/// assert_eq!(written, MlDsa::LEVEL2_PUB_KEY_SIZE);
/// }
/// ```
#[cfg(mldsa_export)]
#[cfg(mldsa_export_public)]
pub fn export_public(&mut self, public: &mut [u8]) -> Result<usize, i32> {
let mut public_size = crate::buffer_len_to_u32(public.len())?;
let rc = unsafe {
Expand All @@ -749,7 +757,7 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_size, mldsa_export_private, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -761,7 +769,7 @@ impl MlDsa {
/// assert_eq!(written, MlDsa::LEVEL2_KEY_SIZE);
/// }
/// ```
#[cfg(mldsa_export)]
#[cfg(mldsa_export_private)]
pub fn export_private(&mut self, private: &mut [u8]) -> Result<usize, i32> {
let mut private_size = crate::buffer_len_to_u32(private.len())?;
let rc = unsafe {
Expand Down Expand Up @@ -793,7 +801,8 @@ impl MlDsa {
/// # Example
///
/// ```rust
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_export, random))]
/// #[cfg(all(mldsa, mldsa_make_key, mldsa_size, mldsa_pub_size,
/// mldsa_export_private, mldsa_export_public, random))]
/// {
/// use wolfssl_wolfcrypt::random::RNG;
/// use wolfssl_wolfcrypt::mldsa::MlDsa;
Expand All @@ -805,7 +814,7 @@ impl MlDsa {
/// key.export_key(&mut priv_buf, &mut pub_buf).expect("Error with export_key()");
/// }
/// ```
#[cfg(mldsa_export)]
#[cfg(all(mldsa_export_private, mldsa_export_public))]
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())?;
Expand Down
20 changes: 14 additions & 6 deletions wrapper/rust/wolfssl-wolfcrypt/tests/test_mldsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ fn test_new_ex() {
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-44.
#[test]
#[cfg(all(mldsa_make_key, mldsa_level2))]
#[cfg(all(mldsa_make_key, mldsa_level2, mldsa_size, mldsa_priv_size,
mldsa_pub_size, mldsa_sig_size))]
fn test_sizes_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
Expand All @@ -79,7 +80,8 @@ fn test_sizes_level44() {
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-65.
#[test]
#[cfg(all(mldsa_make_key, mldsa_level3))]
#[cfg(all(mldsa_make_key, mldsa_level3, mldsa_size, mldsa_priv_size,
mldsa_pub_size, mldsa_sig_size))]
fn test_sizes_level65() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
Expand All @@ -94,7 +96,8 @@ fn test_sizes_level65() {
/// Verify the runtime size queries match the compile-time constants for
/// ML-DSA-87.
#[test]
#[cfg(all(mldsa_make_key, mldsa_level5))]
#[cfg(all(mldsa_make_key, mldsa_level5, mldsa_size, mldsa_priv_size,
mldsa_pub_size, mldsa_sig_size))]
fn test_sizes_level87() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
Expand Down Expand Up @@ -237,7 +240,9 @@ fn test_sign_ctx_verify_level44() {
/// - the re-imported private key can sign messages that verify with the
/// original public key.
#[test]
#[cfg(all(mldsa_make_key, mldsa_import, mldsa_export, mldsa_sign, mldsa_verify))]
#[cfg(all(mldsa_make_key, mldsa_size, mldsa_pub_size, mldsa_sig_size,
mldsa_import_public, mldsa_import_private, mldsa_export_public,
mldsa_export_private, mldsa_sign, mldsa_verify))]
fn test_import_export_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
Expand Down Expand Up @@ -292,7 +297,9 @@ 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(mldsa_make_key, mldsa_import, mldsa_export, mldsa_sign, mldsa_verify))]
#[cfg(all(mldsa_make_key, mldsa_size, mldsa_pub_size, mldsa_sig_size,
mldsa_import_public, mldsa_import_private, mldsa_export_public,
mldsa_export_private, mldsa_sign, mldsa_verify))]
fn test_import_key_level44() {
common::setup();
let mut rng = RNG::new().expect("Error creating RNG");
Expand Down Expand Up @@ -323,7 +330,8 @@ 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(mldsa_make_key_from_seed, mldsa_export))]
#[cfg(all(mldsa_make_key_from_seed, mldsa_size, mldsa_pub_size,
mldsa_export_public, mldsa_export_private))]
fn test_generate_from_seed_determinism() {
common::setup();
// MLDSA_SEED_SZ = 32 bytes
Expand Down
Loading