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 <tunnell@users.noreply.github.com>
Assisted-by: Claude Code (Opus 4.7)
This commit is contained in:
tunnell 2026-04-20 07:40:17 -05:00
parent a642095c55
commit f22f276ead

View file

@ -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(