mirror of
https://github.com/openssl/openssl.git
synced 2025-02-23 14:42:15 +08:00
test/evp_test.c: try fetching algorithms
Instead of relying on implicit fetches, try explicit fetches when available. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/9121)
This commit is contained in:
parent
05c9c7b02d
commit
022351fdc3
@ -325,6 +325,7 @@ static int parse_bin(const char *value, unsigned char **buf, size_t *buflen)
|
||||
typedef struct digest_data_st {
|
||||
/* Digest this test is for */
|
||||
const EVP_MD *digest;
|
||||
EVP_MD *fetched_digest;
|
||||
/* Input to digest */
|
||||
STACK_OF(EVP_TEST_BUFFER) *input;
|
||||
/* Expected output */
|
||||
@ -336,8 +337,10 @@ static int digest_test_init(EVP_TEST *t, const char *alg)
|
||||
{
|
||||
DIGEST_DATA *mdat;
|
||||
const EVP_MD *digest;
|
||||
EVP_MD *fetched_digest;
|
||||
|
||||
if ((digest = EVP_get_digestbyname(alg)) == NULL) {
|
||||
if ((digest = fetched_digest = EVP_MD_fetch(NULL, alg, NULL)) == NULL
|
||||
&& (digest = EVP_get_digestbyname(alg)) == NULL) {
|
||||
/* If alg has an OID assume disabled algorithm */
|
||||
if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) {
|
||||
t->skip = 1;
|
||||
@ -349,6 +352,9 @@ static int digest_test_init(EVP_TEST *t, const char *alg)
|
||||
return 0;
|
||||
t->data = mdat;
|
||||
mdat->digest = digest;
|
||||
mdat->fetched_digest = fetched_digest;
|
||||
if (fetched_digest != NULL)
|
||||
TEST_info("%s is fetched", alg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -358,6 +364,7 @@ static void digest_test_cleanup(EVP_TEST *t)
|
||||
|
||||
sk_EVP_TEST_BUFFER_pop_free(mdat->input, evp_test_buffer_free);
|
||||
OPENSSL_free(mdat->output);
|
||||
EVP_MD_meth_free(mdat->fetched_digest);
|
||||
}
|
||||
|
||||
static int digest_test_parse(EVP_TEST *t,
|
||||
@ -472,6 +479,7 @@ static const EVP_TEST_METHOD digest_test_method = {
|
||||
|
||||
typedef struct cipher_data_st {
|
||||
const EVP_CIPHER *cipher;
|
||||
EVP_CIPHER *fetched_cipher;
|
||||
int enc;
|
||||
/* EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE or EVP_CIPH_OCB_MODE if AEAD */
|
||||
int aead;
|
||||
@ -494,10 +502,12 @@ typedef struct cipher_data_st {
|
||||
static int cipher_test_init(EVP_TEST *t, const char *alg)
|
||||
{
|
||||
const EVP_CIPHER *cipher;
|
||||
EVP_CIPHER *fetched_cipher;
|
||||
CIPHER_DATA *cdat;
|
||||
int m;
|
||||
|
||||
if ((cipher = EVP_get_cipherbyname(alg)) == NULL) {
|
||||
if ((cipher = fetched_cipher = EVP_CIPHER_fetch(NULL, alg, NULL)) == NULL
|
||||
&& (cipher = EVP_get_cipherbyname(alg)) == NULL) {
|
||||
/* If alg has an OID assume disabled algorithm */
|
||||
if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) {
|
||||
t->skip = 1;
|
||||
@ -507,6 +517,7 @@ static int cipher_test_init(EVP_TEST *t, const char *alg)
|
||||
}
|
||||
cdat = OPENSSL_zalloc(sizeof(*cdat));
|
||||
cdat->cipher = cipher;
|
||||
cdat->fetched_cipher = fetched_cipher;
|
||||
cdat->enc = -1;
|
||||
m = EVP_CIPHER_mode(cipher);
|
||||
if (m == EVP_CIPH_GCM_MODE
|
||||
@ -520,6 +531,8 @@ static int cipher_test_init(EVP_TEST *t, const char *alg)
|
||||
cdat->aead = 0;
|
||||
|
||||
t->data = cdat;
|
||||
if (fetched_cipher != NULL)
|
||||
TEST_info("%s is fetched", alg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -535,6 +548,7 @@ static void cipher_test_cleanup(EVP_TEST *t)
|
||||
for (i = 0; i < AAD_NUM; i++)
|
||||
OPENSSL_free(cdat->aad[i]);
|
||||
OPENSSL_free(cdat->tag);
|
||||
EVP_CIPHER_meth_free(cdat->fetched_cipher);
|
||||
}
|
||||
|
||||
static int cipher_test_parse(EVP_TEST *t, const char *keyword,
|
||||
|
Loading…
Reference in New Issue
Block a user