2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 * These tests are setup to load null into the default library context.
13 * Any tests are expected to use the created 'libctx' to find algorithms.
14 * The framework runs the tests twice using the 'default' provider or
15 * 'fips' provider as inputs.
19 * DSA/DH low level APIs are deprecated for public use, but still ok for
22 #include "internal/deprecated.h"
23 #include <openssl/evp.h>
24 #include <openssl/provider.h>
25 #include <openssl/dsa.h>
26 #include <openssl/dh.h>
27 #include <openssl/safestack.h>
28 #include <openssl/x509.h>
30 #include "internal/nelem.h"
31 #include "crypto/bn_dh.h" /* _bignum_ffdhe2048_p */
32 #include "../e_os.h" /* strcasecmp */
34 static OPENSSL_CTX *libctx = NULL;
35 static OSSL_PROVIDER *nullprov = NULL;
36 static OSSL_PROVIDER *libprov = NULL;
37 static STACK_OF(OPENSSL_CSTRING) *cipher_names = NULL;
39 typedef enum OPTION_choice {
47 const OPTIONS *test_get_options(void)
49 static const OPTIONS test_options[] = {
50 OPT_TEST_OPTIONS_DEFAULT_USAGE,
51 { "config", OPT_CONFIG_FILE, '<',
52 "The configuration file to use for the libctx" },
53 { "provider", OPT_PROVIDER_NAME, 's',
54 "The provider to load (The default value is 'default'" },
61 static const char *getname(int id)
63 const char *name[] = {"p", "q", "g" };
65 if (id >= 0 && id < 3)
72 * We're using some DH specific values in this test, so we skip compilation if
73 * we're in a no-dh build.
75 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DH)
77 static int test_dsa_param_keygen(int tstid)
81 EVP_PKEY_CTX *gen_ctx = NULL;
82 EVP_PKEY *pkey_parm = NULL;
83 EVP_PKEY *pkey = NULL;
86 BIGNUM *p = NULL, *q = NULL, *g = NULL;
89 * Just grab some fixed dh p, q, g values for testing,
90 * these 'safe primes' should not be used normally for dsa *.
92 static const BIGNUM *bn[] = {
93 &_bignum_dh2048_256_p, &_bignum_dh2048_256_q, &_bignum_dh2048_256_g
97 * These tests are using bad values for p, q, g by reusing the values.
98 * A value of 0 uses p, 1 uses q and 2 uses g.
99 * There are 27 different combinations, with only the 1 valid combination.
102 qind = (tstid / 3) % 3;
104 expected = (pind == 0 && qind == 1 && gind == 2);
106 TEST_note("Testing with (p, q, g) = (%s, %s, %s)\n", getname(pind),
107 getname(qind), getname(gind));
109 if (!TEST_ptr(pkey_parm = EVP_PKEY_new())
110 || !TEST_ptr(dsa = DSA_new())
111 || !TEST_ptr(p = BN_dup(bn[pind]))
112 || !TEST_ptr(q = BN_dup(bn[qind]))
113 || !TEST_ptr(g = BN_dup(bn[gind]))
114 || !TEST_true(DSA_set0_pqg(dsa, p, q, g)))
118 if (!TEST_true(EVP_PKEY_assign_DSA(pkey_parm, dsa)))
122 if (!TEST_ptr(gen_ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey_parm, NULL))
123 || !TEST_int_gt(EVP_PKEY_keygen_init(gen_ctx), 0)
124 || !TEST_int_eq(EVP_PKEY_keygen(gen_ctx, &pkey), expected))
129 EVP_PKEY_CTX_free(gen_ctx);
130 EVP_PKEY_free(pkey_parm);
137 #endif /* OPENSSL_NO_DSA */
139 #ifndef OPENSSL_NO_DH
140 static int do_dh_param_keygen(int tstid, const BIGNUM **bn)
144 EVP_PKEY_CTX *gen_ctx = NULL;
145 EVP_PKEY *pkey_parm = NULL;
146 EVP_PKEY *pkey = NULL;
148 int pind, qind, gind;
149 BIGNUM *p = NULL, *q = NULL, *g = NULL;
152 * These tests are using bad values for p, q, g by reusing the values.
153 * A value of 0 uses p, 1 uses q and 2 uses g.
154 * There are 27 different combinations, with only the 1 valid combination.
157 qind = (tstid / 3) % 3;
159 expected = (pind == 0 && qind == 1 && gind == 2);
161 TEST_note("Testing with (p, q, g) = (%s, %s, %s)", getname(pind),
162 getname(qind), getname(gind));
164 if (!TEST_ptr(pkey_parm = EVP_PKEY_new())
165 || !TEST_ptr(dh = DH_new())
166 || !TEST_ptr(p = BN_dup(bn[pind]))
167 || !TEST_ptr(q = BN_dup(bn[qind]))
168 || !TEST_ptr(g = BN_dup(bn[gind]))
169 || !TEST_true(DH_set0_pqg(dh, p, q, g)))
173 if (!TEST_true(EVP_PKEY_assign_DH(pkey_parm, dh)))
177 if (!TEST_ptr(gen_ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey_parm, NULL))
178 || !TEST_int_gt(EVP_PKEY_keygen_init(gen_ctx), 0)
179 || !TEST_int_eq(EVP_PKEY_keygen(gen_ctx, &pkey), expected))
184 EVP_PKEY_CTX_free(gen_ctx);
185 EVP_PKEY_free(pkey_parm);
194 * Note that we get the fips186-4 path being run for most of these cases since
195 * the internal code will detect that the p, q, g does not match a safe prime
196 * group (Except for when tstid = 5, which sets the correct p, q, g)
198 static int test_dh_safeprime_param_keygen(int tstid)
200 static const BIGNUM *bn[] = {
201 &_bignum_ffdhe2048_p, &_bignum_ffdhe2048_q, &_bignum_const_2
203 return do_dh_param_keygen(tstid, bn);
206 static int dhx_cert_load(void)
212 static const unsigned char dhx_cert[] = {
213 0x30,0x82,0x03,0xff,0x30,0x82,0x02,0xe7,0xa0,0x03,0x02,0x01,0x02,0x02,0x09,0x00,
214 0xdb,0xf5,0x4d,0x22,0xa0,0x7a,0x67,0xa6,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,
215 0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x44,0x31,0x0b,0x30,0x09,0x06,0x03,0x55,
216 0x04,0x06,0x13,0x02,0x55,0x4b,0x31,0x16,0x30,0x14,0x06,0x03,0x55,0x04,0x0a,0x0c,
217 0x0d,0x4f,0x70,0x65,0x6e,0x53,0x53,0x4c,0x20,0x47,0x72,0x6f,0x75,0x70,0x31,0x1d,
218 0x30,0x1b,0x06,0x03,0x55,0x04,0x03,0x0c,0x14,0x54,0x65,0x73,0x74,0x20,0x53,0x2f,
219 0x4d,0x49,0x4d,0x45,0x20,0x52,0x53,0x41,0x20,0x52,0x6f,0x6f,0x74,0x30,0x1e,0x17,
220 0x0d,0x31,0x33,0x30,0x38,0x30,0x32,0x31,0x34,0x34,0x39,0x32,0x39,0x5a,0x17,0x0d,
221 0x32,0x33,0x30,0x36,0x31,0x31,0x31,0x34,0x34,0x39,0x32,0x39,0x5a,0x30,0x44,0x31,
222 0x0b,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x4b,0x31,0x16,0x30,0x14,
223 0x06,0x03,0x55,0x04,0x0a,0x0c,0x0d,0x4f,0x70,0x65,0x6e,0x53,0x53,0x4c,0x20,0x47,
224 0x72,0x6f,0x75,0x70,0x31,0x1d,0x30,0x1b,0x06,0x03,0x55,0x04,0x03,0x0c,0x14,0x54,
225 0x65,0x73,0x74,0x20,0x53,0x2f,0x4d,0x49,0x4d,0x45,0x20,0x45,0x45,0x20,0x44,0x48,
226 0x20,0x23,0x31,0x30,0x82,0x01,0xb6,0x30,0x82,0x01,0x2b,0x06,0x07,0x2a,0x86,0x48,
227 0xce,0x3e,0x02,0x01,0x30,0x82,0x01,0x1e,0x02,0x81,0x81,0x00,0xd4,0x0c,0x4a,0x0c,
228 0x04,0x72,0x71,0x19,0xdf,0x59,0x19,0xc5,0xaf,0x44,0x7f,0xca,0x8e,0x2b,0xf0,0x09,
229 0xf5,0xd3,0x25,0xb1,0x73,0x16,0x55,0x89,0xdf,0xfd,0x07,0xaf,0x19,0xd3,0x7f,0xd0,
230 0x07,0xa2,0xfe,0x3f,0x5a,0xf1,0x01,0xc6,0xf8,0x2b,0xef,0x4e,0x6d,0x03,0x38,0x42,
231 0xa1,0x37,0xd4,0x14,0xb4,0x00,0x4a,0xb1,0x86,0x5a,0x83,0xce,0xb9,0x08,0x0e,0xc1,
232 0x99,0x27,0x47,0x8d,0x0b,0x85,0xa8,0x82,0xed,0xcc,0x0d,0xb9,0xb0,0x32,0x7e,0xdf,
233 0xe8,0xe4,0xf6,0xf6,0xec,0xb3,0xee,0x7a,0x11,0x34,0x65,0x97,0xfc,0x1a,0xb0,0x95,
234 0x4b,0x19,0xb9,0xa6,0x1c,0xd9,0x01,0x32,0xf7,0x35,0x7c,0x2d,0x5d,0xfe,0xc1,0x85,
235 0x70,0x49,0xf8,0xcc,0x99,0xd0,0xbe,0xf1,0x5a,0x78,0xc8,0x03,0x02,0x81,0x80,0x69,
236 0x00,0xfd,0x66,0xf2,0xfc,0x15,0x8b,0x09,0xb8,0xdc,0x4d,0xea,0xaa,0x79,0x55,0xf9,
237 0xdf,0x46,0xa6,0x2f,0xca,0x2d,0x8f,0x59,0x2a,0xad,0x44,0xa3,0xc6,0x18,0x2f,0x95,
238 0xb6,0x16,0x20,0xe3,0xd3,0xd1,0x8f,0x03,0xce,0x71,0x7c,0xef,0x3a,0xc7,0x44,0x39,
239 0x0e,0xe2,0x1f,0xd8,0xd3,0x89,0x2b,0xe7,0x51,0xdc,0x12,0x48,0x4c,0x18,0x4d,0x99,
240 0x12,0x06,0xe4,0x17,0x02,0x03,0x8c,0x24,0x05,0x8e,0xa6,0x85,0xf2,0x69,0x1b,0xe1,
241 0x6a,0xdc,0xe2,0x04,0x3a,0x01,0x9d,0x64,0xbe,0xfe,0x45,0xf9,0x44,0x18,0x71,0xbd,
242 0x2d,0x3e,0x7a,0x6f,0x72,0x7d,0x1a,0x80,0x42,0x57,0xae,0x18,0x6f,0x91,0xd6,0x61,
243 0x03,0x8a,0x1c,0x89,0x73,0xc7,0x56,0x41,0x03,0xd3,0xf8,0xed,0x65,0xe2,0x85,0x02,
244 0x15,0x00,0x89,0x94,0xab,0x10,0x67,0x45,0x41,0xad,0x63,0xc6,0x71,0x40,0x8d,0x6b,
245 0x9e,0x19,0x5b,0xa4,0xc7,0xf5,0x03,0x81,0x84,0x00,0x02,0x81,0x80,0x2f,0x5b,0xde,
246 0x72,0x02,0x36,0x6b,0x00,0x5e,0x24,0x7f,0x14,0x2c,0x18,0x52,0x42,0x97,0x4b,0xdb,
247 0x6e,0x15,0x50,0x3c,0x45,0x3e,0x25,0xf3,0xb7,0xc5,0x6e,0xe5,0x52,0xe7,0xc4,0xfb,
248 0xf4,0xa5,0xf0,0x39,0x12,0x7f,0xbc,0x54,0x1c,0x93,0xb9,0x5e,0xee,0xe9,0x14,0xb0,
249 0xdf,0xfe,0xfc,0x36,0xe4,0xf2,0xaf,0xfb,0x13,0xc8,0xdf,0x18,0x94,0x1d,0x40,0xb9,
250 0x71,0xdd,0x4c,0x9c,0xa7,0x03,0x52,0x02,0xb5,0xed,0x71,0x80,0x3e,0x23,0xda,0x28,
251 0xe5,0xab,0xe7,0x6f,0xf2,0x0a,0x0e,0x00,0x5b,0x7d,0xc6,0x4b,0xd7,0xc7,0xb2,0xc3,
252 0xba,0x62,0x7f,0x70,0x28,0xa0,0x9d,0x71,0x13,0x70,0xd1,0x9f,0x32,0x2f,0x3e,0xd2,
253 0xcd,0x1b,0xa4,0xc6,0x72,0xa0,0x74,0x5d,0x71,0xef,0x03,0x43,0x6e,0xa3,0x60,0x30,
254 0x5e,0x30,0x0c,0x06,0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x02,0x30,0x00,0x30,
255 0x0e,0x06,0x03,0x55,0x1d,0x0f,0x01,0x01,0xff,0x04,0x04,0x03,0x02,0x05,0xe0,0x30,
256 0x1d,0x06,0x03,0x55,0x1d,0x0e,0x04,0x16,0x04,0x14,0x0b,0x5a,0x4d,0x5f,0x7d,0x25,
257 0xc7,0xf2,0x9d,0xc1,0xaa,0xb7,0x63,0x82,0x2f,0xfa,0x8f,0x32,0xe7,0xc0,0x30,0x1f,
258 0x06,0x03,0x55,0x1d,0x23,0x04,0x18,0x30,0x16,0x80,0x14,0xdf,0x7e,0x5e,0x88,0x05,
259 0x24,0x33,0x08,0xdd,0x22,0x81,0x02,0x97,0xcc,0x9a,0xb7,0xb1,0x33,0x27,0x30,0x30,
260 0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x03,0x82,
261 0x01,0x01,0x00,0x5a,0xf2,0x63,0xef,0xd3,0x16,0xd7,0xf5,0xaa,0xdd,0x12,0x00,0x36,
262 0x00,0x21,0xa2,0x7b,0x08,0xd6,0x3b,0x9f,0x62,0xac,0x53,0x1f,0xed,0x4c,0xd1,0x15,
263 0x34,0x65,0x71,0xee,0x96,0x07,0xa6,0xef,0xb2,0xde,0xd8,0xbb,0x35,0x6e,0x2c,0xe2,
264 0xd1,0x26,0xef,0x7e,0x94,0xe2,0x88,0x51,0xa4,0x6c,0xaa,0x27,0x2a,0xd3,0xb6,0xc2,
265 0xf7,0xea,0xc3,0x0b,0xa9,0xb5,0x28,0x37,0xa2,0x63,0x08,0xe4,0x88,0xc0,0x1b,0x16,
266 0x1b,0xca,0xfd,0x8a,0x07,0x32,0x29,0xa7,0x53,0xb5,0x2d,0x30,0xe4,0xf5,0x16,0xc3,
267 0xe3,0xc2,0x4c,0x30,0x5d,0x35,0x80,0x1c,0xa2,0xdb,0xe3,0x4b,0x51,0x0d,0x4c,0x60,
268 0x5f,0xb9,0x46,0xac,0xa8,0x46,0xa7,0x32,0xa7,0x9c,0x76,0xf8,0xe9,0xb5,0x19,0xe2,
269 0x0c,0xe1,0x0f,0xc6,0x46,0xe2,0x38,0xa7,0x87,0x72,0x6d,0x6c,0xbc,0x88,0x2f,0x9d,
270 0x2d,0xe5,0xd0,0x7d,0x1e,0xc7,0x5d,0xf8,0x7e,0xb4,0x0b,0xa6,0xf9,0x6c,0xe3,0x7c,
271 0xb2,0x70,0x6e,0x75,0x9b,0x1e,0x63,0xe1,0x4d,0xb2,0x81,0xd3,0x55,0x38,0x94,0x1a,
272 0x7a,0xfa,0xbf,0x01,0x18,0x70,0x2d,0x35,0xd3,0xe3,0x10,0x7a,0x9a,0xa7,0x8f,0xf3,
273 0xbd,0x56,0x55,0x5e,0xd8,0xbd,0x4e,0x16,0x76,0xd0,0x48,0x4c,0xf9,0x51,0x54,0xdf,
274 0x2d,0xb0,0xc9,0xaa,0x5e,0x42,0x38,0x50,0xbf,0x0f,0xc0,0xd9,0x84,0x44,0x4b,0x42,
275 0x24,0xec,0x14,0xa3,0xde,0x11,0xdf,0x58,0x7f,0xc2,0x4d,0xb2,0xd5,0x42,0x78,0x6e,
276 0x52,0x3e,0xad,0xc3,0x5f,0x04,0xc4,0xe6,0x31,0xaa,0x81,0x06,0x8b,0x13,0x4b,0x3c,
280 if (!TEST_ptr(bio = BIO_new_mem_buf(dhx_cert, sizeof(dhx_cert)))
281 || !TEST_ptr(cert = X509_new_with_libctx(libctx, NULL))
282 || !TEST_ptr(d2i_X509_bio(bio, &cert)))
291 #endif /* OPENSSL_NO_DH */
293 static int test_cipher_reinit(int test_id)
295 int ret = 0, out1_len = 0, out2_len = 0, diff, ccm;
296 EVP_CIPHER *cipher = NULL;
297 EVP_CIPHER_CTX *ctx = NULL;
298 unsigned char out1[256];
299 unsigned char out2[256];
300 unsigned char in[16] = {
301 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
302 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10
304 unsigned char key[64] = {
305 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
306 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
307 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
308 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
309 0x02, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
310 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
311 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
312 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
314 unsigned char iv[16] = {
315 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
316 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00
318 const char *name = sk_OPENSSL_CSTRING_value(cipher_names, test_id);
320 if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
323 TEST_note("Fetching %s\n", name);
324 if (!TEST_ptr(cipher = EVP_CIPHER_fetch(libctx, name, NULL)))
327 /* ccm fails on the second update - this matches OpenSSL 1_1_1 behaviour */
328 ccm = (EVP_CIPHER_mode(cipher) == EVP_CIPH_CCM_MODE);
330 /* DES3-WRAP uses random every update - so it will give a different value */
331 diff = EVP_CIPHER_is_a(cipher, "DES3-WRAP");
333 if (!TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv))
334 || !TEST_true(EVP_EncryptUpdate(ctx, out1, &out1_len, in, sizeof(in)))
335 || !TEST_true(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv))
336 || !TEST_int_eq(EVP_EncryptUpdate(ctx, out2, &out2_len, in, sizeof(in)),
342 if (!TEST_mem_ne(out1, out1_len, out2, out2_len))
345 if (!TEST_mem_eq(out1, out1_len, out2, out2_len))
351 EVP_CIPHER_free(cipher);
352 EVP_CIPHER_CTX_free(ctx);
357 * This test only uses a partial block (half the block size) of input for each
358 * EVP_EncryptUpdate() in order to test that the second init/update is not using
359 * a leftover buffer from the first init/update.
360 * Note: some ciphers don't need a full block to produce output.
362 static int test_cipher_reinit_partialupdate(int test_id)
364 int ret = 0, out1_len = 0, out2_len = 0, in_len;
365 EVP_CIPHER *cipher = NULL;
366 EVP_CIPHER_CTX *ctx = NULL;
367 unsigned char out1[256];
368 unsigned char out2[256];
369 static const unsigned char in[32] = {
370 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
371 0xba, 0xbe, 0xba, 0xbe, 0x00, 0x00, 0xba, 0xbe,
372 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
373 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
375 static const unsigned char key[64] = {
376 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
377 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
378 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
379 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
380 0x02, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
381 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
382 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
383 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
385 static const unsigned char iv[16] = {
386 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
387 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00
389 const char *name = sk_OPENSSL_CSTRING_value(cipher_names, test_id);
391 if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
394 TEST_note("Fetching %s\n", name);
395 if (!TEST_ptr(cipher = EVP_CIPHER_fetch(libctx, name, NULL)))
398 in_len = EVP_CIPHER_block_size(cipher) / 2;
400 /* skip any ciphers that don't allow partial updates */
401 if (((EVP_CIPHER_flags(cipher)
402 & (EVP_CIPH_FLAG_CTS | EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) != 0)
403 || EVP_CIPHER_mode(cipher) == EVP_CIPH_CCM_MODE
404 || EVP_CIPHER_mode(cipher) == EVP_CIPH_XTS_MODE
405 || EVP_CIPHER_mode(cipher) == EVP_CIPH_WRAP_MODE) {
410 if (!TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv))
411 || !TEST_true(EVP_EncryptUpdate(ctx, out1, &out1_len, in, in_len))
412 || !TEST_true(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv))
413 || !TEST_true(EVP_EncryptUpdate(ctx, out2, &out2_len, in, in_len)))
416 /* DES3-WRAP uses random every update - so it will give a different value */
417 if (EVP_CIPHER_is_a(cipher, "DES3-WRAP")) {
418 if (!TEST_mem_ne(out1, out1_len, out2, out2_len))
421 if (!TEST_mem_eq(out1, out1_len, out2, out2_len))
426 EVP_CIPHER_free(cipher);
427 EVP_CIPHER_CTX_free(ctx);
432 static int name_cmp(const char * const *a, const char * const *b)
434 return strcasecmp(*a, *b);
437 static void collect_cipher_names(EVP_CIPHER *cipher, void *cipher_names_list)
439 STACK_OF(OPENSSL_CSTRING) *names = cipher_names_list;
441 sk_OPENSSL_CSTRING_push(names, EVP_CIPHER_name(cipher));
444 int setup_tests(void)
446 const char *prov_name = "default";
447 char *config_file = NULL;
450 while ((o = opt_next()) != OPT_EOF) {
452 case OPT_PROVIDER_NAME:
453 prov_name = opt_arg();
455 case OPT_CONFIG_FILE:
456 config_file = opt_arg();
466 nullprov = OSSL_PROVIDER_load(NULL, "null");
467 if (!TEST_ptr(nullprov))
470 libctx = OPENSSL_CTX_new();
472 if (!TEST_ptr(libctx))
475 if (config_file != NULL) {
476 if (!TEST_true(OPENSSL_CTX_load_config(libctx, config_file)))
480 libprov = OSSL_PROVIDER_load(libctx, prov_name);
481 if (!TEST_ptr(libprov))
484 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DH)
485 ADD_ALL_TESTS(test_dsa_param_keygen, 3 * 3 * 3);
487 #ifndef OPENSSL_NO_DH
488 ADD_ALL_TESTS(test_dh_safeprime_param_keygen, 3 * 3 * 3);
489 ADD_TEST(dhx_cert_load);
492 if (!TEST_ptr(cipher_names = sk_OPENSSL_CSTRING_new(name_cmp)))
494 EVP_CIPHER_do_all_provided(libctx, collect_cipher_names, cipher_names);
496 ADD_ALL_TESTS(test_cipher_reinit, sk_OPENSSL_CSTRING_num(cipher_names));
497 ADD_ALL_TESTS(test_cipher_reinit_partialupdate,
498 sk_OPENSSL_CSTRING_num(cipher_names));
502 void cleanup_tests(void)
504 sk_OPENSSL_CSTRING_free(cipher_names);
505 OSSL_PROVIDER_unload(libprov);
506 OPENSSL_CTX_free(libctx);
507 OSSL_PROVIDER_unload(nullprov);