Merge remote-tracking branch 'agent/benma-agent/remove-aes-hmac-c-exports'
What changed, and why it matters
This commit removes unused C-language export functions for AES encryption/HMAC from the BitBox02 firmware's Rust code. It is a cleanup change: the functions are deleted, the crate is no longer included in firmware builds, and simulators stop depending on it. There is no indication this fixes an active security bug; it reduces attack surface by narrowing what code is exposed to C callers.
No urgent action required. Treat as routine refactoring. If reviewing for defense-in-depth, verify that no C code still references the removed `rust_cipher_encrypt`/`rust_cipher_decrypt` symbols and that the remaining Rust-only AES+HMAC usage is still reviewed for side-channel and misuse risks.
Security signals we found
Reduction of C FFI attack surface by removing no_mangle AES/HMAC exports
Dependency cleanup: bitbox-aes no longer linked into firmware or simulators
No patch of an identified vulnerability in cryptographic logic
Evidence from the diff
The merge removes #[unsafe(no_mangle)] extern "C" exports rust_cipher_encrypt and rust_cipher_decrypt from bitbox-aes/src/lib.rs, drops bitbox-aes from bitbox02-rust-c firmware feature dependencies, removes it from cbindgen generation lists, and removes simulator/test dependencies. The underlying Rust AES+HMAC helpers remain in bitbox-aes but are no longer callable from C firmware. No vulnerability, buffer-size bug, or cryptographic flaw is described or patched in the diff.
Changed components
src/rust/bitbox-aessrc/rust/bitbox02-rust-csrc/rust/bitbox02-cbindgen.tomlsrc/rust/bitbox02-sys/build.rstest/simulator-graphicaltest/simulator-graphical-bb03Inspect captured patch +2 / −59
### src/rust/Cargo.lock
@@ -114,7 +114,6 @@ version = "0.1.0"
dependencies = [
"bitcoin",
"ctaes",
- "util",
"zeroize",
]
@@ -356,7 +355,6 @@ version = "0.1.0"
dependencies = [
"async_test",
"bip39",
- "bitbox-aes",
"bitbox-bytequeue",
"bitbox-framed-serial-link",
"bitbox-hal",
@@ -433,7 +431,6 @@ name = "bitbox02-rust-c"
version = "0.1.0"
dependencies = [
"bip39",
- "bitbox-aes",
"bitbox-bytequeue",
"bitbox-core-utils",
"bitbox-da14531",
### src/rust/bitbox-aes/Cargo.toml
@@ -11,4 +11,3 @@ license = "Apache-2.0"
bitcoin = { workspace = true }
ctaes = { version = "0.1.0" }
zeroize = { workspace = true }
-util = {path = "../util" }
### src/rust/bitbox-aes/src/lib.rs
@@ -100,40 +100,6 @@ pub fn decrypt_with_hmac(key: &[u8], cipher: &[u8]) -> Result<zeroize::Zeroizing
decrypt(encryption_key.try_into().unwrap(), cipher)
}
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_cipher_encrypt(
- iv: util::bytes::Bytes,
- key: util::bytes::Bytes,
- plain: util::bytes::Bytes,
- mut out: util::bytes::BytesMut,
- out_len: &mut usize,
-) {
- let enc = encrypt_with_hmac(
- &iv.as_ref().try_into().unwrap(),
- key.as_ref(),
- plain.as_ref(),
- );
- out.as_mut()[..enc.len()].copy_from_slice(&enc);
- *out_len = enc.len();
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_cipher_decrypt(
- key: util::bytes::Bytes,
- cipher: util::bytes::Bytes,
- mut out: util::bytes::BytesMut,
- out_len: &mut usize,
-) -> bool {
- match decrypt_with_hmac(key.as_ref(), cipher.as_ref()) {
- Ok(dec) => {
- out.as_mut()[..dec.len()].copy_from_slice(&dec);
- *out_len = dec.len();
- true
- }
- Err(_) => false,
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
### src/rust/bitbox02-cbindgen.toml
@@ -18,10 +18,10 @@ header = '''
parse_deps = true
# ... but only parse these crates.
-include = ["bitbox02", "bitbox02-rust", "bitbox-securechip", "util", "bitbox-aes", "bitbox-da14531", "bitbox-framed-serial-link", "bitbox-bytequeue", "bitbox-usb-report-queue"]
+include = ["bitbox02", "bitbox02-rust", "bitbox-securechip", "util", "bitbox-da14531", "bitbox-framed-serial-link", "bitbox-bytequeue", "bitbox-usb-report-queue"]
# also generate bindings from these crates.
-extra_bindings = ["bitbox02", "bitbox02-rust", "bitbox-securechip", "util", "bitbox-aes", "bitbox-da14531", "bitbox-framed-serial-link", "bitbox-bytequeue", "bitbox-usb-report-queue"]
+extra_bindings = ["bitbox02", "bitbox02-rust", "bitbox-securechip", "util", "bitbox-da14531", "bitbox-framed-serial-link", "bitbox-bytequeue", "bitbox-usb-report-queue"]
[export]
# malloc, free declared in bitbox02-rust-c/src/c_alloc.rs, but does not need to be exported, as it
### src/rust/bitbox02-rust-c/Cargo.toml
@@ -13,7 +13,6 @@ bitbox02-rust = { path = "../bitbox02-rust", optional = true }
bitbox-usb-report-queue = { path = "../bitbox-usb-report-queue" }
bitbox-bytequeue = { path = "../bitbox-bytequeue" }
bitbox-da14531 = { path = "../bitbox-da14531" }
-bitbox-aes = { path = "../bitbox-aes", optional = true }
bitbox02 = { path = "../bitbox02" }
bitbox-hal = { path = "../bitbox-hal" }
bitbox-noise = { path = "../bitbox-noise", optional = true }
@@ -74,7 +73,6 @@ firmware = [
"bitbox-noise",
"util/sha2",
"util/firmware",
- "bitbox-aes",
]
# Only to be enabled in Rust unit tests.
### src/rust/bitbox02-rust-c/src/lib.rs
@@ -32,10 +32,6 @@ mod secp256k1;
)]
mod u2f_c_api;
-// Expose C interface defined in bitbox_aes
-#[cfg(feature = "firmware")]
-extern crate bitbox_aes;
-
// Expose C interface defined in bitbox02_rust
// Enable for firmware and for Nova bootloader (BitBox02 bootloader currently does not need it).
#[cfg(any(
### src/rust/bitbox02-rust/src/lib.rs
@@ -36,6 +36,3 @@ mod xpubcache;
// for `format!`
#[macro_use]
extern crate alloc;
-
-#[cfg(test)]
-extern crate bitbox_aes;
### src/rust/bitbox02-sys/build.rs
@@ -319,8 +319,6 @@ pub fn main() -> BuildResult<()> {
emit_rerun_if_changed("../bitbox02/src");
emit_rerun_if_changed("../util/Cargo.toml");
emit_rerun_if_changed("../util/src");
- emit_rerun_if_changed("../bitbox-aes/Cargo.toml");
- emit_rerun_if_changed("../bitbox-aes/src");
emit_rerun_if_changed("../bitbox-framed-serial-link/Cargo.toml");
emit_rerun_if_changed("../bitbox-framed-serial-link/src");
emit_rerun_if_changed("../bitbox-bytequeue/Cargo.toml");
### src/rust/bitbox02/Cargo.toml
@@ -30,7 +30,6 @@ hex_lit = { workspace = true }
[dev-dependencies]
async_test = { path = "../async_test" }
-bitbox-aes = { path = "../bitbox-aes" }
bitbox-framed-serial-link = { path = "../bitbox-framed-serial-link" }
[features]
### test/simulator-graphical-bb03/Cargo.lock
@@ -325,7 +325,6 @@ version = "0.1.0"
dependencies = [
"bitcoin",
"ctaes",
- "util",
"zeroize",
]
@@ -3011,7 +3010,6 @@ dependencies = [
name = "simulator-graphical-bb03"
version = "0.1.0"
dependencies = [
- "bitbox-aes",
"bitbox-hal",
"bitbox-lvgl",
"bitbox-platform-host",
### test/simulator-graphical-bb03/Cargo.toml
@@ -8,7 +8,6 @@ bitbox-hal = { path = "../../src/rust/bitbox-hal" }
bitbox-platform-host = { path = "../../src/rust/bitbox-platform-host", features = ["simulator-graphical"] }
bitbox-usb-report-queue = { path = "../../src/rust/bitbox-usb-report-queue" }
bitbox02-rust = { path = "../../src/rust/bitbox02-rust", features = ["simulator-graphical"] }
-bitbox-aes = { path = "../../src/rust/bitbox-aes" }
winit = "0.30.12"
tracing = { version = "0.1.41", features = ["log"] }
image = "0.25.8"
### test/simulator-graphical/Cargo.lock
@@ -287,7 +287,6 @@ version = "0.1.0"
dependencies = [
"bitcoin",
"ctaes",
- "util",
"zeroize",
]
@@ -495,7 +494,6 @@ name = "bitbox02-rust-c"
version = "0.1.0"
dependencies = [
"bip39",
- "bitbox-aes",
"bitbox-bytequeue",
"bitbox-core-utils",
"bitbox-da14531",
@@ -2948,7 +2946,6 @@ dependencies = [
name = "simulator-graphical"
version = "0.1.0"
dependencies = [
- "bitbox-aes",
"bitbox-platform-host",
"bitbox02",
"bitbox02-rust",
### test/simulator-graphical/Cargo.toml
@@ -8,7 +8,6 @@ bitbox02-rust = { path="../../src/rust/bitbox02-rust", features=["simulator-grap
bitbox02-rust-c = { path="../../src/rust/bitbox02-rust-c", features=["simulator-graphical"] }
bitbox02 = { path="../../src/rust/bitbox02", features=["simulator-graphical"] }
bitbox-platform-host = { path = "../../src/rust/bitbox-platform-host", features = ["simulator-graphical"] }
-bitbox-aes = { path="../../src/rust/bitbox-aes"}
winit = "0.30.12"
tracing = {version = "0.1.41", features=["log"]}
image = "0.25.8"Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.