Skip to content

Rust crate updates 2026-05-05#10402

Open
holtrop-wolfssl wants to merge 6 commits intowolfSSL:masterfrom
holtrop-wolfssl:rust-crate-updates-2026-05-05
Open

Rust crate updates 2026-05-05#10402
holtrop-wolfssl wants to merge 6 commits intowolfSSL:masterfrom
holtrop-wolfssl:rust-crate-updates-2026-05-05

Conversation

@holtrop-wolfssl
Copy link
Copy Markdown
Contributor

Description

commit bb8cfdeef5b8ea401821b9196df442e45762b212 (HEAD -> rust-crate-updates-2026-05-05, origin/rust-crate-updates-2026-05-05)
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Tue May 5 11:23:29 2026 -0400

    Rust wrapper: add blake2_digest module

commit 9cb17a916f6dee7760da100c6aba25b7919440d3
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Tue May 5 08:33:50 2026 -0400

    Rust wrapper: add blake2_mac module

commit 48026098966f2982858b90da8fc33ccc794e4094
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Fri May 1 07:49:26 2026 -0400

    Rust wrapper: implement Clone for HMAC types

commit f831e97548e779186b368dd9574446075ff9664f
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Thu Apr 30 09:27:27 2026 -0400

    Rust wrapper: add Aes192Ccm and Aes192Gcm

commit d4cac6fe066dd8216af879a1ebfd1341867ea15f
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Thu Apr 30 08:40:43 2026 -0400

    Rust wrapper: store pointer to C ECC key struct instead of instance
    
    This fixes internal pointers breaking if Rust moves the ECC struct (with
    some build configurations).

commit e9bb45c1aa62eacba06ad20d9098d2fa63b18ece
Author: Josh Holtrop <josh@wolfssl.com>
Date:   Mon Apr 27 22:31:56 2026 -0400

    Rust wrapper: ensure memory safety for C RNG struct
    
    - store pointer to WC_RNG instead of full struct
    - enforce RNG is not dropped before consumer structs
    
    The C library stores a pointer via the set_rng() methods on a few
    structs (e.g. RSA). This change holds a reference (or instance) of RNG
    within the consumer structs to ensure it is kept alive if set_rng (or
    now set_shared_rng) is used.

Testing

Unit/CI tests.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

- store pointer to WC_RNG instead of full struct
- enforce RNG is not dropped before consumer structs

The C library stores a pointer via the set_rng() methods on a few
structs (e.g. RSA). This change holds a reference (or instance) of RNG
within the consumer structs to ensure it is kept alive if set_rng (or
now set_shared_rng) is used.
This fixes internal pointers breaking if Rust moves the ECC struct (with
some build configurations).
@holtrop-wolfssl holtrop-wolfssl self-assigned this May 5, 2026
Copilot AI review requested due to automatic review settings May 5, 2026 20:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the wolfssl-wolfcrypt Rust wrapper to (1) improve RNG lifetime safety across FFI consumers, (2) add RustCrypto trait integrations for BLAKE2 digest/MAC, and (3) extend AEAD support with AES-192 CCM/GCM wrappers, along with corresponding test updates.

Changes:

  • Refactors RNG to own a C-heap WC_RNG* and updates RNG-taking APIs to accept &RNG (plus new set_shared_rng(Arc<RNG>) for consumers that store an RNG pointer internally).
  • Adds RustCrypto digest::Digest wrappers (blake2_digest) and digest::Mac wrappers (blake2_mac) for BLAKE2b/BLAKE2s.
  • Adds AEAD wrappers and tests for AES-192-GCM and AES-192-CCM, and adds Clone support for HMAC MAC types.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wrapper/rust/wolfssl-wolfcrypt/tests/test_rsa.rs Updates tests to new RNG borrowing/sharing patterns (&RNG, set_shared_rng).
