size_t soutl, inl_ = (size_t)inl;
int blocksize;
+ if (inl < 0) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_LENGTH);
+ return 0;
+ }
+
if (ossl_likely(outl != NULL)) {
*outl = 0;
} else {
size_t soutl, inl_ = (size_t)inl;
int blocksize;
+ if (inl < 0) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_LENGTH);
+ return 0;
+ }
+
if (ossl_likely(outl != NULL)) {
*outl = 0;
} else {
return ret;
}
+static int test_evp_cipher_negative_length(void)
+{
+ EVP_CIPHER_CTX *ctx = NULL;
+ EVP_CIPHER *cipher = NULL;
+ unsigned char key[16] = { 0 };
+ unsigned char iv[16] = { 0 };
+ unsigned char buffer[32] = { 0 };
+ int outl = 0;
+ int ret = 0;
+
+ if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
+ goto end;
+
+ if (!TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "AES-128-CBC", testpropq)))
+ goto end;
+
+ /* Initialize encryption context */
+ if (!TEST_int_eq(EVP_EncryptInit_ex2(ctx, cipher, key, iv, NULL), 1))
+ goto end;
+
+ /* Test EVP_EncryptUpdate with negative length - should fail */
+ if (!TEST_int_eq(EVP_EncryptUpdate(ctx, buffer, &outl, (unsigned char *)"test", -1), 0))
+ goto end;
+
+ /* Reinitialize for decryption */
+ if (!TEST_int_eq(EVP_DecryptInit_ex2(ctx, cipher, key, iv, NULL), 1))
+ goto end;
+
+ /* Test EVP_DecryptUpdate with negative length - should fail */
+ if (!TEST_int_eq(EVP_DecryptUpdate(ctx, buffer, &outl, (unsigned char *)"test", -1), 0))
+ goto end;
+
+ ret = 1;
+end:
+ EVP_CIPHER_free(cipher);
+ EVP_CIPHER_CTX_free(ctx);
+ return ret;
+}
+
static int test_evp_cipher_pipeline(void)
{
OSSL_PROVIDER *fake_pipeline = NULL;
ADD_TEST(test_invalid_ctx_for_digest);
+ ADD_TEST(test_evp_cipher_negative_length);
+
ADD_TEST(test_evp_cipher_pipeline);
#ifndef OPENSSL_NO_ML_KEM