1*66bae5e7Schristos /*
2*66bae5e7Schristos  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3*66bae5e7Schristos  *
4*66bae5e7Schristos  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*66bae5e7Schristos  * this file except in compliance with the License.  You can obtain a copy
6*66bae5e7Schristos  * in the file LICENSE in the source distribution or at
7*66bae5e7Schristos  * https://www.openssl.org/source/license.html
8*66bae5e7Schristos  */
9*66bae5e7Schristos 
10*66bae5e7Schristos /*
11*66bae5e7Schristos  * SHA256 low level APIs are deprecated for public use, but still ok for
12*66bae5e7Schristos  * internal use.  Note, that due to symbols not being exported, only the
13*66bae5e7Schristos  * #defines can be accessed.  In this case SHA256_CBLOCK.
14*66bae5e7Schristos  */
15*66bae5e7Schristos #include "internal/deprecated.h"
16*66bae5e7Schristos 
17*66bae5e7Schristos #include <string.h>
18*66bae5e7Schristos #include <openssl/sha.h>
19*66bae5e7Schristos #include <openssl/evp.h>
20*66bae5e7Schristos #include <openssl/provider.h>
21*66bae5e7Schristos #include "internal/sizes.h"
22*66bae5e7Schristos #include "testutil.h"
23*66bae5e7Schristos 
24*66bae5e7Schristos static char *config_file = NULL;
25*66bae5e7Schristos static char *alg = "digest";
26*66bae5e7Schristos static int use_default_ctx = 0;
27*66bae5e7Schristos static char *fetch_property = NULL;
28*66bae5e7Schristos static int expected_fetch_result = 1;
29*66bae5e7Schristos 
30*66bae5e7Schristos typedef enum OPTION_choice {
31*66bae5e7Schristos     OPT_ERR = -1,
32*66bae5e7Schristos     OPT_EOF = 0,
33*66bae5e7Schristos     OPT_ALG_FETCH_TYPE,
34*66bae5e7Schristos     OPT_FETCH_PROPERTY,
35*66bae5e7Schristos     OPT_FETCH_FAILURE,
36*66bae5e7Schristos     OPT_USE_DEFAULTCTX,
37*66bae5e7Schristos     OPT_CONFIG_FILE,
38*66bae5e7Schristos     OPT_TEST_ENUM
39*66bae5e7Schristos } OPTION_CHOICE;
40*66bae5e7Schristos 
test_get_options(void)41*66bae5e7Schristos const OPTIONS *test_get_options(void)
42*66bae5e7Schristos {
43*66bae5e7Schristos     static const OPTIONS test_options[] = {
44*66bae5e7Schristos         OPT_TEST_OPTIONS_WITH_EXTRA_USAGE("[provname...]\n"),
45*66bae5e7Schristos         { "config", OPT_CONFIG_FILE, '<', "The configuration file to use for the libctx" },
46*66bae5e7Schristos         { "type", OPT_ALG_FETCH_TYPE, 's', "The fetch type to test" },
47*66bae5e7Schristos         { "property", OPT_FETCH_PROPERTY, 's', "The fetch property e.g. provider=fips" },
48*66bae5e7Schristos         { "fetchfail", OPT_FETCH_FAILURE, '-', "fetch is expected to fail" },
49*66bae5e7Schristos         { "defaultctx", OPT_USE_DEFAULTCTX, '-',
50*66bae5e7Schristos           "Use the default context if this is set" },
51*66bae5e7Schristos         { OPT_HELP_STR, 1, '-', "file\tProvider names to explicitly load\n" },
52*66bae5e7Schristos         { NULL }
53*66bae5e7Schristos     };
54*66bae5e7Schristos     return test_options;
55*66bae5e7Schristos }
56*66bae5e7Schristos 
calculate_digest(const EVP_MD * md,const char * msg,size_t len,const unsigned char * exptd)57*66bae5e7Schristos static int calculate_digest(const EVP_MD *md, const char *msg, size_t len,
58*66bae5e7Schristos                             const unsigned char *exptd)
59*66bae5e7Schristos {
60*66bae5e7Schristos     unsigned char out[SHA256_DIGEST_LENGTH];
61*66bae5e7Schristos     EVP_MD_CTX *ctx;
62*66bae5e7Schristos     int ret = 0;
63*66bae5e7Schristos 
64*66bae5e7Schristos     if (!TEST_ptr(ctx = EVP_MD_CTX_new())
65*66bae5e7Schristos             || !TEST_true(EVP_DigestInit_ex(ctx, md, NULL))
66*66bae5e7Schristos             || !TEST_true(EVP_DigestUpdate(ctx, msg, len))
67*66bae5e7Schristos             || !TEST_true(EVP_DigestFinal_ex(ctx, out, NULL))
68*66bae5e7Schristos             || !TEST_mem_eq(out, SHA256_DIGEST_LENGTH, exptd,
69*66bae5e7Schristos                             SHA256_DIGEST_LENGTH)
70*66bae5e7Schristos             || !TEST_true(md == EVP_MD_CTX_get0_md(ctx)))
71*66bae5e7Schristos         goto err;
72*66bae5e7Schristos 
73*66bae5e7Schristos     ret = 1;
74*66bae5e7Schristos  err:
75*66bae5e7Schristos     EVP_MD_CTX_free(ctx);
76*66bae5e7Schristos     return ret;
77*66bae5e7Schristos }
78*66bae5e7Schristos 
load_providers(OSSL_LIB_CTX ** libctx,OSSL_PROVIDER * prov[])79*66bae5e7Schristos static int load_providers(OSSL_LIB_CTX **libctx, OSSL_PROVIDER *prov[])
80*66bae5e7Schristos {
81*66bae5e7Schristos     OSSL_LIB_CTX *ctx = NULL;
82*66bae5e7Schristos     int ret = 0;
83*66bae5e7Schristos     size_t i;
84*66bae5e7Schristos 
85*66bae5e7Schristos     ctx = OSSL_LIB_CTX_new();
86*66bae5e7Schristos     if (!TEST_ptr(ctx))
87*66bae5e7Schristos         goto err;
88*66bae5e7Schristos 
89*66bae5e7Schristos     if (!TEST_true(OSSL_LIB_CTX_load_config(ctx, config_file)))
90*66bae5e7Schristos         goto err;
91*66bae5e7Schristos     if (test_get_argument_count() > 2)
92*66bae5e7Schristos         goto err;
93*66bae5e7Schristos 
94*66bae5e7Schristos     for (i = 0; i < test_get_argument_count(); ++i) {
95*66bae5e7Schristos         char *provname = test_get_argument(i);
96*66bae5e7Schristos         prov[i] = OSSL_PROVIDER_load(ctx, provname);
97*66bae5e7Schristos         if (!TEST_ptr(prov[i]))
98*66bae5e7Schristos             goto err;
99*66bae5e7Schristos     }
100*66bae5e7Schristos 
101*66bae5e7Schristos     ret = 1;
102*66bae5e7Schristos     *libctx = ctx;
103*66bae5e7Schristos err:
104*66bae5e7Schristos     if (ret == 0)
105*66bae5e7Schristos         OSSL_LIB_CTX_free(ctx);
106*66bae5e7Schristos     return ret;
107*66bae5e7Schristos }
108*66bae5e7Schristos 
unload_providers(OSSL_LIB_CTX ** libctx,OSSL_PROVIDER * prov[])109*66bae5e7Schristos static void unload_providers(OSSL_LIB_CTX **libctx, OSSL_PROVIDER *prov[])
110*66bae5e7Schristos {
111*66bae5e7Schristos     if (prov[0] != NULL)
112*66bae5e7Schristos         OSSL_PROVIDER_unload(prov[0]);
113*66bae5e7Schristos     if (prov[1] != NULL)
114*66bae5e7Schristos         OSSL_PROVIDER_unload(prov[1]);
115*66bae5e7Schristos     /* Not normally needed, but we would like to test that
116*66bae5e7Schristos      * OPENSSL_thread_stop_ex() behaves as expected.
117*66bae5e7Schristos      */
118*66bae5e7Schristos     if (libctx != NULL && *libctx != NULL) {
119*66bae5e7Schristos         OPENSSL_thread_stop_ex(*libctx);
120*66bae5e7Schristos         OSSL_LIB_CTX_free(*libctx);
121*66bae5e7Schristos     }
122*66bae5e7Schristos }
123*66bae5e7Schristos 
make_algor(int nid)124*66bae5e7Schristos static X509_ALGOR *make_algor(int nid)
125*66bae5e7Schristos {
126*66bae5e7Schristos     X509_ALGOR *algor;
127*66bae5e7Schristos 
128*66bae5e7Schristos     if (!TEST_ptr(algor = X509_ALGOR_new())
129*66bae5e7Schristos         || !TEST_true(X509_ALGOR_set0(algor, OBJ_nid2obj(nid),
130*66bae5e7Schristos                                       V_ASN1_UNDEF, NULL))) {
131*66bae5e7Schristos         X509_ALGOR_free(algor);
132*66bae5e7Schristos         return NULL;
133*66bae5e7Schristos     }
134*66bae5e7Schristos     return algor;
135*66bae5e7Schristos }
136*66bae5e7Schristos 
137*66bae5e7Schristos /*
138*66bae5e7Schristos  * Test EVP_MD_fetch()
139*66bae5e7Schristos  */
test_md(const EVP_MD * md)140*66bae5e7Schristos static int test_md(const EVP_MD *md)
141*66bae5e7Schristos {
142*66bae5e7Schristos     const char testmsg[] = "Hello world";
143*66bae5e7Schristos     const unsigned char exptd[] = {
144*66bae5e7Schristos       0x27, 0x51, 0x8b, 0xa9, 0x68, 0x30, 0x11, 0xf6, 0xb3, 0x96, 0x07, 0x2c,
145*66bae5e7Schristos       0x05, 0xf6, 0x65, 0x6d, 0x04, 0xf5, 0xfb, 0xc3, 0x78, 0x7c, 0xf9, 0x24,
146*66bae5e7Schristos       0x90, 0xec, 0x60, 0x6e, 0x50, 0x92, 0xe3, 0x26
147*66bae5e7Schristos     };
148*66bae5e7Schristos 
149*66bae5e7Schristos     return TEST_ptr(md)
150*66bae5e7Schristos         && TEST_true(EVP_MD_is_a(md, "SHA256"))
151*66bae5e7Schristos         && TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))
152*66bae5e7Schristos         && TEST_int_eq(EVP_MD_get_size(md), SHA256_DIGEST_LENGTH)
153*66bae5e7Schristos         && TEST_int_eq(EVP_MD_get_block_size(md), SHA256_CBLOCK);
154*66bae5e7Schristos }
155*66bae5e7Schristos 
test_implicit_EVP_MD_fetch(void)156*66bae5e7Schristos static int test_implicit_EVP_MD_fetch(void)
157*66bae5e7Schristos {
158*66bae5e7Schristos     OSSL_LIB_CTX *ctx = NULL;
159*66bae5e7Schristos     OSSL_PROVIDER *prov[2] = {NULL, NULL};
160*66bae5e7Schristos     int ret = 0;
161*66bae5e7Schristos 
162*66bae5e7Schristos     ret = (use_default_ctx == 0 || load_providers(&ctx, prov))
163*66bae5e7Schristos         && test_md(EVP_sha256());
164*66bae5e7Schristos 
165*66bae5e7Schristos     unload_providers(&ctx, prov);
166*66bae5e7Schristos     return ret;
167*66bae5e7Schristos }
168*66bae5e7Schristos 
test_explicit_EVP_MD_fetch(const char * id)169*66bae5e7Schristos static int test_explicit_EVP_MD_fetch(const char *id)
170*66bae5e7Schristos {
171*66bae5e7Schristos     OSSL_LIB_CTX *ctx = NULL;
172*66bae5e7Schristos     EVP_MD *md = NULL;
173*66bae5e7Schristos     OSSL_PROVIDER *prov[2] = {NULL, NULL};
174*66bae5e7Schristos     int ret = 0;
175*66bae5e7Schristos 
176*66bae5e7Schristos     if (use_default_ctx == 0 && !load_providers(&ctx, prov))
177*66bae5e7Schristos         goto err;
178*66bae5e7Schristos 
179*66bae5e7Schristos     md = EVP_MD_fetch(ctx, id, fetch_property);
180*66bae5e7Schristos     if (expected_fetch_result != 0) {
181*66bae5e7Schristos         if (!test_md(md))
182*66bae5e7Schristos             goto err;
183*66bae5e7Schristos 
184*66bae5e7Schristos         /* Also test EVP_MD_up_ref() while we're doing this */
185*66bae5e7Schristos         if (!TEST_true(EVP_MD_up_ref(md)))
186*66bae5e7Schristos             goto err;
187*66bae5e7Schristos         /* Ref count should now be 2. Release first one here */
188*66bae5e7Schristos         EVP_MD_free(md);
189*66bae5e7Schristos     } else {
190*66bae5e7Schristos         if (!TEST_ptr_null(md))
191*66bae5e7Schristos             goto err;
192*66bae5e7Schristos     }
193*66bae5e7Schristos     ret = 1;
194*66bae5e7Schristos 
195*66bae5e7Schristos  err:
196*66bae5e7Schristos     EVP_MD_free(md);
197*66bae5e7Schristos     unload_providers(&ctx, prov);
198*66bae5e7Schristos     return ret;
199*66bae5e7Schristos }
200*66bae5e7Schristos 
test_explicit_EVP_MD_fetch_by_name(void)201*66bae5e7Schristos static int test_explicit_EVP_MD_fetch_by_name(void)
202*66bae5e7Schristos {
203*66bae5e7Schristos     return test_explicit_EVP_MD_fetch("SHA256");
204*66bae5e7Schristos }
205*66bae5e7Schristos 
206*66bae5e7Schristos /*
207*66bae5e7Schristos  * idx 0: Allow names from OBJ_obj2txt()
208*66bae5e7Schristos  * idx 1: Force an OID in text form from OBJ_obj2txt()
209*66bae5e7Schristos  */
test_explicit_EVP_MD_fetch_by_X509_ALGOR(int idx)210*66bae5e7Schristos static int test_explicit_EVP_MD_fetch_by_X509_ALGOR(int idx)
211*66bae5e7Schristos {
212*66bae5e7Schristos     int ret = 0;
213*66bae5e7Schristos     X509_ALGOR *algor = make_algor(NID_sha256);
214*66bae5e7Schristos     const ASN1_OBJECT *obj;
215*66bae5e7Schristos     char id[OSSL_MAX_NAME_SIZE];
216*66bae5e7Schristos 
217*66bae5e7Schristos     if (algor == NULL)
218*66bae5e7Schristos         return 0;
219*66bae5e7Schristos 
220*66bae5e7Schristos     X509_ALGOR_get0(&obj, NULL, NULL, algor);
221*66bae5e7Schristos     switch (idx) {
222*66bae5e7Schristos     case 0:
223*66bae5e7Schristos         if (!TEST_int_gt(OBJ_obj2txt(id, sizeof(id), obj, 0), 0))
224*66bae5e7Schristos             goto end;
225*66bae5e7Schristos         break;
226*66bae5e7Schristos     case 1:
227*66bae5e7Schristos         if (!TEST_int_gt(OBJ_obj2txt(id, sizeof(id), obj, 1), 0))
228*66bae5e7Schristos             goto end;
229*66bae5e7Schristos         break;
230*66bae5e7Schristos     }
231*66bae5e7Schristos 
232*66bae5e7Schristos     ret = test_explicit_EVP_MD_fetch(id);
233*66bae5e7Schristos  end:
234*66bae5e7Schristos     X509_ALGOR_free(algor);
235*66bae5e7Schristos     return ret;
236*66bae5e7Schristos }
237*66bae5e7Schristos 
238*66bae5e7Schristos /*
239*66bae5e7Schristos  * Test EVP_CIPHER_fetch()
240*66bae5e7Schristos  */
encrypt_decrypt(const EVP_CIPHER * cipher,const unsigned char * msg,size_t len)241*66bae5e7Schristos static int encrypt_decrypt(const EVP_CIPHER *cipher, const unsigned char *msg,
242*66bae5e7Schristos                            size_t len)
243*66bae5e7Schristos {
244*66bae5e7Schristos     int ret = 0, ctlen, ptlen;
245*66bae5e7Schristos     EVP_CIPHER_CTX *ctx = NULL;
246*66bae5e7Schristos     unsigned char key[128 / 8];
247*66bae5e7Schristos     unsigned char ct[64], pt[64];
248*66bae5e7Schristos 
249*66bae5e7Schristos     memset(key, 0, sizeof(key));
250*66bae5e7Schristos     if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())
251*66bae5e7Schristos             || !TEST_true(EVP_CipherInit_ex(ctx, cipher, NULL, key, NULL, 1))
252*66bae5e7Schristos             || !TEST_true(EVP_CipherUpdate(ctx, ct, &ctlen, msg, len))
253*66bae5e7Schristos             || !TEST_true(EVP_CipherFinal_ex(ctx, ct, &ctlen))
254*66bae5e7Schristos             || !TEST_true(EVP_CipherInit_ex(ctx, cipher, NULL, key, NULL, 0))
255*66bae5e7Schristos             || !TEST_true(EVP_CipherUpdate(ctx, pt, &ptlen, ct, ctlen))
256*66bae5e7Schristos             || !TEST_true(EVP_CipherFinal_ex(ctx, pt, &ptlen))
257*66bae5e7Schristos             || !TEST_mem_eq(pt, ptlen, msg, len))
258*66bae5e7Schristos         goto err;
259*66bae5e7Schristos 
260*66bae5e7Schristos     ret = 1;
261*66bae5e7Schristos err:
262*66bae5e7Schristos     EVP_CIPHER_CTX_free(ctx);
263*66bae5e7Schristos     return ret;
264*66bae5e7Schristos }
265*66bae5e7Schristos 
test_cipher(const EVP_CIPHER * cipher)266*66bae5e7Schristos static int test_cipher(const EVP_CIPHER *cipher)
267*66bae5e7Schristos {
268*66bae5e7Schristos     const unsigned char testmsg[] = "Hello world";
269*66bae5e7Schristos 
270*66bae5e7Schristos     return TEST_ptr(cipher)
271*66bae5e7Schristos         && TEST_true(encrypt_decrypt(cipher, testmsg, sizeof(testmsg)));
272*66bae5e7Schristos }
273*66bae5e7Schristos 
test_implicit_EVP_CIPHER_fetch(void)274*66bae5e7Schristos static int test_implicit_EVP_CIPHER_fetch(void)
275*66bae5e7Schristos {
276*66bae5e7Schristos     OSSL_LIB_CTX *ctx = NULL;
277*66bae5e7Schristos     OSSL_PROVIDER *prov[2] = {NULL, NULL};
278*66bae5e7Schristos     int ret = 0;
279*66bae5e7Schristos 
280*66bae5e7Schristos     ret = (use_default_ctx == 0 || load_providers(&ctx, prov))
281*66bae5e7Schristos         && test_cipher(EVP_aes_128_cbc());
282*66bae5e7Schristos 
283*66bae5e7Schristos     unload_providers(&ctx, prov);
284*66bae5e7Schristos     return ret;
285*66bae5e7Schristos }
286*66bae5e7Schristos 
test_explicit_EVP_CIPHER_fetch(const char * id)287*66bae5e7Schristos static int test_explicit_EVP_CIPHER_fetch(const char *id)
288*66bae5e7Schristos {
289*66bae5e7Schristos     OSSL_LIB_CTX *ctx = NULL;
290*66bae5e7Schristos     EVP_CIPHER *cipher = NULL;
291*66bae5e7Schristos     OSSL_PROVIDER *prov[2] = {NULL, NULL};
292*66bae5e7Schristos     int ret = 0;
293*66bae5e7Schristos 
294*66bae5e7Schristos     if (use_default_ctx == 0 && !load_providers(&ctx, prov))
295*66bae5e7Schristos         goto err;
296*66bae5e7Schristos 
297*66bae5e7Schristos     cipher = EVP_CIPHER_fetch(ctx, id, fetch_property);
298*66bae5e7Schristos     if (expected_fetch_result != 0) {
299*66bae5e7Schristos         if (!test_cipher(cipher))
300*66bae5e7Schristos             goto err;
301*66bae5e7Schristos 
302*66bae5e7Schristos         if (!TEST_true(EVP_CIPHER_up_ref(cipher)))
303*66bae5e7Schristos             goto err;
304*66bae5e7Schristos         /* Ref count should now be 2. Release first one here */
305*66bae5e7Schristos         EVP_CIPHER_free(cipher);
306*66bae5e7Schristos     } else {
307*66bae5e7Schristos         if (!TEST_ptr_null(cipher))
308*66bae5e7Schristos             goto err;
309*66bae5e7Schristos     }
310*66bae5e7Schristos     ret = 1;
311*66bae5e7Schristos err:
312*66bae5e7Schristos     EVP_CIPHER_free(cipher);
313*66bae5e7Schristos     unload_providers(&ctx, prov);
314*66bae5e7Schristos     return ret;
315*66bae5e7Schristos }
316*66bae5e7Schristos 
test_explicit_EVP_CIPHER_fetch_by_name(void)317*66bae5e7Schristos static int test_explicit_EVP_CIPHER_fetch_by_name(void)
318*66bae5e7Schristos {
319*66bae5e7Schristos     return test_explicit_EVP_CIPHER_fetch("AES-128-CBC");
320*66bae5e7Schristos }
321*66bae5e7Schristos 
322*66bae5e7Schristos /*
323*66bae5e7Schristos  * idx 0: Allow names from OBJ_obj2txt()
324*66bae5e7Schristos  * idx 1: Force an OID in text form from OBJ_obj2txt()
325*66bae5e7Schristos  */
test_explicit_EVP_CIPHER_fetch_by_X509_ALGOR(int idx)326*66bae5e7Schristos static int test_explicit_EVP_CIPHER_fetch_by_X509_ALGOR(int idx)
327*66bae5e7Schristos {
328*66bae5e7Schristos     int ret = 0;
329*66bae5e7Schristos     X509_ALGOR *algor = make_algor(NID_aes_128_cbc);
330*66bae5e7Schristos     const ASN1_OBJECT *obj;
331*66bae5e7Schristos     char id[OSSL_MAX_NAME_SIZE];
332*66bae5e7Schristos 
333*66bae5e7Schristos     if (algor == NULL)
334*66bae5e7Schristos         return 0;
335*66bae5e7Schristos 
336*66bae5e7Schristos     X509_ALGOR_get0(&obj, NULL, NULL, algor);
337*66bae5e7Schristos     switch (idx) {
338*66bae5e7Schristos     case 0:
339*66bae5e7Schristos         if (!TEST_int_gt(OBJ_obj2txt(id, sizeof(id), obj, 0), 0))
340*66bae5e7Schristos             goto end;
341*66bae5e7Schristos         break;
342*66bae5e7Schristos     case 1:
343*66bae5e7Schristos         if (!TEST_int_gt(OBJ_obj2txt(id, sizeof(id), obj, 1), 0))
344*66bae5e7Schristos             goto end;
345*66bae5e7Schristos         break;
346*66bae5e7Schristos     }
347*66bae5e7Schristos 
348*66bae5e7Schristos     ret = test_explicit_EVP_CIPHER_fetch(id);
349*66bae5e7Schristos  end:
350*66bae5e7Schristos     X509_ALGOR_free(algor);
351*66bae5e7Schristos     return ret;
352*66bae5e7Schristos }
353*66bae5e7Schristos 
setup_tests(void)354*66bae5e7Schristos int setup_tests(void)
355*66bae5e7Schristos {
356*66bae5e7Schristos     OPTION_CHOICE o;
357*66bae5e7Schristos 
358*66bae5e7Schristos     while ((o = opt_next()) != OPT_EOF) {
359*66bae5e7Schristos         switch (o) {
360*66bae5e7Schristos         case OPT_CONFIG_FILE:
361*66bae5e7Schristos             config_file = opt_arg();
362*66bae5e7Schristos             break;
363*66bae5e7Schristos         case OPT_ALG_FETCH_TYPE:
364*66bae5e7Schristos             alg = opt_arg();
365*66bae5e7Schristos             break;
366*66bae5e7Schristos         case OPT_FETCH_PROPERTY:
367*66bae5e7Schristos             fetch_property = opt_arg();
368*66bae5e7Schristos             break;
369*66bae5e7Schristos         case OPT_FETCH_FAILURE:
370*66bae5e7Schristos             expected_fetch_result = 0;
371*66bae5e7Schristos             break;
372*66bae5e7Schristos         case OPT_USE_DEFAULTCTX:
373*66bae5e7Schristos             use_default_ctx = 1;
374*66bae5e7Schristos             break;
375*66bae5e7Schristos         case OPT_TEST_CASES:
376*66bae5e7Schristos            break;
377*66bae5e7Schristos         default:
378*66bae5e7Schristos         case OPT_ERR:
379*66bae5e7Schristos             return 0;
380*66bae5e7Schristos         }
381*66bae5e7Schristos     }
382*66bae5e7Schristos     if (strcmp(alg, "digest") == 0) {
383*66bae5e7Schristos         ADD_TEST(test_implicit_EVP_MD_fetch);
384*66bae5e7Schristos         ADD_TEST(test_explicit_EVP_MD_fetch_by_name);
385*66bae5e7Schristos         ADD_ALL_TESTS_NOSUBTEST(test_explicit_EVP_MD_fetch_by_X509_ALGOR, 2);
386*66bae5e7Schristos     } else {
387*66bae5e7Schristos         ADD_TEST(test_implicit_EVP_CIPHER_fetch);
388*66bae5e7Schristos         ADD_TEST(test_explicit_EVP_CIPHER_fetch_by_name);
389*66bae5e7Schristos         ADD_ALL_TESTS_NOSUBTEST(test_explicit_EVP_CIPHER_fetch_by_X509_ALGOR, 2);
390*66bae5e7Schristos     }
391*66bae5e7Schristos     return 1;
392*66bae5e7Schristos }
393