Skip to content

Commit 1da353b

Browse files
Merge pull request #10248 from holtrop-wolfssl/rust-digest-signature
Rust wrapper: add digest and signature crate trait implementations
2 parents cf2db42 + 9c50689 commit 1da353b

17 files changed

Lines changed: 1674 additions & 4 deletions

wrapper/rust/wolfssl-wolfcrypt/Cargo.lock

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wrapper/rust/wolfssl-wolfcrypt/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ std = []
1515
rand_core = ["dep:rand_core"]
1616
aead = ["dep:aead"]
1717
cipher = ["dep:cipher"]
18+
digest = ["dep:digest"]
19+
signature = ["dep:signature"]
1820

1921
[dependencies]
2022
rand_core = { version = "0.10", optional = true, default-features = false }
2123
aead = { version = "0.5", optional = true, default-features = false }
2224
cipher = { version = "0.5", optional = true, default-features = false }
25+
digest = { version = "0.11", optional = true, default-features = false, features = ["block-api"] }
26+
signature = { version = "2.2", optional = true, default-features = false }
2327
zeroize = { version = "1.3", default-features = false, features = ["derive"] }
2428

2529
[dev-dependencies]
2630
aead = { version = "0.5", features = ["alloc", "dev"] }
2731
cipher = "0.5"
32+
digest = { version = "0.11", features = ["dev"] }
33+
signature = "2.2"
2834

2935
[build-dependencies]
3036
bindgen = "0.72.1"

wrapper/rust/wolfssl-wolfcrypt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FEATURES := rand_core,aead,cipher
1+
FEATURES := rand_core,aead,cipher,digest,signature
22
CARGO_FEATURE_FLAGS := --features $(FEATURES)
33

44
.PHONY: all

wrapper/rust/wolfssl-wolfcrypt/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,22 @@ fn scan_cfg() -> Result<()> {
433433
check_cfg(&binding, "wc_RNG_DRBG_Reseed", "random_hashdrbg");
434434
check_cfg(&binding, "wc_InitRng", "random");
435435

436+
// When WOLFSSL_NO_MALLOC is set without WOLFSSL_STATIC_MEMORY, the
437+
// WC_RNG struct contains an inline `drbg_data` field and wolfCrypt sets
438+
// `rng->drbg = &rng->drbg_data` — a self-referential pointer. Rust
439+
// moves values by memcpy, which would silently invalidate that pointer.
440+
// Detect this configuration and refuse to build.
441+
if binding.contains("drbg_data") {
442+
eprintln!(
443+
"error: wolfSSL appears to be built with WOLFSSL_NO_MALLOC \
444+
(without WOLFSSL_STATIC_MEMORY). This embeds a self-referential \
445+
pointer inside WC_RNG (drbg -> drbg_data) that is incompatible \
446+
with Rust move semantics. Please rebuild wolfSSL without \
447+
WOLFSSL_NO_MALLOC, or enable WOLFSSL_STATIC_MEMORY."
448+
);
449+
std::process::exit(1);
450+
}
451+
436452
/* rsa */
437453
check_cfg(&binding, "wc_InitRsaKey", "rsa");
438454
check_cfg(&binding, "wc_RsaDirect", "rsa_direct");

wrapper/rust/wolfssl-wolfcrypt/src/ecc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl Drop for ECCPoint {
296296
/// `import_x963_ex()`, `import_private_key()`, `import_private_key_ex()`,
297297
/// `import_raw()`, or `import_raw_ex()`.
298298
pub struct ECC {
299-
wc_ecc_key: sys::ecc_key,
299+
pub(crate) wc_ecc_key: sys::ecc_key,
300300
}
301301

302302
#[cfg(ecc_curve_ids)]

0 commit comments

Comments
 (0)