Repository navigation
Conversation
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Allocation-failure paths leak copied ARIA sessions, and overly broad test guards cause false failures across several backends and build configurations.
5 open issues
Exclude TSIP and FSPSM backends from generic self-copy assertions · New Exclude KCAPI and no-small-stack builds from generic copy allocation test · New Exclude KCAPI and no-small-stack builds from SHA-384/512 copy tests · New Close copied ARIA session before zeroing destination on allocation failure · New Close copied ARIA session before zeroing destination on allocation failure · New
What changed in this PR
This PR improves wolfCrypt hardware error reporting and hash-context copy safety.
Changes:
- Propagates hardware lock, timeout, and transform errors.
- Rejects hash/HMAC self-copy and adds allocation-failure cleanup.
- Adds regression tests for self-copy and copy allocation failures.
| File | Description |
|---|---|
| wolfcrypt/src/sha512.c | Adds self-copy checks and failure cleanup. |
| wolfcrypt/src/sha3.c | Rejects self-copy. |
| wolfcrypt/src/sha256.c | Adds copy allocation-failure cleanup. |
| wolfcrypt/src/sha.c | Rejects self-copy. |
| wolfcrypt/src/md5.c | Propagates transform errors. |
| wolfcrypt/src/hmac.c | Rejects self-copy. |
| wolfcrypt/src/des3.c | Returns ColdFire lock and timeout errors. |
| wolfcrypt/src/aes.c | Improves hardware errors, allocation cleanup, and key wiping. |
| tests/api/test_sha512.h | Registers allocation-failure tests. |
| tests/api/test_sha512.c | Tests self-copy and allocation failures. |
| tests/api/test_sha3.c | Tests self-copy rejection. |
| tests/api/test_sha256.h | Registers allocation-failure testing. |
| tests/api/test_sha256.c | Tests copy allocation failure. |
| tests/api/test_sha.c | Tests self-copy rejection. |
| tests/api/test_hmac.c | Verifies rejected self-copy preserves state. |
| tests/api/test_digest.h | Adds shared self-copy test helpers. |
Review effort: Balanced
dgarske
force-pushed
the
hw_hash_errors
branch
from
December 4, 2026 22:30
46f267b to
5f2ca1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Hardware ports reported success after a failure:
wc_AesEncrypt()/wc_AesDecrypt()skipped the block operation and returned 0 when the hardware mutex could not be taken, so callers got unprocessed output. They now return the lock error. (F-19395)BAD_MUTEX_EorWC_TIMEOUT_E. ColdFire AES-CBC now checks the lock and wipes the key from the hardware buffer before unlocking. (F-9953, F-8327)Hash copy:
wc_HmacCopy(),wc_ShaCopy(),wc_Sha384Copy(),wc_Sha512Copy()andwc_Sha3Copy()freed the destination before copying, so copying a context onto itself destroyed it. They now returnBAD_FUNC_ARGforsrc == dst, aswc_Sha256Copy()already does. (F-11132, F-11133)Wcache and ARIA state when a later allocation failed. (F-9959, F-9960)Resolves F-19395, F-9953, F-8327, F-9954, F-12172, F-11132, F-11133, F-9959, F-9960.
Testing
New tests in
tests/apifor self-copy on each hash and HMAC, and for allocation failure during SHA-256/384/512 copies (underWOLFSSL_SMALL_STACK_CACHEwithWOLFSSL_HASH_KEEP). Each fails without the fix.--enable-all, a small-stack build with the W cache andWOLFSSL_HASH_KEEP,--enable-cryptonlywithout HMAC and without SHA-512, with ASan and-Werror.