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