Repository navigation
Check AEAD tags on EVP_Cipher finalization and fix ARIA-GCM, derive_init and PKCS#7 PWRI defects - #12415
Open
dgarske wants to merge 1 commit into
Open
Check AEAD tags on EVP_Cipher finalization and fix ARIA-GCM, derive_init and PKCS#7 PWRI defects#12415dgarske wants to merge 1 commit into
dgarske wants to merge 1 commit into
Conversation
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Stale authentication flags let reused SM4-GCM/CCM contexts accept empty messages without verifying tags, while ChaCha20-Poly1305 rejects valid empty messages without AAD.
2 open issues
What changed in this PR
This PR hardens wolfSSL’s EVP compatibility layer and PKCS#7 decoding against authentication, buffer-handling, and key-lifetime defects.
Changes:
- Checks AEAD authentication during finalization and isolates ARIA-GCM tag storage.
- Clears freed derive-context peer keys and rejects invalid PWRI content-key lengths.
- Adds regression tests for authentication, exact-sized buffers, context reuse, and malformed keys.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/pkcs7.h | Tracks unwrapped PWRI key length. |
| wolfssl/openssl/evp.h | Adds AEAD message-state flags. |
| wolfcrypt/src/pkcs7.c | Validates PWRI content-key lengths. |
| wolfcrypt/src/evp.c | Updates authentication, ARIA buffering, and peer-key cleanup. |
| tests/api/test_pkcs7.h | Registers PWRI regression tests. |
| tests/api/test_pkcs7.c | Tests shortened and zero-length PWRI keys. |
| tests/api/test_evp_pkey.c | Tests repeated derive initialization. |
| tests/api/test_evp_cipher.h | Registers cipher regression tests. |
| tests/api/test_evp_cipher.c | Tests AEAD finalization and exact-sized ARIA buffers. |
Review effort: Balanced
dgarske
force-pushed
the
evp_pkcs7_checks
branch
2 times, most recently
from
December 5, 2026 00:28
952a534 to
4e7a37c
Compare
dgarske
force-pushed
the
evp_pkcs7_checks
branch
from
December 5, 2026 03:29
4e7a37c to
df468ca
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
EVP_Cipher(ctx, NULL, NULL, 0)decryption finalization for AES-GCM, AES-CCM and SM4 never ran a decrypt when no payload call had been made, so a forged empty message was accepted. It now checks the tag of the empty message and returns the payload call's authentication error if that failed, matching OpenSSL. (F-16663)IsCipherTypeAEAD(), so itsEVP_Cipher()finalization returned success without checking the Poly1305 tag. (F-17537)EVP_Cipher()andEVP_CipherFinal()paths wrote the tag past the caller's output on encrypt and appended it to the caller's input on decrypt. Both now go through an internal buffer sized for the tag. (F-15320)EVP_PKEY_derive_init()freedpeerKeywithout clearing it, so re-initializing a derive context used and then double-freed it. (F-18634)wc_AesGcmDecrypt()asked the kernel for zero bytes of output for an empty message with no AAD, so the kernel never ran the decrypt and any tag was accepted, also throughwc_GmacVerify(). It now reads into a 1-byte buffer so the tag is checked. (F-19169)The EVP cipher context gains
authMsgTried/authMsgDone, andwc_PKCS7gainspwriCekSz(last member). #11689 adds the same two EVP fields for its CCM rework, so whichever lands second rebases.Resolves F-16663, F-17537, F-15320, F-18634, F-19085, F-19169.
Testing
New tests in
tests/api(test_evp_cipher.c,test_evp_pkey.c,test_pkcs7.c) each fail without the fix: forged empty GCM/CCM/ChaCha20-Poly1305 messages accepted, an ASan overflow (ARIA-GCM), an ASan use-after-free (derive_init), a short PWRI CEK decoded.--enable-all,--enable-opensslextrawith AES-GCM/CCM and ChaCha20-Poly1305 (non-streaming GCM),--enable-opensslall --enable-pkcs7 --enable-pwdbased,--disable-aesgcm, and--enable-cryptonly, with ASan and-Werror.test_wc_AesGcmDecrypt_EmptyTag.