Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d3e12fd
F-17413 - Recognize attached private-only ECC keys
aidangarske Nov 23, 2026
dcf4312
F-13637 - Bound skipped recipient header maps
aidangarske Nov 23, 2026
73cf64a
F-17424 - Document empty direct recipient ciphertext
aidangarske Nov 23, 2026
804b6de
F-14972 - Size RSA prime export buffers for odd widths
aidangarske Nov 23, 2026
b35c16c
F-14973 - Validate skipped signature header maps
aidangarske Nov 23, 2026
605baf9
F-14974 - Forward tolerant decode flags to the HPKE ek header
aidangarske Nov 23, 2026
d3bb124
F-18398 - Report short HPKE recipient output as buffer too small
aidangarske Nov 23, 2026
79b7422
F-14994 - Reject duplicate labels in skipped header maps
aidangarske Nov 23, 2026
bab83c7
F-18434 - Remove invariant status guards in MAC, sign and encrypt paths
aidangarske Nov 23, 2026
896d3f8
F-14976 - Report a truncated PSA components claim as malformed
aidangarske Nov 23, 2026
dae5f33
F-14995 - Accept an empty protected map for AES Key Wrap recipients
aidangarske Nov 23, 2026
80f0faf
F-17461 - Bound the PSA prior-label scan by its counter and status only
aidangarske Nov 23, 2026
c683e53
F-17462 - Document the status-guarded loop deviation and prove each l…
aidangarske Nov 24, 2026
cb681ca
F-15038 - Convert container bounds to uint64_t from size_t locals
aidangarske Nov 24, 2026
2e70142
F-17463 - Convert the head length bound to uint64_t from a size_t local
aidangarske Nov 24, 2026
fe405b5
F-17464 - Convert the text label length room to uint64_t from a size_…
aidangarske Nov 24, 2026
030fa2c
F-17465 - Convert the countersignature list count from a size_t local
aidangarske Nov 24, 2026
cff1852
F-17466 - Cast wolfCrypt curve enumerators to int explicitly
aidangarske Nov 24, 2026
69a8a5d
F-17467 - Cast the HPKE ephemeral curve enumerator to int
aidangarske Nov 24, 2026
5f44f28
F-17468 - Pass the COSE_Mac recipient count as size_t
aidangarske Nov 24, 2026
952566a
F-17469 - Pass the COSE_Encrypt recipient count as size_t
aidangarske Nov 24, 2026
66e0727
F-18437 - Drop dead status initializers in header and PSA encoders
aidangarske Nov 24, 2026
349eaff
F-18399 - Report an empty signatures or recipients array as malformed
aidangarske Nov 24, 2026
10c81cf
F-18475 - Reject a detached payload when the message carries its own
aidangarske Nov 24, 2026
45f5aa9
F-17445 - Require detached firmware manifests
aidangarske Nov 23, 2026
2456a6c
F-18473 - Reject a detached payload for a countersignature target wit…
aidangarske Nov 24, 2026
6849cd2
F-14977 - Require an attached ECC key for ECDSA countersignature verify
aidangarske Nov 24, 2026
976fe04
F-14978 - Require matching attached keys for local countersignature s…
aidangarske Nov 24, 2026
141f94e
F-14980 - Require an attached ECC key for local ECDSA signing
aidangarske Nov 24, 2026
c59e6e6
F-15104 - Require a symmetric or empty attachment before using symmet…
aidangarske Nov 24, 2026
e2e673d
F-14979 - Require the matching key attachment in COSE_Key encode and …
aidangarske Nov 24, 2026
26d6c20
F-17509 - Scrub HMAC contexts after every COSE_Mac0 and COSE_Mac oper…
aidangarske Nov 24, 2026
6ac260b
F-17516 - Derive ECDH-ES content keys through a wiped HKDF PRK
aidangarske Nov 24, 2026
5312ded
F-17517 - Wrap and unwrap content keys with a local, wiped AES context
aidangarske Nov 24, 2026
98becca
F-17495 - Count each expected content key wipe in the ECDH-ES zeroize…
aidangarske Nov 24, 2026
140d8d4
F-18429 - Leave the CBOR cursor unchanged when a public encode or dec…
aidangarske Nov 24, 2026
b57eba1
F-18474 - Bind the resolver-selected UEID to the authenticated PSA token
aidangarske Nov 24, 2026
0ab7ef2
F-18461 - Report an oversized HPKE-0-KE recipient kid as an argument …
aidangarske Nov 24, 2026
4410e4f
F-17471 - Initialize library context and profile byte arrays from hex…
aidangarske Nov 24, 2026
8cc5a44
F-15047 - Document the PSA overlap address comparison deviation
aidangarske Nov 24, 2026
7f09dd2
F-15048 - View PSA claim objects as unsigned char bytes in the overla…
aidangarske Nov 24, 2026
8cdc497
F-15049 - View the countersignature header as unsigned char bytes in …
aidangarske Nov 24, 2026
8f01f04
F-17460 - Document the GNU asm zeroization barrier as a Rule 1.2 devi…
aidangarske Nov 24, 2026
5c9a1b4
F-15050 - Require IEEE 754 binary32 and binary64 for the CBOR float e…
aidangarske Nov 24, 2026
205016a
F-15112 - Wipe cached ML-DSA private vectors before wolfCrypt resets …
aidangarske Nov 24, 2026
6ed1dad
F-18397 - Encode a private-only EC2 key as kty, crv and d
aidangarske Nov 24, 2026
591eabd
F-18425 - Read an ECDH-ES ephemeral key from the recipient protected …
aidangarske Nov 24, 2026
9edeebc
F-15043 - Copy const inputs into mutable buffers for non-const wolfCr…
aidangarske Nov 24, 2026
c7d7110
F-15045 - Give the test hook and curve-gate check visible declarations
aidangarske Nov 24, 2026
798d54d
F-18439 - Document text literals in example byte arrays and guard the…
aidangarske Nov 24, 2026
aa39b34
F-18476 - Reject a verify scratch buffer that overlaps its message or…
aidangarske Nov 24, 2026
0dc2d38
F-15103 - Reject a create or decrypt scratch buffer that overlaps an …
aidangarske Nov 24, 2026
fc577b2
F-14996 - Run the content cipher after a failed HPKE-0-KE recipient open
aidangarske Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
F-17517 - Wrap and unwrap content keys with a local, wiped AES context
  • Loading branch information