wrapper/rust/wolfssl-wolfcrypt/tests/test_random.rs Updates RNG tests to match RNG methods taking &self (no mut).
wrapper/rust/wolfssl-wolfcrypt/tests/test_hmac_mac.rs Adds a clone/forking test to validate cloned HMAC MAC state equivalence.
wrapper/rust/wolfssl-wolfcrypt/tests/test_ecc.rs Updates ECC tests for RNG ownership and shared RNG binding.
wrapper/rust/wolfssl-wolfcrypt/tests/test_curve25519.rs Updates Curve25519 tests for conditional RNG sharing when blinding is enabled.
wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_mac.rs Adds MAC trait tests for BLAKE2b/BLAKE2s keyed constructions.
wrapper/rust/wolfssl-wolfcrypt/tests/test_blake2_digest.rs Adds Digest trait tests for typed BLAKE2b/BLAKE2s hashers.
wrapper/rust/wolfssl-wolfcrypt/tests/test_aes.rs Adds AES-192-GCM/CCM AEAD roundtrip tests.
wrapper/rust/wolfssl-wolfcrypt/src/rsa.rs Refactors RSA RNG usage (&RNG params, owned/shared RNG binding stored to ensure lifetime).
wrapper/rust/wolfssl-wolfcrypt/src/rsa_pkcs1v15.rs Updates RSA PKCS#1v1.5 signing wrapper to new RNG pointer model.
wrapper/rust/wolfssl-wolfcrypt/src/random.rs Refactors RNG to own WC_RNG* allocated via wc_rng_new_ex, updates methods to take &self.
wrapper/rust/wolfssl-wolfcrypt/src/mlkem.rs Updates ML-KEM APIs to accept &RNG and pass WC_RNG* through FFI.
wrapper/rust/wolfssl-wolfcrypt/src/lms.rs Updates LMS keygen to accept &RNG.
wrapper/rust/wolfssl-wolfcrypt/src/lib.rs Adds alloc support and conditionally exports new BLAKE2 digest/MAC modules.
wrapper/rust/wolfssl-wolfcrypt/src/hmac.rs Implements deep Clone for HMAC via wc_HmacCopy.
wrapper/rust/wolfssl-wolfcrypt/src/hmac_mac.rs Derives Clone for HMAC MAC wrapper types.
wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs Updates Ed448 key generation to accept &RNG.
wrapper/rust/wolfssl-wolfcrypt/src/ed25519.rs Updates Ed25519 key generation to accept &RNG.
wrapper/rust/wolfssl-wolfcrypt/src/ecdsa.rs Adapts ECDSA wrapper FFI calls to ECC key pointer storage changes.
wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs Refactors ECC to store a C-heap ecc_key* and adds owned/shared RNG binding.
wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs Updates Dilithium APIs to accept &RNG.
wrapper/rust/wolfssl-wolfcrypt/src/dh.rs Updates DH APIs to accept &RNG.
wrapper/rust/wolfssl-wolfcrypt/src/curve25519.rs Updates Curve25519 APIs to accept &RNG, adds RNG ownership/sharing for blinding.
wrapper/rust/wolfssl-wolfcrypt/src/blake2_mac.rs Adds RustCrypto Mac trait wrappers for keyed BLAKE2b/BLAKE2s.
wrapper/rust/wolfssl-wolfcrypt/src/blake2_digest.rs Adds RustCrypto Digest trait wrappers for typed BLAKE2b/BLAKE2s hashers.
wrapper/rust/wolfssl-wolfcrypt/src/aes.rs Adds AES-192 CCM/GCM AEAD wrappers.
wrapper/rust/wolfssl-wolfcrypt/Makefile Enables the new alloc feature in the Makefile feature set.
wrapper/rust/wolfssl-wolfcrypt/Cargo.toml Replaces std feature with alloc and keeps feature list in sync with new APIs/modules.
Comments suppressed due to low confidence (1)

wrapper/rust/wolfssl-wolfcrypt/Cargo.toml:22

  • This change removes the previously exported std feature and adds a new alloc feature. Together with the public API signature changes in this PR (e.g., set_rng/generate now taking RNG or &RNG instead of &mut RNG), this is a semver-breaking change for a 1.x crate. Consider either (a) bumping the crate major version, or (b) keeping std as a backwards-compatible feature alias to alloc and providing compatibility shims where practical.
[features]
alloc = []
rand_core = ["dep:rand_core"]
aead = ["dep:aead"]
cipher = ["dep:cipher"]
mac = ["digest/mac"]
digest = ["dep:digest"]
signature = ["dep:signature"]
password-hash = ["dep:password-hash", "password-hash/phc"]
kem = ["dep:kem", "hybrid-array/extra-sizes"]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +400 to +409
fn new_ecc_key(heap: *mut core::ffi::c_void, dev_id: i32) -> Result<*mut sys::ecc_key, i32> {
let key = unsafe { sys::wc_ecc_key_new(heap) };
if key.is_null() {
return Err(sys::wolfCrypt_ErrorCodes_MEMORY_E);
}
let rc = unsafe { sys::wc_ecc_init_ex(key, heap, dev_id) };
if rc != 0 {
unsafe { sys::wc_ecc_key_free(key); }
return Err(rc);
}
Comment on lines +1686 to +1693
/// instance.
///
/// # Safety contract
///
/// The caller must ensure that the `RNG` instance is not dropped before
/// this `ECC` instance. The `ECC` struct holds an internal pointer to the
/// `RNG`'s underlying `WC_RNG` context, and dropping the `RNG` first
/// would result in a dangling pointer.
Comment on lines +1188 to +1195
/// instance.
///
/// # Safety contract
///
/// The caller must ensure that the `RNG` instance is not dropped before
/// this `RSA` instance. The `RSA` struct holds an internal pointer to the
/// `RNG`'s underlying `WC_RNG` context, and dropping the `RNG` first
/// would result in a dangling pointer.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

MemBrowse Memory Report

No memory changes detected for:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants