AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

Merge rust-bitcoin/rust-bitcoin#6856: hashes: Fix Hkdf::expand panic

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6856: hashes: Fix Hkdf::expand panic

9e71cce17be751cabd63f58eee27b9250ba80e9b hashes: Test Hkdf::expand at maximum output length (Jamil Lambert, PhD)
c61576fea722b164abd6aa230bf34f514078eda4 hashes: Fix Hkdf::expand panic at max length (Jamil Lambert, PhD)

Pull request description:

Hkdf::expand accepts an output buffer up to the RFC-5869 maximum of 255 * T::Hash::LEN bytes, but the per-block counter was a u8. At the maximum length the counter reaches 255 on the final block and the subsequent counter += 1 overflows.

Replace the u8 counter with a for loop which cannot overflow.

Closes project-loupe/audit-rust-bitcoin#5


ACKs for top commit:
satsfy:
tACK 9e71cce17be751cabd63f58eee27b9250ba80e9b
tcharding:
ACK 9e71cce17be751cabd63f58eee27b9250ba80e9b
apoelstra:
ACK 9e71cce17be751cabd63f58eee27b9250ba80e9b; successfully ran local tests


Tree-SHA512: 07838b649685d88d334dd05216ddbc11ba0f52a0a3e40f40bc52f5b55d75bd68d5ee14ffc666314d4bafd1013bae52b3598300b47095ab851fb33aabaa07d516
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a panic (sudden crash) in the HKDF key-derivation function when a caller asks for the maximum allowed output length. The previous code used an 8-bit counter that overflowed on the final block, causing the program to abort. The fix replaces the counter with a loop that cannot overflow. This is a denial-of-service-style bug: a valid, RFC-compliant request could crash the library.

Recommended action

Upgrade to a version of rust-bitcoin that includes this commit. If HKDF is exposed to untrusted input lengths, apply the patch immediately to prevent a panic on maximum-length requests. Review any code that catches panics around HKDF usage, as the panic is now removed.

Security signals we found

01

Integer overflow in block counter leading to runtime panic

02

Denial-of-service vector via a valid, maximum-length HKDF expand request

03

Violation of RFC-5869 maximum output guarantee

04

Fix verified by regression test against RFC-5869 test vector

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.