aidangarske committed Nov 30, 2026
commit 5312ded6c977262a0944f180f108eb1c02b1ce81
4 changes: 4 additions & 0 deletions .github/workflows/c99-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ jobs:
run: |
make countersign-config-test CC=${{ matrix.cc }} WOLFSSL_INC=$HOME/wolfssl-install/include

- name: AES Key Wrap configuration gate
run: |
make keywrap-config-test CC=${{ matrix.cc }} WOLFSSL_INC=$HOME/wolfssl-install/include

- name: Experimental-feature acknowledgement gate
run: |
make experimental-check CC=${{ matrix.cc }} WOLFSSL_INC=$HOME/wolfssl-install/include
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ SCEN_IOTFLEET = examples/scenarios/iot_fleet_config
SCEN_SENSOR = examples/scenarios/sensor_attestation
SCEN_BROADCAST = examples/scenarios/group_broadcast_mac

.PHONY: all shared test pkg-config-test ecdsa-policy-test rsapss-policy-test countersign-config-test zero-alloc-check force-zero-check zeroize-test deprecated-algs-test ecc-import-policy-test ext-sign-test no-local-sign-test ext-sign-demo ext-sign-force-failure coverage eat-psa-test eat-psa-float-test eat-psa-min-buffers-test eat-psa-claim-limits-test eat-psa-profile-test eat-psa-config-check eat-psa-ext-sign-test eat-psa-ext-sign-force-failure eat-psa-coverage eat-psa-coverage-force-failure hpke-coverage-force-failure generic-reduced-alg-test tool tool-test cmdline-test demo demos hpke-demo lean-verify psa-eat-lean-verify psa-eat-demo mldsa-demo mldsa-verify lms-demo lms-verify comprehensive scenarios release-scenarios release-coverage cxx-check valgrind-check release-validate release-artifacts interop-tcose tcose-upstream interop-go-cose interop-python-cwt interop-rust-coset c99-check c99-check-lms c99-hpke-check experimental-check clean FORCE
.PHONY: all shared test pkg-config-test ecdsa-policy-test rsapss-policy-test countersign-config-test keywrap-config-test zero-alloc-check force-zero-check zeroize-test deprecated-algs-test ecc-import-policy-test ext-sign-test no-local-sign-test ext-sign-demo ext-sign-force-failure coverage eat-psa-test eat-psa-float-test eat-psa-min-buffers-test eat-psa-claim-limits-test eat-psa-profile-test eat-psa-config-check eat-psa-ext-sign-test eat-psa-ext-sign-force-failure eat-psa-coverage eat-psa-coverage-force-failure hpke-coverage-force-failure generic-reduced-alg-test tool tool-test cmdline-test demo demos hpke-demo lean-verify psa-eat-lean-verify psa-eat-demo mldsa-demo mldsa-verify lms-demo lms-verify comprehensive scenarios release-scenarios release-coverage cxx-check valgrind-check release-validate release-artifacts interop-tcose tcose-upstream interop-go-cose interop-python-cwt interop-rust-coset c99-check c99-check-lms c99-hpke-check experimental-check clean FORCE

