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
36 changes: 35 additions & 1 deletion wrapper/rust/wolfssl-wolfcrypt/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions wrapper/rust/wolfssl-wolfcrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ std = []
rand_core = ["dep:rand_core"]
aead = ["dep:aead"]
cipher = ["dep:cipher"]
digest = ["dep:digest"]
signature = ["dep:signature"]

[dependencies]
rand_core = { version = "0.10", optional = true, default-features = false }
aead = { version = "0.5", optional = true, default-features = false }
cipher = { version = "0.5", optional = true, default-features = false }
digest = { version = "0.11", optional = true, default-features = false, features = ["block-api"] }
signature = { version = "2.2", optional = true, default-features = false }
zeroize = { version = "1.3", default-features = false, features = ["derive"] }

[dev-dependencies]
aead = { version = "0.5", features = ["alloc", "dev"] }
cipher = "0.5"
digest = { version = "0.11", features = ["dev"] }
signature = "2.2"

[build-dependencies]
bindgen = "0.72.1"
Expand Down
2 changes: 1 addition & 1 deletion wrapper/rust/wolfssl-wolfcrypt/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FEATURES := rand_core,aead,cipher
FEATURES := rand_core,aead,cipher,digest,signature
CARGO_FEATURE_FLAGS := --features $(FEATURES)

.PHONY: all
Expand Down
16 changes: 16 additions & 0 deletions wrapper/rust/wolfssl-wolfcrypt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,22 @@ fn scan_cfg() -> Result<()> {
check_cfg(&binding, "wc_RNG_DRBG_Reseed", "random_hashdrbg");
check_cfg(&binding, "wc_InitRng", "random");

// When WOLFSSL_NO_MALLOC is set without WOLFSSL_STATIC_MEMORY, the
// WC_RNG struct contains an inline `drbg_data` field and wolfCrypt sets
// `rng->drbg = &rng->drbg_data` — a self-referential pointer. Rust
// moves values by memcpy, which would silently invalidate that pointer.
// Detect this configuration and refuse to build.
if binding.contains("drbg_data") {
eprintln!(
"error: wolfSSL appears to be built with WOLFSSL_NO_MALLOC \
(without WOLFSSL_STATIC_MEMORY). This embeds a self-referential \
pointer inside WC_RNG (drbg -> drbg_data) that is incompatible \
with Rust move semantics. Please rebuild wolfSSL without \
WOLFSSL_NO_MALLOC, or enable WOLFSSL_STATIC_MEMORY."
);
std::process::exit(1);
}
Comment on lines +436 to +450
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

binding.contains("drbg_data") is an overly broad heuristic that can cause false positives (any unrelated symbol/comment containing that substring will hard-error the build). Prefer a more targeted check (mandatory): e.g., regex match the WC_RNG struct definition (or the generated bindgen struct) and confirm it contains a drbg_data field and the self-referential drbg pointer arrangement you’re trying to guard against.

Copilot uses AI. Check for mistakes.

/* rsa */
check_cfg(&binding, "wc_InitRsaKey", "rsa");
check_cfg(&binding, "wc_RsaDirect", "rsa_direct");
Expand Down
2 changes: 1 addition & 1 deletion wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl Drop for ECCPoint {
/// `import_x963_ex()`, `import_private_key()`, `import_private_key_ex()`,
/// `import_raw()`, or `import_raw_ex()`.
pub struct ECC {
wc_ecc_key: sys::ecc_key,
pub(crate) wc_ecc_key: sys::ecc_key,
}

#[cfg(ecc_curve_ids)]
Expand Down
Loading
Loading