Skip to content

fix(blake2): reject empty MAC keys - #914

Open
thevilledev wants to merge 2 commits into
RustCrypto:masterfrom
thevilledev:fix/blake2-reject-empty-mac-key
Open

fix(blake2): reject empty MAC keys#914
thevilledev wants to merge 2 commits into
RustCrypto:masterfrom
thevilledev:fix/blake2-reject-empty-mac-key

Conversation

@thevilledev

Copy link
Copy Markdown

Summary

RFC 7693 §2.5 reserves kk = 0 for unkeyed hashing, and §3.3 prepends a padded key block only when kk > 0. new_from_slice(&[]) did both at once by recording kk = 0 in the parameter block while still seeding the buffer with a full zero-filled key block.

new_with_salt_and_personal has rejected this since #510. new_from_slice never got the same guard, and #510's regression test covered only the constructor it fixed. The changelog entry for v0.11.0 lists the handling of unkeyed hashes in keyed mode as fixed (#911).

This issue was found by differential testing against various other libraries like digestif, HACL* and Cryptokit, which all return the plain unkeyed digest for a zero-length key.

Prior work on empty keys:

Changes

Test

The regression test fails before the implementation change and passes afterward.

Cover the generic KeyInit constructor alongside the parameterized
constructor so both BLAKE2 variants enforce the same key invariant.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Treat zero-length keys as invalid through the generic KeyInit API.
Match the parameterized constructor and keep unkeyed hashing explicit.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
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.

1 participant