Skip to content

XOF fixes#3064

Merged
justsmth merged 8 commits intoaws:mainfrom
manastasova:shake_x4_zero
Mar 6, 2026
Merged

XOF fixes#3064
justsmth merged 8 commits intoaws:mainfrom
manastasova:shake_x4_zero

Conversation

@manastasova
Copy link
Copy Markdown
Contributor

@manastasova manastasova commented Mar 2, 2026

Issues:

Resolves: 17, 56, 58, 60

Description of changes:

This PR rejects XOF digests in HKDF, cleanse sensitive states, and update function pointers:

  • HKDF is built on HMAC, which does not support XOF (extendable-output) algorithms such as SHAKE128 and SHAKE256. Previously, passing a SHAKE digest would fall through to HMAC, which rejects it internally - except in HKDF_expand, where EVP_MD_size() returns 0 for XOF digests, causing a division by zero before HMAC is ever called.
    • Add early EVP_MD_FLAG_XOF checks to all three public HKDF functions so that XOF digests are rejected immediately with a clear error rather than causing undefined behavior or relying on HMAC's internal rejection.
  • Cleanse bitstates in batched SHAKE operations.
  • Clean up digest context on early return in EVP_Digest.
  • Explicitly set XOF function pointers to NULL for EVP_sha512_224.

Call-out:

  • Some check are redundant - HKDF calls with SHAKE will fail once HMAC-layer is reached. However, this redundancy aims at early failing in the expected API layer, thus prevents hidden bugs as the division by zero.

Testing:

./crypto/crypto_test

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@manastasova manastasova marked this pull request as ready for review March 2, 2026 23:10
@manastasova manastasova requested a review from a team as a code owner March 2, 2026 23:10
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 51.85185% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.53%. Comparing base (e2b4850) to head (c56af9a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crypto/fipsmodule/hkdf/hkdf.c 33.33% 6 Missing ⚠️
crypto/fipsmodule/hmac/hmac.c 33.33% 4 Missing ⚠️
crypto/fipsmodule/evp/p_hkdf.c 33.33% 2 Missing ⚠️
crypto/fipsmodule/digest/digest.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3064      +/-   ##
==========================================
+ Coverage   78.37%   78.53%   +0.16%     
==========================================
  Files         689      689              
  Lines      121148   121175      +27     
  Branches    16973    16982       +9     
==========================================
+ Hits        94948    95169     +221     
+ Misses      25302    25106     -196     
- Partials      898      900       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

justsmth
justsmth previously approved these changes Mar 3, 2026
@justsmth justsmth disabled auto-merge March 6, 2026 20:59
@justsmth justsmth merged commit 54de982 into aws:main Mar 6, 2026
436 of 462 checks passed
WillChilds-Klein pushed a commit to WillChilds-Klein/aws-lc that referenced this pull request Mar 11, 2026
### Issues:
Resolves: 17, 56, 58, 60

### Description of changes:          
This PR rejects XOF digests in HKDF, cleanse sensitive states, and
update function pointers:
* HKDF is built on HMAC, which does not support XOF (extendable-output)
algorithms such as SHAKE128 and SHAKE256. Previously, passing a SHAKE
digest would fall through to HMAC, which rejects it internally - except
in HKDF_expand, where EVP_MD_size() returns 0 for XOF digests, causing a
division by zero before HMAC is ever called.
* Add early EVP_MD_FLAG_XOF checks to all three public HKDF functions so
that XOF digests are rejected immediately with a clear error rather than
causing undefined behavior or relying on HMAC's internal rejection.
* Cleanse bitstates in batched SHAKE operations.
* Clean up digest context on early return in EVP_Digest.
* Explicitly set XOF function pointers to NULL for EVP_sha512_224.

### Call-out:
* Some check are _redundant_ - HKDF calls with SHAKE will fail once
HMAC-layer is reached. However, this _redundancy_ aims at early failing
in the expected API layer, thus prevents hidden bugs as the division by
zero.

### Testing:
`./crypto/crypto_test`

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.

---------

Co-authored-by: Justin W Smith <103147162+justsmth@users.noreply.github.com>
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.

4 participants