Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -25653,8 +25653,8 @@ static int test_wc_CreateEncryptedPKCS8Key(void)
{
EXPECT_DECLS;
#if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
&& !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
!defined(NO_ASN_CRYPT)
&& !defined(NO_AES_CBC) && defined(HAVE_AES_DECRYPT) && !defined(NO_RSA) && \
!defined(NO_SHA) && !defined(NO_ASN_CRYPT)
WC_RNG rng;
byte* encKey = NULL;
word32 encKeySz = 0;
Expand Down Expand Up @@ -25696,7 +25696,8 @@ static int test_wc_CreateEncryptedPKCS8Key(void)

#if defined(HAVE_PKCS8) && !defined(NO_ASN) && !defined(NO_PWDBASED) && \
!defined(NO_SHA) && !defined(NO_ASN_CRYPT) && ((defined(WOLFSSL_AES_256) && \
!defined(NO_AES_CBC)) || !defined(NO_DES3) || !defined(NO_RC4))
!defined(NO_AES_CBC) && defined(HAVE_AES_DECRYPT)) || !defined(NO_DES3) || \
!defined(NO_RC4))
/* Encrypt a block-aligned plaintext PKCS#8 and verify the trailing encrypted
* OCTET STRING length. expExtra is the padding expected: a full block for CBC
* ciphers, 0 for stream ciphers. Also confirms a decrypt round-trip. */
Expand Down Expand Up @@ -25765,7 +25766,7 @@ static int test_wc_EncryptPKCS8Key_blockAligned(void)
EXPECT_DECLS;
#if defined(HAVE_PKCS8) && !defined(NO_ASN) && !defined(NO_PWDBASED) \
&& defined(WOLFSSL_AES_256) && !defined(NO_AES_CBC) && !defined(NO_SHA) \
&& !defined(NO_ASN_CRYPT)
&& defined(HAVE_AES_DECRYPT) && !defined(NO_ASN_CRYPT)
EXPECT_TEST(enc_pkcs8_pad_check(PKCS5, PBES2, AES256CBCb, AES_BLOCK_SIZE));
#endif
return EXPECT_RESULT();
Expand Down Expand Up @@ -25840,7 +25841,7 @@ static int test_wc_EncryptPKCS8Key_ex_goodHmac(void)
EXPECT_DECLS;
#if defined(HAVE_PKCS8) && !defined(NO_ASN) && !defined(NO_PWDBASED) \
&& defined(WOLFSSL_AES_256) && !defined(NO_AES_CBC) && !defined(NO_ASN_CRYPT) \
&& !defined(NO_SHA256) && !defined(NO_HMAC)
&& defined(HAVE_AES_DECRYPT) && !defined(NO_SHA256) && !defined(NO_HMAC)
WC_RNG rng;
word32 outSz = 0;
word32 encSz = 0;
Expand Down Expand Up @@ -37755,7 +37756,7 @@ static int test_certreq_sighash_algos(void)
!defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
!defined(NO_SHA256) && defined(WOLFSSL_SHA384) && \
defined(WOLFSSL_AES_256) && defined(HAVE_AES_CBC) && \
!defined(WOLFSSL_NO_TLS12)
defined(HAVE_AES_DECRYPT) && !defined(WOLFSSL_NO_TLS12)
WOLFSSL_CTX *ctx_c = NULL;
WOLFSSL_CTX *ctx_s = NULL;
WOLFSSL *ssl_c = NULL;
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ static int test_wc_AesCbcEncryptDecrypt_BadArgs(Aes* aes, byte* key,
ExpectIntEQ(wc_AesCbcEncrypt(NULL, cipher, plain, 0),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));

