Skip to content

Commit 3ca90b1

Browse files
Rust wrapper: add signature implementations
1 parent 7f33de0 commit 3ca90b1

15 files changed

Lines changed: 1344 additions & 3 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/Cargo.lock

Lines changed: 7 additions & 0 deletions
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ rand_core = ["dep:rand_core"]
1616
aead = ["dep:aead"]
1717
cipher = ["dep:cipher"]
1818
digest = ["dep:digest"]
19+
signature = ["dep:signature"]
1920

2021
[dependencies]
2122
rand_core = { version = "0.10", optional = true, default-features = false }
2223
aead = { version = "0.5", optional = true, default-features = false }
2324
cipher = { version = "0.5", optional = true, default-features = false }
2425
digest = { version = "0.11", optional = true, default-features = false, features = ["block-api"] }
26+
signature = { version = "2.2", optional = true, default-features = false }
2527
zeroize = { version = "1.3", default-features = false, features = ["derive"] }
2628

2729
[dev-dependencies]
2830
aead = { version = "0.5", features = ["alloc", "dev"] }
2931
cipher = "0.5"
3032
digest = { version = "0.11", features = ["dev"] }
33+
signature = "2.2"
3134

3235
[build-dependencies]
3336
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,digest
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)