|
271 | 271 | #undef LINUXKM_LKCAPI_REGISTER_AESCMAC |
272 | 272 | #endif |
273 | 273 |
|
| 274 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)) && defined(LINUXKM_LKCAPI_REGISTER_AESCMAC) |
| 275 | + #error LINUXKM_LKCAPI_REGISTER for AES-CMAC is supported only on Linux kernel versions >= 5.6.0. |
| 276 | +#endif |
| 277 | + |
274 | 278 | #ifdef LINUXKM_LKCAPI_REGISTER_AESCMAC |
275 | 279 | #include <wolfssl/wolfcrypt/cmac.h> |
276 | 280 | #endif |
@@ -513,6 +517,16 @@ static int km_AesGet(struct km_AesCtx *ctx, int decrypt_p, int copy_p, Aes **aes |
513 | 517 | XMEMCPY(aes_copy, ret, sizeof(Aes)); |
514 | 518 | #if defined(WOLFSSL_AESGCM_STREAM) && defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_AESNI) |
515 | 519 | aes_copy->streamData = NULL; |
| 520 | +#endif |
| 521 | +#ifdef WC_DEBUG_CIPHER_LIFECYCLE |
| 522 | + { |
| 523 | + int ret2 = wc_debug_CipherLifecycleInit(&aes_copy->CipherLifecycleTag, NULL); |
| 524 | + if (ret2 != 0) { |
| 525 | + ForceZero(aes_copy, sizeof *aes_copy); |
| 526 | + free(aes_copy); |
| 527 | + return -ENOMEM; |
| 528 | + } |
| 529 | + } |
516 | 530 | #endif |
517 | 531 | *aes = aes_copy; |
518 | 532 | } |
@@ -5017,6 +5031,9 @@ static int linuxkm_test_aesecb(void) { |
5017 | 5031 | * configurations: wc_AesFree()'s only mainstream XFREE() target is the |
5018 | 5032 | * GCM-streaming streamData buffer, which the CMAC path never allocates. |
5019 | 5033 | * _CRYPTO_CB per-instance contexts would break that invariant. |
| 5034 | + * |
| 5035 | + * The tracking allocation when WC_DEBUG_CIPHER_LIFECYCLE is accommodated |
| 5036 | + * explicitly in km_AesCmacMaterialize(). |
5020 | 5037 | */ |
5021 | 5038 | #if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_FREE) |
5022 | 5039 | #error LINUXKM_LKCAPI_REGISTER_AESCMAC is incompatible with WOLF_CRYPTO_CB_FREE. |
@@ -5111,14 +5128,16 @@ static int km_AesCmacSetKey(struct crypto_shash *tfm, const u8 *key, |
5111 | 5128 | /* wc_InitCmac() zeroizes the Cmac before use, but doesn't release the |
5112 | 5129 | * embedded Aes on post-wc_AesInit() failures. |
5113 | 5130 | */ |
| 5131 | + if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) { |
5114 | 5132 | #ifdef WC_LINUXKM_CMAC_HAVE_CMACFREE |
5115 | | - (void)wc_CmacFree(new_pristine); |
| 5133 | + (void)wc_CmacFree(new_pristine); |
5116 | 5134 | #else |
5117 | | - /* no wc_CmacFree() in the boundary -- a failed-init Cmac holds no |
5118 | | - * allocations in pre-v6 FIPS configurations, so zeroization suffices. |
5119 | | - */ |
5120 | | - ForceZero(new_pristine, sizeof(*new_pristine)); |
| 5135 | + /* no wc_CmacFree() in the boundary -- a failed-init Cmac holds no |
| 5136 | + * allocations in pre-v6 FIPS configurations, so zeroization suffices. |
| 5137 | + */ |
| 5138 | + ForceZero(new_pristine, sizeof(*new_pristine)); |
5121 | 5139 | #endif |
| 5140 | + } |
5122 | 5141 | free(new_pristine); |
5123 | 5142 | /* fail closed on rekey failure -- the kernel re-flags NEED_KEY, and a |
5124 | 5143 | * stale pristine would misattribute subsequent traffic to the old |
@@ -5166,6 +5185,16 @@ static int km_AesCmacMaterialize(struct crypto_shash *tfm, |
5166 | 5185 | return -ENOMEM; |
5167 | 5186 |
|
5168 | 5187 | XMEMCPY(cmac, t_ctx->pristine, sizeof(*cmac)); |
| 5188 | +#ifdef WC_DEBUG_CIPHER_LIFECYCLE |
| 5189 | + { |
| 5190 | + int ret = wc_debug_CipherLifecycleInit(&cmac->aes.CipherLifecycleTag, NULL); |
| 5191 | + if (ret != 0) { |
| 5192 | + ForceZero(cmac, sizeof *cmac); |
| 5193 | + free(cmac); |
| 5194 | + return -ENOMEM; |
| 5195 | + } |
| 5196 | + } |
| 5197 | +#endif |
5169 | 5198 |
|
5170 | 5199 | XMEMCPY(cmac->digest, st->digest, WC_AES_BLOCK_SIZE); |
5171 | 5200 | XMEMCPY(cmac->buffer, st->buffer, WC_AES_BLOCK_SIZE); |
|
0 commit comments