#ifdef HAVE_AES_DECRYPT
ExpectIntEQ(wc_AesSetKey(aes, key, keyLen, iv, AES_DECRYPTION), 0);
ExpectIntEQ(wc_AesCbcDecrypt(NULL, NULL, NULL, 0),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
Expand Down Expand Up @@ -751,6 +752,7 @@ static int test_wc_AesCbcEncryptDecrypt_BadArgs(Aes* aes, byte* key,
ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, cipher,
WC_AES_BLOCK_SIZE * 2, key, keyLen, iv),
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
#endif /* HAVE_AES_DECRYPT */

return EXPECT_RESULT();
}
Expand Down
13 changes: 7 additions & 6 deletions tests/api/test_pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,20 @@ int test_wc_PKCS12_create(void)
#if !defined(NO_DES3) && !defined(NO_SHA)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_SHA1_DES3, PBE_SHA1_DES3));
#endif
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_256) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
#if defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT) && !defined(NO_AES) && \
!defined(NO_AES_256) && !defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
/* Encoding certificate with PBE_AES256_CBC needs WOLFSSL_ASN_TEMPLATE */
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES256_CBC, PBE_AES256_CBC));
#endif
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_128) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
#if defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT) && !defined(NO_AES) && \
!defined(NO_AES_128) && !defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE)
/* Encoding certificate with PBE_AES128_CBC needs WOLFSSL_ASN_TEMPLATE */
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES128_CBC, PBE_AES128_CBC));
#endif
/* Testing a mixture of 2 algorithms */
#if defined(HAVE_AES_CBC) && !defined(NO_AES) && !defined(NO_AES_256) && \
!defined(NO_SHA) && defined(WOLFSSL_ASN_TEMPLATE) && !defined(NO_DES3)
#if defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT) && !defined(NO_AES) && \
!defined(NO_AES_256) && !defined(NO_SHA) && \
defined(WOLFSSL_ASN_TEMPLATE) && !defined(NO_DES3)
EXPECT_TEST(test_wc_PKCS12_create_once(PBE_AES256_CBC, PBE_SHA1_DES3));
#endif
#endif
Expand Down
16 changes: 9 additions & 7 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
* WOLFSSL_AES_EAX: Enable AES-EAX AEAD mode default: off
* WOLFSSL_CMAC: Enable AES-CMAC (RFC 4493) default: off
* HAVE_AESCCM: Enable AES-CCM mode default: off
* HAVE_AESCCM_DECRYPT: Enable AES-CCM decryption default: on
* (when HAVE_AESCCM is enabled)
* HAVE_AES_KEYWRAP: Enable AES key wrap (RFC 3394) default: off
* WOLFSSL_AES_KEYWRAP_PADDING: AES key wrap padding (RFC 5649) default: off
* WOLFSSL_AES_CBC_LENGTH_CHECKS: Validate CBC input length default: off
Expand Down Expand Up @@ -8979,7 +8981,7 @@ void AES_GCM_encrypt_vaes(const unsigned char *in, unsigned char *out,
#endif /* HAVE_INTEL_AVX2 */
#endif /* HAVE_INTEL_AVX1 */

#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)
void AES_GCM_decrypt_aesni(const unsigned char *in, unsigned char *out,
const unsigned char* addt, const unsigned char* ivec,
const unsigned char *tag, word32 nbytes, word32 abytes,
Expand Down Expand Up @@ -9018,7 +9020,7 @@ void AES_GCM_decrypt_vaes(const unsigned char *in, unsigned char *out,
#endif
#endif /* HAVE_INTEL_AVX2 */
#endif /* HAVE_INTEL_AVX1 */
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */

#endif /* WOLFSSL_AESNI */

Expand Down Expand Up @@ -15341,7 +15343,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
authIn, authInSz);
}

#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESCCM_DECRYPT)
int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
const byte* authTag, word32 authTagSz,
Expand Down Expand Up @@ -15410,7 +15412,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
return (kStatus_Success == status) ? 0 : BAD_FUNC_ARG;
}

#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESCCM_DECRYPT)
int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
const byte* authTag, word32 authTagSz,
Expand Down Expand Up @@ -15458,7 +15460,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
}
return 0;
}
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESCCM_DECRYPT */

#else

Expand Down Expand Up @@ -15773,7 +15775,7 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
return ret;
}

#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESCCM_DECRYPT)
/* Software AES - CCM Decrypt */
int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
Expand Down Expand Up @@ -15966,7 +15968,7 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
return ret;
}

#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESCCM_DECRYPT */
#endif /* software CCM */

/* abstract functions that call lower level AESCCM functions */
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/port/cavium/cavium_nitrox.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ int NitroxAesGcmEncrypt(Aes* aes,
authInSz, authIn, authTag);
}

#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cavium GCM-only decrypt build lacks its helper · Missing/incorrect platform conditionals

NitroxAesGcmDecrypt() is emitted when only HAVE_AESGCM_DECRYPT is set, but its NitroxAesDecrypt() callee remains under HAVE_AES_DECRYPT; Cavium NO_AES_DECRYPT builds fail. Adjacent #8240 concerns IV padding, not this guard.

Related known finding #8240 (similar but distinct): Both affect the Cavium Nitrox GCM decrypt wrapper, but #8240 passes uninitialized IV-tail bytes to hardware, whereas this candidate conditionally omits NitroxAesDecrypt and breaks GCM-only builds. The faulting operations, root causes, and required patches differ.

Suggested fix: Guard NitroxAesDecrypt() with HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT, while keeping CBC entry points restricted to HAVE_AES_DECRYPT.
Basis: ISO/IEC 9899:1990 §6.7 requires an external definition for an identifier with external linkage that is used in an expression.

