Skip to content

Commit e438131

Browse files
committed
EVP_Cipher: correct parameter checking
EVP_Cipher(ctx, NULL, NULL, 0) is a valid call for all algorithms. For none-AEAD it results in a no-op.
1 parent ac81d9d commit e438131

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

wolfcrypt/src/evp.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8118,8 +8118,12 @@ void wolfSSL_EVP_init(void)
81188118

81198119
WOLFSSL_ENTER("wolfSSL_EVP_Cipher");
81208120

8121-
if (ctx == NULL || ((src == NULL || dst == NULL) &&
8122-
(TRUE
8121+
if (ctx == NULL) {
8122+
WOLFSSL_MSG("Bad argument.");
8123+
return WOLFSSL_FATAL_ERROR;
8124+
}
8125+
8126+
if (TRUE
81238127
#ifdef HAVE_AESGCM
81248128
&& ctx->cipherType != AES_128_GCM_TYPE &&
81258129
ctx->cipherType != AES_192_GCM_TYPE &&
@@ -8141,9 +8145,15 @@ void wolfSSL_EVP_init(void)
81418145
#ifdef WOLFSSL_SM4_CCM
81428146
&& ctx->cipherType != SM4_CCM_TYPE
81438147
#endif
8144-
))) {
8145-
WOLFSSL_MSG("Bad argument.");
8146-
return WOLFSSL_FATAL_ERROR;
8148+
) {
8149+
/* Not an AEAD cipher */
8150+
/* No-op for none AEAD ciphers */
8151+
if (src == NULL && dst == NULL && len == 0)
8152+
return 0;
8153+
if (src == NULL || dst == NULL) {
8154+
WOLFSSL_MSG("Bad argument.");
8155+
return WOLFSSL_FATAL_ERROR;
8156+
}
81478157
}
81488158

81498159
if (ctx->cipherType == WOLFSSL_EVP_CIPH_TYPE_INIT) {

0 commit comments

Comments
 (0)