mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
crypto: copy HMAC state instead of rehashing key pads #36812
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36812
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/hkdf-hmac-state"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Setting up an encrypted connection derives six values with the same secret. Each HKDF expansion repeats two SHA256 compressions to hash the same HMAC key pads.
Fix: Hash the key pads once per HKDF context, then copy the prepared HMAC state for each expansion. The copy replaces two setup compressions, saving ten SHA256 compressions across the six outputs - the derived bytes stay identical. RFC 2104 section 4 describes this optimization:
Measurements:
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
Concept ACK
🔵 Suggestion · Six-label HKDF vectors lack expected-value provenance
The new fixed outputs do not identify their source, so readers cannot distinguish an independent correctness check from a snapshot of the implementation's output.
Location:
src/test/crypto_tests.cpp:1080(head).Review coverage was incomplete.
Reviewed:
80130b90e2f5· Full review report · Previous reportspermalink
Concept ACK
Code review ACK (read the diff, didn't build).
The optimization is standard and correct: HKDF-Expand here uses the same PRK for all six expansions, so pre-absorbing the key pads once (
PrepareHMAC→m_hmac) and copying that prepared state perExpand32is bit-identical to reconstructingCHMAC_SHA256(prk, ...)each time (RFC 2104 §4).Two things I checked while reviewing:
Expand32isconstand doesCHMAC_SHA256{m_hmac}(a copy), so it can't mutate the shared context for later labels — and the new test asserts exactly that ("Expansions must not modify the shared context state"), with the six BIP324 label vectors pinning the outputs.m_hmacembeds key-deriving material (as the oldm_prkdid);BIP324Cipher::Initializestill doesmemory_cleanse(&hkdf, sizeof(hkdf)), which zeroes them_hmacSHA256 midstates in place, so the "wipe anything that could re-derive the keys" invariant is preserved.The ~20% on connection setup is a nice win for a hot path. LGTM modulo a Tested ACK from someone who can run
crypto_tests.