Skip to content

Fix Blake2 oversized key path#10447

Merged
SparkiDev merged 1 commit into
wolfSSL:masterfrom
mattia-moffa:20260508-blake2-long-key-fix
May 12, 2026
Merged

Fix Blake2 oversized key path#10447
SparkiDev merged 1 commit into
wolfSSL:masterfrom
mattia-moffa:20260508-blake2-long-key-fix

Conversation

@mattia-moffa

@mattia-moffa mattia-moffa commented May 11, 2026

Copy link
Copy Markdown
Member

Description

  • Reduce long keys in a separate state rather than reusing the state used for the HMAC inner hash.
  • Pad the rest of the buffer with zeros as required by the spec.
  • Add regression tests

Fixes zd#21783 (1, 3)

Testing

./configure --enable-blake2 --enable-blake2s
make
make check

- Reduce long keys in a separate state rather than reusing the state used
for the HMAC inner hash.
- Pad the rest of the buffer with zeros as required by the spec.
- Add regression tests
@mattia-moffa mattia-moffa self-assigned this May 11, 2026
Copilot AI review requested due to automatic review settings May 11, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes HMAC-BLAKE2b/HMAC-BLAKE2s handling for oversized keys by ensuring the “hash-long-key then pad to blocksize” step doesn’t clobber the active inner-hash state, and by guaranteeing the padded key buffer is zero-filled per the HMAC spec behavior. It also adds regression tests to prevent reintroduction.

Changes:

  • Zero-initialize the block-sized key buffer (x_key) so reduced keys (hashed long keys) are correctly zero-padded to block size.
  • In wc_Blake2*b/s*HmacFinal, hash oversized keys using a dedicated temporary Blake2* state (keyHash) instead of reusing the caller’s b2* state.
  • Add test vectors covering oversized key inputs for both BLAKE2b and BLAKE2s HMAC.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
wolfcrypt/test/test.c Adds regression tests for HMAC-BLAKE2b/HMAC-BLAKE2s with oversized keys.
wolfcrypt/src/blake2s.c Fixes oversized-key handling by zero-padding x_key and using a separate hash state in wc_Blake2sHmacFinal.
wolfcrypt/src/blake2b.c Fixes oversized-key handling by zero-padding x_key and using a separate hash state in wc_Blake2bHmacFinal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

2 similar comments
@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@mattia-moffa

Copy link
Copy Markdown
Member Author

Jenkins retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #10447

Scan targets checked: wolfcrypt-bugs, wolfcrypt-src

No new issues found in the changed files. ✅

@SparkiDev
SparkiDev merged commit 2c4f854 into wolfSSL:master May 12, 2026
485 of 487 checks passed
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.

5 participants