#include <stdio.h>
#include "internal/cryptlib.h"
+#include "internal/provider.h"
#include <openssl/rand.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
EVP_PKEY **pubk, int npubk)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
+ const OSSL_PROVIDER *prov = EVP_CIPHER_provider(type);
+ OSSL_LIB_CTX *libctx = prov != NULL ? ossl_provider_libctx(prov) : NULL;
+ EVP_PKEY_CTX *pctx = NULL;
int i, len;
int rv = 0;
return 0;
len = EVP_CIPHER_CTX_iv_length(ctx);
- if (len < 0 || RAND_bytes(iv, len) <= 0)
+ if (len < 0 || RAND_priv_bytes_ex(libctx, iv, len) <= 0)
goto err;
len = EVP_CIPHER_CTX_key_length(ctx);
for (i = 0; i < npubk; i++) {
size_t keylen = len;
- EVP_PKEY_CTX *pctx = NULL;
- if ((pctx = EVP_PKEY_CTX_new(pubk[i], NULL)) == NULL) {
+ pctx = EVP_PKEY_CTX_new_from_pkey(libctx, pubk[i], NULL);
+ if (pctx == NULL) {
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
goto err;
}
ekl[i] = (int)keylen;
EVP_PKEY_CTX_free(pctx);
}
+ pctx = NULL;
rv = npubk;
err:
+ EVP_PKEY_CTX_free(pctx);
OPENSSL_cleanse(key, sizeof(key));
return rv;
}
# endif /* OPENSSL_NO_DEPRECATED_3_0 */
#endif /* OPENSSL_NO_EC */
-static int test_EVP_Enveloped(void)
+/*
+ * n = 0 => test using legacy cipher
+ * n = 1 => test using fetched cipher
+ */
+static int test_EVP_Enveloped(int n)
{
int ret = 0;
EVP_CIPHER_CTX *ctx = NULL;
static const unsigned char msg[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int len, kek_len, ciphertext_len, plaintext_len;
unsigned char ciphertext[32], plaintext[16];
- const EVP_CIPHER *type = NULL;
+ EVP_CIPHER *type = NULL;
if (nullprov != NULL)
return TEST_skip("Test does not support a non-default library context");
- type = EVP_aes_256_cbc();
+ if (n == 0)
+ type = (EVP_CIPHER *)EVP_aes_256_cbc();
+ else if (!TEST_ptr(type = EVP_CIPHER_fetch(testctx, "AES-256-CBC",
+ testpropq)))
+ goto err;
if (!TEST_ptr(keypair = load_example_rsa_key())
|| !TEST_ptr(kek = OPENSSL_zalloc(EVP_PKEY_size(keypair)))
ret = 1;
err:
+ if (n != 0)
+ EVP_CIPHER_free(type);
OPENSSL_free(kek);
EVP_PKEY_free(keypair);
EVP_CIPHER_CTX_free(ctx);
ADD_ALL_TESTS(test_EVP_DigestSignInit, 9);
ADD_TEST(test_EVP_DigestVerifyInit);
ADD_TEST(test_EVP_Digest);
- ADD_TEST(test_EVP_Enveloped);
+ ADD_ALL_TESTS(test_EVP_Enveloped, 2);
ADD_ALL_TESTS(test_d2i_AutoPrivateKey, OSSL_NELEM(keydata));
ADD_TEST(test_privatekey_to_pkcs8);
ADD_TEST(test_EVP_PKCS82PKEY_wrong_tag);