# --- Core library ---
all: $(LIB_A)
Expand Down Expand Up @@ -362,6 +362,12 @@ countersign-config-test:
-DWOLFCOSE_NO_COUNTERSIGN -x c -fsyntax-only -
@echo "PASS: countersignature operation guards compile cleanly"

# AES Key Wrap is independent of the AES content ciphers.
keywrap-config-test:
$(CC) $(C99_FLAGS) -DWOLFCOSE_ENABLE_AESWRAP -DWOLFCOSE_NO_AESGCM \
-DWOLFCOSE_NO_AESCCM -fsyntax-only $(SRC)
@echo "PASS: AES Key Wrap compiles without AES-GCM or AES-CCM"

zero-alloc-check:
sh scripts/check_zero_alloc.sh

Expand Down
22 changes: 18 additions & 4 deletions src/wolfcose_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ int wc_CoseEncrypt_Encrypt(const WOLFCOSE_RECIPIENT* recipients,
uint8_t recipientProtectedBuf[WOLFCOSE_PROTECTED_HDR_MAX];
size_t recipientProtectedLen = 0;
size_t encStructLen = 0;
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM) || \
defined(WOLFCOSE_KEY_WRAP)
Aes aes;
#endif
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
int aesInited = 0;
#endif
size_t keyLen = 0;
Expand Down Expand Up @@ -722,11 +725,19 @@ int wc_CoseEncrypt_Encrypt(const WOLFCOSE_RECIPIENT* recipients,
#endif
#if defined(WOLFCOSE_KEY_WRAP)
if (useKeyWrap != 0) {
/* The content cipher is done; reuse its Aes for the KEK. */
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
if (aesInited != 0) {
(void)wc_AesFree(&aes);
(void)wolfCose_ForceZero(&aes, sizeof(aes));
aesInited = 0;
}
#endif
ret = wolfCose_KeyWrap(recipients[i].algId,
recipients[i].key,
cekKeyWrap, keyLen,
wrappedCek, sizeof(wrappedCek),
&wrappedCekLen);
&wrappedCekLen, &aes);
if (ret == WOLFCOSE_SUCCESS) {
ret = wc_CBOR_EncodeBstr(&ctx, wrappedCek, wrappedCekLen);
}
Expand Down Expand Up @@ -805,8 +816,11 @@ int wc_CoseEncrypt_Decrypt(const WOLFCOSE_RECIPIENT* recipient,
size_t recipientsCount = 0;
size_t recipientsCountBound = 0u;
size_t i;
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM) || \
defined(WOLFCOSE_KEY_WRAP)
Aes aes;
#endif
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
int aesInited = 0;
#endif
int32_t alg = 0;
Expand Down Expand Up @@ -1468,7 +1482,7 @@ int wc_CoseEncrypt_Decrypt(const WOLFCOSE_RECIPIENT* recipient,
ret = wolfCose_KeyUnwrap(recipientAlgId, recipient->key,
wrappedCekData, wrappedCekLen,
cekKeyWrap, sizeof(cekKeyWrap),
&unwrappedCekLen);
&unwrappedCekLen, &aes);
}
if ((ret == WOLFCOSE_SUCCESS) && (unwrappedCekLen != keyLen)) {
ret = WOLFCOSE_E_COSE_KEY_TYPE;
Expand Down
9 changes: 6 additions & 3 deletions src/wolfcose_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include <wolfcose/wolfcose.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/hash.h>
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM)
#if defined(WOLFCOSE_HAVE_AESGCM) || defined(WOLFCOSE_HAVE_AESCCM) || \
defined(WOLFCOSE_KEY_WRAP)
#include <wolfssl/wolfcrypt/aes.h>
#endif
#if defined(WOLFCOSE_HAVE_HMAC)
Expand Down Expand Up @@ -747,12 +748,14 @@ WOLFCOSE_LOCAL int wolfCose_KeyWrapKeySize(int32_t alg, size_t* keySz);
/* KeyWrap -- defined in wolfcose_recipient.c */
WOLFCOSE_LOCAL int wolfCose_KeyWrap(int32_t alg, const WOLFCOSE_KEY* kek,
const uint8_t* cek, size_t cekLen,
uint8_t* out, size_t outSz, size_t* outLen);
uint8_t* out, size_t outSz, size_t* outLen,
Aes* aes);

