Rust wrapper: fix cfg detection in build.rs for dilithium#10699
Open
holtrop-wolfssl wants to merge 1 commit into
Open
Rust wrapper: fix cfg detection in build.rs for dilithium#10699holtrop-wolfssl wants to merge 1 commit into
holtrop-wolfssl wants to merge 1 commit into
Conversation
The C library renamed dilithium to wc_mldsa, but bindgen does not pick up the backward-compatibility macros.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Rust wolfssl-wolfcrypt wrapper to detect and call wolfCrypt’s canonical ML-DSA (wc_mldsa) symbols after the C-side Dilithium rename, so Cargo cfgs and the wrapper build correctly when bindgen doesn’t emit legacy macro aliases.
Changes:
- Updated
build.rscfg scanning to look forwc_MlDsaKey_*functions andWC_MLDSA_*constants instead of legacywc_dilithium_*/DILITHIUM_*. - Switched the Rust Dilithium wrapper implementation to call the canonical
wc_MlDsaKey_*API andMLDSA_*/WC_MLDSA_*constants. - Updated Dilithium test comments to reference
MLDSA_*sizing constants.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| wrapper/rust/wolfssl-wolfcrypt/build.rs | Fixes Cargo cfg detection by scanning for canonical ML-DSA symbols emitted by bindgen. |
| wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs | Migrates the wrapper’s FFI calls/constants from legacy Dilithium spellings to canonical ML-DSA spellings. |
| wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs | Aligns test documentation comments with renamed ML-DSA constants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
85
to
88
| /// 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; | ||
| /// [`Dilithium::generate_from_seed()`] (`MLDSA_SEED_SZ`). | ||
| pub const MLDSA_SEED_SZ: usize = sys::MLDSA_SEED_SZ as usize; | ||
|
|
Comment on lines
443
to
445
| pub fn size(&mut self) -> Result<usize, i32> { | ||
| 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 { |
Comment on lines
473
to
475
| pub fn priv_size(&mut self) -> Result<usize, i32> { | ||
| 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 { |
Comment on lines
502
to
504
| pub fn pub_size(&mut self) -> Result<usize, i32> { | ||
| 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 { |
Comment on lines
639
to
644
| #[cfg(dilithium_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) | ||
| }; |
Comment on lines
681
to
+686
| #[cfg(dilithium_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( |
Comment on lines
764
to
769
| #[cfg(dilithium_export)] | ||
| 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 { | ||
| sys::wc_dilithium_export_private( | ||
| sys::wc_MlDsaKey_ExportPrivRaw( | ||
| &mut self.ws_key, private.as_mut_ptr(), &mut private_size, |
Comment on lines
808
to
814
| #[cfg(dilithium_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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Rust wrapper: fix cfg detection in build.rs for dilithium
The C library renamed dilithium to wc_mldsa, but bindgen does not pick up the backward-compatibility macros.
Testing
How did you test?
Checklist