3 releases
| new 0.1.3 | Apr 30, 2026 |
|---|---|
| 0.1.2 | Apr 30, 2026 |
| 0.1.0 | Apr 28, 2026 |
#5 in #wolf-ssl
85 downloads per month
Used in 3 crates
(via wolfhsm)
73KB
1.5K
SLoC
wolfhsm-sys
Raw Rust FFI bindings to wolfHSM,
auto-generated by bindgen at build time.
Most users should depend on the higher-level wolfhsm
crate instead. Use wolfhsm-sys directly only if you need access to wolfHSM
C API symbols that are not yet wrapped by wolfhsm.
What
wolfhsm-sys exposes the wolfHSM C client API directly as unsafe Rust
functions and types. The bindings cover:
- Client API — the complete
wh_Client_*function set: connect/disconnect, key generation and caching, ECC/RSA/AES/CMAC/HKDF operations, NVM object store, counters, certificate management, authentication, SHE key management, and custom callbacks - Communication layer —
wh_Comm_*connection and framing primitives - POSIX transport types —
PosixTransportTcp*,PosixTransportUds*,PosixTransportShm*structs and init/connect/disconnect functions - Constants and error codes —
WH_*andWOLFHSM_*result codes and configuration constants
The bindings also include a small C shim (shims.c) that stack-allocates
wolfcrypt structs on the C side — necessary because wolfcrypt types are
opaque in the Rust FFI and cannot be zero-initialized from Rust.
Why
wolfhsm-sys separates the generated FFI from the safe wrapper so that:
- The bindgen output can be regenerated (by bumping
wolfhsm-src) without a breaking-change version bump onwolfhsm. - Downstream crates with unusual requirements can use the raw bindings without pulling in the opinionated safe API.
- The
links = "wolfhsm_sys"key prevents multiple copies of the wolfHSM static archive from being linked into the same binary.
How it works
build.rs performs five steps:
- Read wolfSSL metadata — reads
DEP_WOLFCRYPT_SYS_*fromwolfcrypt-sys(wolfSSL include paths, vendored flag, lib dirs). - Read wolfHSM metadata — reads
DEP_WOLFHSM_SRC_INCLUDEandDEP_WOLFHSM_SRC_LIBfromwolfhsm-src(wolfHSM include path and compiled library location). - Compile
shims.c— a small C translation unit that stack-allocates wolfcrypt key and context structures and exposes them via thin wrapper functions callable from Rust. - Emit link directives — instructs
rustcto search forlibwolfhsm.ain thewolfhsm-srcoutput directory and link it, followed by the wolfSSL library. - Run bindgen — generates
bindings.rsinOUT_DIRfromwrapper.h, which includeswh_client.hand the POSIX transport headers. The allowlist captureswh_Client_*functions,wh_Comm_*,posixTransport*types and functions, andWH_*/WOLFHSM_*constants; wolfSSL internals are excluded.
How to use
[dependencies]
wolfhsm-sys = "0.1"
use wolfhsm_sys::*;
unsafe {
// Configure a TCP transport to the wolfHSM server
let mut tcp_ctx: PosixTransportTcpClientContext = core::mem::zeroed();
// ... set ip/port fields, call posixTransportTcp_Connect, wh_Client_Init, etc.
}
All functions are unsafe. For a safe API see the wolfhsm crate.
Build requirements
- The
wolfhsm-srccrate must be a direct[dependency](not[build-dependency]) so Cargo propagates itsDEP_WOLFHSM_SRC_*metadata to this crate's build script.wolfhsm-sysdeclares this dependency automatically — you do not need to addwolfhsm-srcto your ownCargo.toml. - wolfHSM source: set
WOLFHSM_SRCor initialise the bundled submodule. - wolfSSL headers: set
WOLFSSL_DIRorWOLFSSL_INCLUDE_DIR.
See wolfhsm-src for full
configuration details.
Features
| Feature | Description |
|---|---|
she |
SHE (Secure Hardware Extension) — propagates to wolfhsm-src |
References
Copyright
Copyright (C) 2006-2026 wolfSSL Inc.
wolfHSM is copyright wolfSSL Inc. and its contributors.
License
GPL-3.0-only OR LicenseRef-wolfSSL-commercial
Available under the GNU General Public License v3.0. For proprietary or commercial use, a commercial license is available from wolfSSL Inc.
Dependencies
~0–2.5MB
~50K SLoC