cipher: remove unused AES-HMAC C exports
What changed, and why it matters
This commit removes two unused C-language bridge functions that wrapped an AES-HMAC encryption/decryption module. The functions themselves were not called from C code; the firmware now calls the same encryption logic directly from Rust. Removing them eliminates the risk that someone might later misuse these wrappers with a wrong input size, but the change does not fix any currently exploitable vulnerability.
No immediate action required. Treat as routine defensive cleanup. If these wrappers were ever intended to be reintroduced, ensure input-length validation and safe buffer sizing rather than relying on unwrap/try_into panics.
Security signals we found
Removal of C FFI wrappers that could panic on malformed inputs
Commit message acknowledges potential panic conditions (invalid IV length, undersized output buffer)
No functional change to the underlying AES-HMAC implementation
No replacement callers or new attack surface introduced
Evidence from the diff
The patch deletes rust_cipher_encrypt and rust_cipher_decrypt from bitbox-aes/src/lib.rs, along with their Cargo.toml dependency on util, cbindgen bindings, and references in simulators/tests. The commit message explicitly states the wrappers could panic on invalid IV length or undersized output buffer. The actual AES-HMAC implementation (encrypt_with_hmac/decrypt_with_hmac) remains in place and is used directly by the Rust keystore. No C caller is present in the diff or mentioned as using these exports.
Changed components
src/rust/bitbox-aes/src/lib.rssrc/rust/bitbox-aes/Cargo.tomlsrc/rust/bitbox02-cbindgen.tomlsrc/rust/bitbox02-rust-c/Cargo.tomlsrc/rust/bitbox02-rust-c/src/lib.rssrc/rust/bitbox02-rust/src/lib.rssrc/rust/bitbox02-sys/build.rssrc/rust/bitbox02/Cargo.tomltest/simulator-graphical-bb03test/simulator-graphicalInspect 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 17/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.