Skip to content

Commit bd4bebe

Browse files
committed
feat: add wolfssl git submodule; update for new wolfSSL API
- Add wolfssl-src/wolfssl as a git submodule (github.com/wolfSSL/wolfssl @ 0c9b639) so vendored builds work out-of-the-box after `git submodule update --init`, with no WOLFSSL_SRC required - Add submodule fallback (step 3) in resolve_source_dir; skip empty WOLFSSL_SRC so callers can unset it without triggering a panic - Add include = [...] to wolfssl-src/Cargo.toml so cargo publish captures the submodule tree - Add WOLFSSL_TLS13 to user_settings.h (required by wolfcrypt-tls) - Update wolfcrypt-wrapper Dilithium calls to new wolfSSL API: wc_dilithium_{sign,verify}_msg → wc_dilithium_{sign,verify}_ctx_msg (upstream added context-string params per FIPS 204 final) - Point .cargo/config.toml at wolfssl-repo-install / wolfssl-repo
1 parent 5c72f14 commit bd4bebe

7 files changed

Lines changed: 43 additions & 15 deletions

File tree

.cargo/config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ rustflags = ["-C", "link-arg=-Tmemory.x", "-C", "link-arg=-Tlink.x"]
1919
# Use the local wolfssl build that has HAVE_DILITHIUM and WOLF_CRYPTO_CB enabled.
2020
# Built from ~/wolfssl with -DWOLFSSL_CRYPTOCB=yes -DWOLFSSL_DILITHIUM=yes.
2121
# Overrides the system pkg-config installation at /usr/local (which lacks these flags).
22-
WOLFSSL_DIR = "/home/mark/wolfssl-install"
22+
WOLFSSL_DIR = "/home/mark/wolfssl-rs/wolfssl-repo-install"
2323
# wolfSSL source tree for the vendored build (cryptocb-only / riscv-bare-metal features).
2424
# When those features are active, wolfcrypt-sys bypasses WOLFSSL_DIR and compiles
2525
# wolfSSL from source via wolfssl-src using this path.
26-
WOLFSSL_SRC = "/home/mark/wolfssl"
26+
WOLFSSL_SRC = "/home/mark/wolfssl-rs/wolfssl-repo"
2727
# riscv32 C cross-compiler via zig cc.
2828
# Used by the cc crate when compiling wolfssl-src for the riscv32imc-unknown-none-elf target.
2929
CC_riscv32imc_unknown_none_elf = { value = ".cargo/riscv32-cc", relative = true }
@@ -35,4 +35,4 @@ CC_riscv32imc_unknown_none_elf = { value = ".cargo/riscv32-cc", relative = true
3535
# cache entry for /usr/local/lib wins.
3636
# --disable-new-dtags is required: modern binutils defaults to DT_RUNPATH which loses
3737
# to the ldconfig cache, while DT_RPATH takes priority before everything.
38-
rustflags = ["-C", "link-arg=-Wl,--disable-new-dtags,-rpath,/home/mark/wolfssl-install/lib"]
38+
rustflags = ["-C", "link-arg=-Wl,--disable-new-dtags,-rpath,/home/mark/wolfssl-rs/wolfssl-repo-install/lib"]

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "wolfssl-src/wolfssl"]
2+
path = wolfssl-src/wolfssl
3+
url = https://github.com/wolfSSL/wolfssl.git