/* KeyUnwrap -- defined in wolfcose_recipient.c */
WOLFCOSE_LOCAL int wolfCose_KeyUnwrap(int32_t alg, const WOLFCOSE_KEY* kek,
const uint8_t* wrappedCek, size_t wrappedLen,
uint8_t* cekOut, size_t cekOutSz, size_t* cekLen);
uint8_t* cekOut, size_t cekOutSz, size_t* cekLen,
Aes* aes);

/* IsKeyWrapAlg -- defined in wolfcose_recipient.c */
WOLFCOSE_LOCAL int wolfCose_IsKeyWrapAlg(int32_t alg);
Expand Down
68 changes: 57 additions & 11 deletions src/wolfcose_recipient.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ int wolfCose_KeyWrapKeySize(int32_t alg, size_t* keySz)
* \param out Output buffer for wrapped key
* \param outSz Output buffer size
* \param outLen Output: wrapped key length (cekLen + 8)
* \param aes Caller's unused AES context; freed and wiped on return
* \return WOLFCOSE_SUCCESS or error code
*/
int wolfCose_KeyWrap(int32_t alg, const WOLFCOSE_KEY* kek,
const uint8_t* cek, size_t cekLen,
uint8_t* out, size_t outSz, size_t* outLen)
uint8_t* out, size_t outSz, size_t* outLen,
Aes* aes)
{
int ret;
size_t expectedKeySz;
int aesInited = 0;

if ((kek == NULL) || (cek == NULL) || (out == NULL) || (outLen == NULL)) {
if ((kek == NULL) || (cek == NULL) || (out == NULL) || (outLen == NULL) ||
(aes == NULL)) {
ret = WOLFCOSE_E_INVALID_ARG;
}
else if (wolfCose_KeyIsSymmetric(kek) == 0) {
Expand All @@ -126,11 +130,24 @@ int wolfCose_KeyWrap(int32_t alg, const WOLFCOSE_KEY* kek,
}
}

/* An owned Aes lets the KEK schedule be wiped; wc_AesKeyWrap may not. */
if (ret == WOLFCOSE_SUCCESS) {
if (wc_AesInit(aes, NULL, INVALID_DEVID) != 0) {
ret = WOLFCOSE_E_CRYPTO;
}
else {
aesInited = 1;
}
}
if ((ret == WOLFCOSE_SUCCESS) &&
(wc_AesSetKey(aes, kek->key.symm.key, (word32)kek->key.symm.keyLen,
NULL, AES_ENCRYPTION) != 0)) {
ret = WOLFCOSE_E_CRYPTO;
}
if (ret == WOLFCOSE_SUCCESS) {
int wrapRet;
wrapRet = wc_AesKeyWrap(kek->key.symm.key, (word32)kek->key.symm.keyLen,
cek, (word32)cekLen,
out, (word32)outSz, NULL);
wrapRet = wc_AesKeyWrap_ex(aes, cek, (word32)cekLen,
out, (word32)outSz, NULL);
if (wrapRet > 0) {
*outLen = (size_t)wrapRet;
ret = WOLFCOSE_SUCCESS;
Expand All @@ -140,6 +157,13 @@ int wolfCose_KeyWrap(int32_t alg, const WOLFCOSE_KEY* kek,
}
}

if (aesInited != 0) {
(void)wc_AesFree(aes);
}
if (aes != NULL) {
(void)wolfCose_ForceZero(aes, sizeof(*aes));
}

return ret;
}

Expand All @@ -153,16 +177,20 @@ int wolfCose_KeyWrap(int32_t alg, const WOLFCOSE_KEY* kek,
* \param cekOut Output buffer for unwrapped CEK
* \param cekOutSz Output buffer size
* \param cekLen Output: unwrapped CEK length
* \param aes Caller's unused AES context; freed and wiped on return
* \return WOLFCOSE_SUCCESS or error code
*/
int wolfCose_KeyUnwrap(int32_t alg, const WOLFCOSE_KEY* kek,
const uint8_t* wrappedCek, size_t wrappedLen,
uint8_t* cekOut, size_t cekOutSz, size_t* cekLen)
uint8_t* cekOut, size_t cekOutSz, size_t* cekLen,
Aes* aes)
{
int ret;
size_t expectedKeySz;
int aesInited = 0;

if ((kek == NULL) || (wrappedCek == NULL) || (cekOut == NULL) || (cekLen == NULL)) {
if ((kek == NULL) || (wrappedCek == NULL) || (cekOut == NULL) ||
(cekLen == NULL) || (aes == NULL)) {
ret = WOLFCOSE_E_INVALID_ARG;
}
else if (wolfCose_KeyIsSymmetric(kek) == 0) {
Expand All @@ -188,12 +216,23 @@ int wolfCose_KeyUnwrap(int32_t alg, const WOLFCOSE_KEY* kek,
}
}

if (ret == WOLFCOSE_SUCCESS) {
if (wc_AesInit(aes, NULL, INVALID_DEVID) != 0) {
ret = WOLFCOSE_E_CRYPTO;
}
else {
aesInited = 1;
}
}
if ((ret == WOLFCOSE_SUCCESS) &&
(wc_AesSetKey(aes, kek->key.symm.key, (word32)kek->key.symm.keyLen,
NULL, AES_DECRYPTION) != 0)) {
ret = WOLFCOSE_E_CRYPTO;
}
if (ret == WOLFCOSE_SUCCESS) {
int unwrapRet;
unwrapRet = wc_AesKeyUnWrap(kek->key.symm.key,
(word32)kek->key.symm.keyLen,
wrappedCek, (word32)wrappedLen,
cekOut, (word32)cekOutSz, NULL);
unwrapRet = wc_AesKeyUnWrap_ex(aes, wrappedCek, (word32)wrappedLen,
cekOut, (word32)cekOutSz, NULL);
if (unwrapRet > 0) {
*cekLen = (size_t)unwrapRet;
ret = WOLFCOSE_SUCCESS;
Expand All @@ -203,6 +242,13 @@ int wolfCose_KeyUnwrap(int32_t alg, const WOLFCOSE_KEY* kek,
}
}

if (aesInited != 0) {
(void)wc_AesFree(aes);
}
if (aes != NULL) {
(void)wolfCose_ForceZero(aes, sizeof(*aes));
}

return ret;
}
#endif /* WOLFCOSE_KEY_WRAP */
Expand Down
92 changes: 92 additions & 0 deletions tests/test_cose.c
Original file line number Diff line number Diff line change
Expand Up @@ -14098,8 +14098,95 @@ static int wolfCose_TestZeroizeSawLen(size_t len)
}
return found;
}

static size_t wolfCose_TestZeroizeCountLen(size_t len)
{
size_t i;
size_t count = 0;
for (i = 0; i < g_zeroizeCount; i++) {
if (g_zeroizeLens[i] == len) {
count++;
}
}
return count;
}
#endif /* WOLFCOSE_TEST_ZEROIZE_HOOK */

#if defined(WOLFCOSE_TEST_ZEROIZE_HOOK) && defined(WOLFCOSE_KEY_WRAP) && \
defined(WOLFCOSE_HAVE_AESGCM) && defined(WOLFCOSE_ENCRYPT_ENCRYPT) && \
defined(WOLFCOSE_ENCRYPT_DECRYPT)
/* AES key wrap scrubs its KEK schedule in addition to the content cipher
* context, so each direction wipes at least two Aes objects. */
static void test_cose_key_wrap_context_zeroize(void)
{
static const uint8_t kek[16] = {
0x61u, 0x62u, 0x63u, 0x64u, 0x65u, 0x66u, 0x67u, 0x68u,
0x69u, 0x6Au, 0x6Bu, 0x6Cu, 0x6Du, 0x6Eu, 0x6Fu, 0x70u
};
static const uint8_t wrongKek[16] = {
0x71u, 0x72u, 0x73u, 0x74u, 0x75u, 0x76u, 0x77u, 0x78u,
0x79u, 0x7Au, 0x7Bu, 0x7Cu, 0x7Du, 0x7Eu, 0x7Fu, 0x80u
};
static const uint8_t iv[12] = { 0u };
static const uint8_t payload[] = { 0x01u, 0x02u, 0x03u };
static uint8_t scratch[512];
static uint8_t out[512];
static uint8_t plain[64];
WOLFCOSE_KEY key;
WOLFCOSE_KEY wrongKey;
WOLFCOSE_RECIPIENT rcpt;
WOLFCOSE_HDR hdr;
WC_RNG rng;
size_t outLen = 0;
size_t plainLen = 0;
int ret;

TEST_LOG(" [Key wrap context zeroize]\n");
(void)wc_CoseKey_Init(&key);
(void)wc_CoseKey_Init(&wrongKey);
ret = wc_InitRng(&rng);
TEST_ASSERT(ret == 0, "key wrap zeroize rng");
if (ret == 0) {
ret = wc_CoseKey_SetSymmetric(&key, kek, sizeof(kek));
TEST_ASSERT(ret == 0, "key wrap zeroize key setup");
rcpt.algId = WOLFCOSE_ALG_A128KW;
rcpt.key = &key;
rcpt.kid = NULL;
rcpt.kidLen = 0;
wolfCose_TestZeroizeReset();
ret = wc_CoseEncrypt_Encrypt(&rcpt, 1, WOLFCOSE_ALG_A128GCM,
iv, sizeof(iv), payload, sizeof(payload), NULL, 0, NULL, 0,
scratch, sizeof(scratch), out, sizeof(out), &outLen, &rng);
TEST_ASSERT((ret == 0) &&
(wolfCose_TestZeroizeCountLen(sizeof(Aes)) >= 2u),
"key wrap scrubs the KEK cipher context");
wolfCose_TestZeroizeReset();
ret = wc_CoseEncrypt_Decrypt(&rcpt, 0, out, outLen, NULL, 0, NULL, 0,
scratch, sizeof(scratch), &hdr, plain, sizeof(plain), &plainLen);
TEST_ASSERT((ret == 0) &&
(wolfCose_TestZeroizeCountLen(sizeof(Aes)) >= 2u),
"key unwrap scrubs the KEK cipher context");
if (ret == 0) {
ret = wc_CoseKey_SetSymmetric(&wrongKey, wrongKek,
sizeof(wrongKek));
}
if (ret == 0) {
rcpt.key = &wrongKey;
wolfCose_TestZeroizeReset();
ret = wc_CoseEncrypt_Decrypt(&rcpt, 0, out, outLen, NULL, 0,
NULL, 0, scratch, sizeof(scratch), &hdr, plain,
sizeof(plain), &plainLen);
TEST_ASSERT((ret != 0) &&
(wolfCose_TestZeroizeCountLen(sizeof(Aes)) >= 1u),
"failed key unwrap scrubs the KEK cipher context");
}
(void)wc_FreeRng(&rng);
}
wc_CoseKey_Free(&wrongKey);
wc_CoseKey_Free(&key);
}
#endif /* ZEROIZE_HOOK && KEY_WRAP && AESGCM && ENCRYPT */

#if defined(WOLFCOSE_TEST_ZEROIZE_HOOK) && defined(WOLFCOSE_HAVE_HMAC256) && \
defined(WOLFCOSE_MAC0_CREATE) && defined(WOLFCOSE_MAC0_VERIFY) && \
defined(WOLFCOSE_MAC_CREATE) && defined(WOLFCOSE_MAC_VERIFY)
Expand Down Expand Up @@ -31221,6 +31308,11 @@ int test_cose(void)
#endif
test_cose_key_encode_size_exact();
test_cose_symmetric_attachment();
#if defined(WOLFCOSE_TEST_ZEROIZE_HOOK) && defined(WOLFCOSE_KEY_WRAP) && \
defined(WOLFCOSE_HAVE_AESGCM) && defined(WOLFCOSE_ENCRYPT_ENCRYPT) && \
defined(WOLFCOSE_ENCRYPT_DECRYPT)
test_cose_key_wrap_context_zeroize();
#endif
#if defined(WOLFCOSE_TEST_ZEROIZE_HOOK) && defined(WOLFCOSE_HAVE_HMAC256) && \
defined(WOLFCOSE_MAC0_CREATE) && defined(WOLFCOSE_MAC0_VERIFY) && \
defined(WOLFCOSE_MAC_CREATE) && defined(WOLFCOSE_MAC_VERIFY)
Expand Down