n = EVP_CIPHER_CTX_get_iv_length(ctx);
if (!ossl_assert(n >= 0 && n <= (int)sizeof(ctx->iv)))
return 0;
- if (iv)
+ if (iv != NULL)
memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_get_iv_length(ctx));
memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_get_iv_length(ctx));
break;
case EVP_CIPH_CTR_MODE:
ctx->num = 0;
/* Don't reuse IV for CTR mode */
- if (iv)
- memcpy(ctx->iv, iv, EVP_CIPHER_CTX_get_iv_length(ctx));
+ if (iv != NULL) {
+ if ((n = EVP_CIPHER_CTX_get_iv_length(ctx)) <= 0)
+ return 0;
+ memcpy(ctx->iv, iv, n);
+ }
break;
default:
}
}
- if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
+ if (key != NULL || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
if (!ctx->cipher->init(ctx, key, iv, enc))
return 0;
}