From f22f276ead6499d7f62f2f8255e686e9e85e9c0b Mon Sep 17 00:00:00 2001 From: tunnell Date: Mon, 20 Apr 2026 07:40:17 -0500 Subject: [PATCH] Use constant-time compare for FPGA key check The BIP-39 backup-key confirmation flow compared the entered key against the in-memory FPGA key with `==`, which short-circuits on the first mismatching byte and leaks prefix-length information through timing. Switch to `subtle::ConstantTimeEq`. The `subtle` crate is already a direct dependency and used in the same crate's `backups.rs` for the same purpose. Signed-off-by: tunnell Assisted-by: Claude Code (Opus 4.7) --- services/root-keys/src/implementation.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index be591a0ca..045db6e5a 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -8,6 +8,7 @@ use core::num::NonZeroUsize; use aes::Aes256; use aes::cipher::{BlockDecrypt, BlockEncrypt}; +use subtle::ConstantTimeEq; use cipher::generic_array::GenericArray; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::{EdwardsPoint, edwards::CompressedEdwardsY}; @@ -1642,7 +1643,7 @@ impl<'a> RootKeys { { Ok(verify) => { log::debug!("got bip39 verification: {:x?}", verify); - if &verify == &pcache.fpga_key { + if bool::from(verify.as_slice().ct_eq(&pcache.fpga_key)) { log::debug!("verify succeeded"); modals .show_notification(