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

fix(crypto): copy only the digest length in `blake2s_Final()`

Public commit record

What the developer wrote

Authored by Ondřej Vejpustek

85/100 · Strong
fix(crypto): copy only the digest length in `blake2s_Final()`

`blake2s_Final()` copied `outlen` (the caller's buffer size) bytes from
the 32-byte internal buffer, so `outlen > 32` caused an out-of-bounds
stack read. Copy `S->outlen` instead, same as `blake2b_Final()`.

Inherited probably from upstream commit 932be4e, which forgot to update
the `memcpy()` in `ref/blake2s-ref.c`.

[no changelog]

(cherry picked from commit b109a5bb745f1843dfd40790fe46903c66d9564e)
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a memory safety bug in the Trezor firmware's implementation of the BLAKE2s hashing function. The finalization routine was copying as many bytes as the caller's output buffer could hold, rather than the actual hash digest length. If a caller passed a buffer larger than 32 bytes, the function would read past the end of its internal 32-byte buffer, potentially leaking nearby stack data into the output. The fix makes BLAKE2s behave consistently with the already-correct BLAKE2b implementation.

Recommended action

Apply the patch and run the updated unit tests. Review all call sites of `blake2s_Final()` in the firmware and host tooling to confirm no code relies on the previous over-copy behavior. Consider auditing other inherited upstream crypto code for similar `memcpy` length mismatches.

Security signals we found

01

Out-of-bounds stack read in cryptographic finalization routine

02

Potential information disclosure of adjacent stack memory

03

Inconsistency between blake2b_Final and blake2s_Final copy behavior

04

Regression test added to prevent reintroduction

Risk score

Why this scored 60/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/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.