wolfcrypt-wrapper/src/dilithium.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ impl Dilithium {
867867
let msg_len = msg.len() as u32;
868868
let mut sig_len = sig.len() as u32;
869869
let rc = unsafe {
870-
sys::wc_dilithium_sign_msg(
870+
sys::wc_dilithium_sign_ctx_msg(
871+
core::ptr::null(), 0,
871872
msg.as_ptr(), msg_len,
872873
sig.as_mut_ptr(), &mut sig_len,
873874
&mut self.ws_key,
@@ -1038,7 +1039,8 @@ impl Dilithium {
10381039
let msg_len = msg.len() as u32;
10391040
let mut sig_len = sig.len() as u32;
10401041
let rc = unsafe {
1041-
sys::wc_dilithium_sign_msg_with_seed(
1042+
sys::wc_dilithium_sign_ctx_msg_with_seed(
1043+
core::ptr::null(), 0,
10421044
msg.as_ptr(), msg_len,
10431045
sig.as_mut_ptr(), &mut sig_len,
10441046
&mut self.ws_key,
@@ -1184,8 +1186,9 @@ impl Dilithium {
11841186
let msg_len = msg.len() as u32;
11851187
let mut res = 0i32;
11861188
let rc = unsafe {
1187-
sys::wc_dilithium_verify_msg(
1189+
sys::wc_dilithium_verify_ctx_msg(
11881190
sig.as_ptr(), sig_len,
1191+
core::ptr::null(), 0,
11891192
msg.as_ptr(), msg_len,
11901193
&mut res,
11911194
&mut self.ws_key,

wolfssl-src/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ repository = "https://github.com/wolfSSL/wolfssl-rs"
1010
readme = "README.md"
1111
keywords = ["wolfcrypt", "wolfssl", "fips", "cryptography"]
1212
categories = ["cryptography"]
13+
include = [
14+
"src/**",
15+
"patches/**",
16+
"wolfssl/**",
17+
"user_settings*.h",
18+
"riscv_bare_metal_helpers.c",
19+
"README.md",
20+
"Cargo.toml",
21+
]
1322

1423
[features]
1524
default = []

wolfssl-src/src/lib.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//! The builder discovers wolfSSL sources in order:
1717
//! 1. `source_dir()` programmatic override
1818
//! 2. `WOLFSSL_SRC` environment variable
19-
//! 3. `pkg-config` (looks for a `wolfssl` package whose prefix contains source files)
19+
//! 3. Bundled submodule at `wolfssl-src/wolfssl/` (present after `git submodule update --init`)
20+
//! 4. `pkg-config` (looks for a `wolfssl` package whose prefix contains source files)
2021
2122
use std::collections::HashSet;
2223
use std::env;
@@ -52,7 +53,7 @@ impl Build {
5253
}
5354

5455
/// Set the path to the wolfSSL source tree.
55-
/// If not set, defaults to `WOLFSSL_SRC` env var, then `pkg-config`.
56+
/// If not set, defaults to `WOLFSSL_SRC` env var, then the bundled submodule, then `pkg-config`.
5657
pub fn source_dir(&mut self, dir: PathBuf) -> &mut Self {
5758
self.source_dir = Some(dir);
5859
self
@@ -227,23 +228,31 @@ impl Build {
227228

228229
// 2. WOLFSSL_SRC env var
229230
if let Ok(dir) = env::var("WOLFSSL_SRC") {
230-
let path = PathBuf::from(&dir);
231-
if !path.exists() {
232-
panic!("WOLFSSL_SRC={dir} does not exist");
231+
if !dir.is_empty() {
232+
let path = PathBuf::from(&dir);
233+
if !path.exists() {
234+
panic!("WOLFSSL_SRC={dir} does not exist");
235+
}
236+
return path;
233237
}
234-
return path;
235238
}
236239

237-
// 3. pkg-config
240+
// 3. Bundled submodule (wolfssl-src/wolfssl/ inside this crate)
241+
let bundled = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("wolfssl");
242+
if bundled.join("wolfcrypt/src").exists() {
243+
return bundled;
244+
}
245+
246+
// 4. pkg-config
238247
if let Some(dir) = Self::find_via_pkg_config() {
239248
return dir;
240249
}
241250

242251
panic!(
243252
"wolfSSL source not found. Either:\n \
253+
- Run: git submodule update --init\n \
244254
- Set WOLFSSL_SRC to the path of your wolfssl checkout\n \
245-
- Install wolfssl-dev so that pkg-config can find it\n \
246-
- Clone it: git clone https://github.com/wolfSSL/wolfssl.git"
255+
- Install wolfssl-dev so that pkg-config can find it"
247256
);
248257
}
249258

wolfssl-src/user_settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
* instead of RSA_BUFFER_E. Required for Wycheproof OAEP zero-length test vectors. */
110110
#define WOLFSSL_RSA_DECRYPT_TO_0_LEN
111111

112+
/* TLS 1.3 */
113+
#define WOLFSSL_TLS13
114+
112115
/* TLS extensions and SNI — required by OPENSSL_ALL for struct layout
113116
* in ssl.c even though we don't compile the TLS protocol files. */
114117
#define HAVE_TLS_EXTENSIONS

wolfssl-src/wolfssl

Submodule wolfssl added at 0c9b639

0 commit comments

Comments
 (0)