int NitroxAesGcmDecrypt(Aes* aes,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
Expand All @@ -865,7 +865,7 @@ int NitroxAesGcmDecrypt(Aes* aes,
return NitroxAesDecrypt(aes, AES_GCM, key, ivTmp, out, in, sz,
authInSz, authIn, authTag);
}
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */
#endif /* HAVE_AESGCM */

#endif /* HAVE_AES_CBC || HAVE_AESGCM */
Expand Down
4 changes: 2 additions & 2 deletions wolfcrypt/src/port/intel/quickassist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ int IntelQaSymAesGcmEncrypt(WC_ASYNC_DEV* dev,
CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT,
CPA_CY_SYM_HASH_AES_GCM, authTag, authTagSz, authIn, authInSz);
}
#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)
int IntelQaSymAesGcmDecrypt(WC_ASYNC_DEV* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
Expand All @@ -2641,7 +2641,7 @@ int IntelQaSymAesGcmDecrypt(WC_ASYNC_DEV* dev,
CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT,
CPA_CY_SYM_HASH_AES_GCM, (byte*)authTag, authTagSz, authIn, authInSz);
}
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */
#endif /* HAVE_AESGCM */

#ifndef NO_DES3
Expand Down
10 changes: 6 additions & 4 deletions wolfcrypt/src/port/intel/quickassist_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ static int IntelQaGetCyInstanceCount(void);
static int IntelQaSymAesGcmEncrypt(IntelQaDev*, byte*,
const byte*, word32, const byte*, word32, const byte*, word32,
byte*, word32, const byte*, word32);
#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)
static int IntelQaSymAesGcmDecrypt(IntelQaDev*, byte*,
const byte*, word32, const byte*, word32, const byte*, word32,
const byte*, word32, const byte*, word32);
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */
#endif /* HAVE_AESGCM */
#endif /* !NO_AES */

Expand Down Expand Up @@ -1173,7 +1173,7 @@ int IntelQaSymAesGcmEncrypt(IntelQaDev* dev,
CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT,
CPA_CY_SYM_HASH_AES_GCM, authTag, authTagSz, authIn, authInSz);
}
#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)
int IntelQaSymAesGcmDecrypt(IntelQaDev* dev,
byte* out, const byte* in, word32 sz,
const byte* key, word32 keySz,
Expand All @@ -1187,7 +1187,7 @@ int IntelQaSymAesGcmDecrypt(IntelQaDev* dev,
CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT,
CPA_CY_SYM_HASH_AES_GCM, (byte*)authTag, authTagSz, authIn, authInSz);
}
#endif /* HAVE_AES_DECRYPT */
#endif /* HAVE_AES_DECRYPT || HAVE_AESGCM_DECRYPT */
#endif /* HAVE_AESGCM */

#ifndef NO_DES3
Expand Down Expand Up @@ -1281,6 +1281,7 @@ int IntelQaSymSync_CryptoDevCb(int devId, struct wc_CryptoInfo* info, void* ctx)
info->cipher.aesgcm_enc.authInSz);
}
else {
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)
Aes* aes = info->cipher.aesgcm_dec.aes;
if (aes == NULL)
return BAD_FUNC_ARG;
Expand All @@ -1296,6 +1297,7 @@ int IntelQaSymSync_CryptoDevCb(int devId, struct wc_CryptoInfo* info, void* ctx)
info->cipher.aesgcm_dec.authTagSz,
info->cipher.aesgcm_dec.authIn,
info->cipher.aesgcm_dec.authInSz);
#endif
}
}
#endif /* HAVE_AESGCM */
Expand Down
4 changes: 3 additions & 1 deletion wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16964,16 +16964,18 @@ static wc_test_ret_t aes_no_key_set_test(void)
if (wc_AesGcmEncrypt(aes, cipher, plain, WC_AES_BLOCK_SIZE, iv, sizeof(iv),
tag, sizeof(tag), NULL, 0) != WC_NO_ERR_TRACE(MISSING_KEY))
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESGCM_DECRYPT)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mode-specific decrypt paths lack successful-operation coverage · Weak or missing assertions

The new branches only assert MISSING_KEY; successful GCM and CCM decrypt KATs remain HAVE_AES_DECRYPT-only. The newly enabled mode-specific implementations are never functionally exercised.

Suggested fix: Run successful decrypt and authentication-failure KATs under the corresponding GCM and CCM mode-specific guards.

if (wc_AesGcmDecrypt(aes, cipher, plain, WC_AES_BLOCK_SIZE, iv, sizeof(iv),
tag, sizeof(tag), NULL, 0) != WC_NO_ERR_TRACE(MISSING_KEY))
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
#endif
#endif

#ifdef HAVE_AESCCM
if (wc_AesCcmEncrypt(aes, cipher, plain, WC_AES_BLOCK_SIZE, iv, 13,
tag, sizeof(tag), NULL, 0) != WC_NO_ERR_TRACE(MISSING_KEY))
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
#ifdef HAVE_AES_DECRYPT
#if defined(HAVE_AES_DECRYPT) || defined(HAVE_AESCCM_DECRYPT)
if (wc_AesCcmDecrypt(aes, cipher, plain, WC_AES_BLOCK_SIZE, iv, 13,
tag, sizeof(tag), NULL, 0) != WC_NO_ERR_TRACE(MISSING_KEY))
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
Expand Down
Loading
Loading