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:
the intermediate results … on the B-byte blocks (K XOR ipad) and (K XOR opad) can be precomputed only once
Measurements:
BIP324_HKDF (ops/s, higher is better)
Before █████████████████████████████████░░░░░░░ 1,430,064 (baseline)
After ████████████████████████████████████████ 1,724,373 (+20.6%)