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.
This commit is contained in:
Juliusz Sosinowicz
2024-01-19 12:32:17 +01:00
parent ac81d9d29c
commit e438131a3b

View File

@ -8118,8 +8118,12 @@ void wolfSSL_EVP_init(void)
WOLFSSL_ENTER("wolfSSL_EVP_Cipher"); WOLFSSL_ENTER("wolfSSL_EVP_Cipher");
if (ctx == NULL || ((src == NULL || dst == NULL) && if (ctx == NULL) {
(TRUE WOLFSSL_MSG("Bad argument.");
return WOLFSSL_FATAL_ERROR;
}
if (TRUE
#ifdef HAVE_AESGCM #ifdef HAVE_AESGCM
&& ctx->cipherType != AES_128_GCM_TYPE && && ctx->cipherType != AES_128_GCM_TYPE &&
ctx->cipherType != AES_192_GCM_TYPE && ctx->cipherType != AES_192_GCM_TYPE &&
@ -8141,9 +8145,15 @@ void wolfSSL_EVP_init(void)
#ifdef WOLFSSL_SM4_CCM #ifdef WOLFSSL_SM4_CCM
&& ctx->cipherType != SM4_CCM_TYPE && ctx->cipherType != SM4_CCM_TYPE
#endif #endif
))) { ) {
WOLFSSL_MSG("Bad argument."); /* Not an AEAD cipher */
return WOLFSSL_FATAL_ERROR; /* No-op for none AEAD ciphers */
if (src == NULL && dst == NULL && len == 0)
return 0;
if (src == NULL || dst == NULL) {
WOLFSSL_MSG("Bad argument.");
return WOLFSSL_FATAL_ERROR;
}
} }
if (ctx->cipherType == WOLFSSL_EVP_CIPH_TYPE_INIT) { if (ctx->cipherType == WOLFSSL_EVP_CIPH_TYPE_INIT) {