Skip to content

fix(crypto): wipe secret-key temporaries - #3456

Draft
Jr-kenny wants to merge 2 commits into
0xMiden:nextfrom
Jr-kenny:Jrkenny/fix-falcon-secret-zeroization
Draft

fix(crypto): wipe secret-key temporaries#3456
Jr-kenny wants to merge 2 commits into
0xMiden:nextfrom
Jr-kenny:Jrkenny/fix-falcon-secret-zeroization

Conversation

@Jr-kenny

@Jr-kenny Jr-kenny commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Ports 0xMiden/crypto#1061 now that the crypto crates live in this workspace. The original gap is tracked in 0xMiden/miden-vm#3533.

What was still leaking

SecretKey wipes its stored Falcon basis on drop, but the work around it was leaving extra copies of the same secret material behind. Polynomial<F> claimed ZeroizeOnDrop without a Drop implementation, so those coefficients were never actually wiped. Signing, serialization, deserialization, public-key derivation, and rejected key-generation retries all created more secret polynomials or encoded key buffers that dropped normally.

The same encoded-key pattern also showed up in the ECDSA and EdDSA secret-key comparison and serialization paths.

What changed

FalconFelt now implements Zeroize, and secret-carrying polynomials are wrapped in Zeroizing where they are created. The unbacked ZeroizeOnDrop marker is gone. The FFT chain in SecretKey::read_from, the encoded buffers in write_into and generate_seed, the public-key derivation clones, and rejected ntru_gen candidates are all covered.

Secret-key equality stays available to the crate's tests, but Eq and PartialEq are no longer exposed for Falcon, ECDSA, or EdDSA secret-key wrappers in production builds. ECDSA and EdDSA serialization now wipe their temporary encoded copies too.

I ported the security changes onto the current next code instead of copying the old crypto files across, so the newer miden-vm refactors stay intact. The BigInt and Complex64 residue documented in 0xMiden/miden-vm#3533 is still outside this change because those paths need the same manual volatile treatment already used by LdlTree.

Checks I ran

The focused regression failed before the fix because FalconFelt did not satisfy Zeroize. It passes with this change, along with the full crypto suite and the build combinations used by this code.

cargo test -p miden-crypto test_zeroize_wipes_falcon_felt_polynomial
cargo test -p miden-crypto dsa                         # 53 passed
cargo test -p miden-crypto --lib                       # 677 passed
cargo check -p miden-crypto --all-targets --all-features
cargo clippy -p miden-crypto --all-targets --all-features -- -D warnings
cargo check -p miden-crypto --no-default-features --target wasm32-unknown-unknown
cargo +nightly fmt --all --check

Comment thread crates/crypto/src/dsa/falcon512_poseidon2/keys/secret_key.rs Outdated
Comment thread crates/crypto/src/dsa/falcon512_poseidon2/math/polynomial.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants