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
11 #include <openssl/core_dispatch.h>
12 #include <openssl/evp.h>
13 #include <openssl/pem.h>
14 #include <openssl/rsa.h>
15 #include <openssl/x509.h>
16 #include <openssl/core_names.h>
17 #include <openssl/params.h>
18 #include <openssl/param_build.h>
19 #include <openssl/encoder.h>
20 #include <openssl/decoder.h>
22 #include "internal/pem.h" /* For PVK and "blob" PEM headers */
23 #include "internal/cryptlib.h" /* ossl_assert */
28 static BN_CTX
*bnctx
= NULL
;
29 static OSSL_PARAM_BLD
*bld_prime_nc
= NULL
;
30 static OSSL_PARAM_BLD
*bld_prime
= NULL
;
31 static OSSL_PARAM
*ec_explicit_prime_params_nc
= NULL
;
32 static OSSL_PARAM
*ec_explicit_prime_params_explicit
= NULL
;
34 # ifndef OPENSSL_NO_EC2M
35 static OSSL_PARAM_BLD
*bld_tri_nc
= NULL
;
36 static OSSL_PARAM_BLD
*bld_tri
= NULL
;
37 static OSSL_PARAM
*ec_explicit_tri_params_nc
= NULL
;
38 static OSSL_PARAM
*ec_explicit_tri_params_explicit
= NULL
;
42 static EVP_PKEY
*make_template(const char *type
, OSSL_PARAM
*genparams
)
44 EVP_PKEY
*pkey
= NULL
;
45 EVP_PKEY_CTX
*ctx
= EVP_PKEY_CTX_new_from_name(NULL
, type
, NULL
);
48 * No real need to check the errors other than for the cascade
49 * effect. |pkey| will simply remain NULL if something goes wrong.
52 && EVP_PKEY_paramgen_init(ctx
) > 0
54 || EVP_PKEY_CTX_set_params(ctx
, genparams
) > 0)
55 && EVP_PKEY_gen(ctx
, &pkey
) > 0);
56 EVP_PKEY_CTX_free(ctx
);
61 static EVP_PKEY
*make_key(const char *type
, EVP_PKEY
*template,
62 OSSL_PARAM
*genparams
)
64 EVP_PKEY
*pkey
= NULL
;
67 ? EVP_PKEY_CTX_new(template, NULL
)
68 : EVP_PKEY_CTX_new_from_name(NULL
, type
, NULL
);
71 * No real need to check the errors other than for the cascade
72 * effect. |pkey| will simply remain NULL if something goes wrong.
75 && EVP_PKEY_keygen_init(ctx
) > 0
77 || EVP_PKEY_CTX_set_params(ctx
, genparams
) > 0)
78 && EVP_PKEY_keygen(ctx
, &pkey
) > 0);
79 EVP_PKEY_CTX_free(ctx
);
83 /* Main test driver */
86 * TODO(3.0) For better error output, changed the callbacks to take __FILE__
87 * and __LINE__ as first two arguments, and have them use the lower case
88 * functions, such as test_strn_eq(), rather than the uppercase macros
89 * (TEST_strn2_eq(), for example).
92 typedef int (encoder
)(void **encoded
, long *encoded_len
, void *object
,
93 const char *output_type
, int selection
,
94 const char *pass
, const char *pcipher
);
95 typedef int (decoder
)(void **object
, void *encoded
, long encoded_len
,
97 typedef int (tester
)(const void *data1
, size_t data1_len
,
98 const void *data2
, size_t data2_len
);
99 typedef int (checker
)(const char *type
, const void *data
, size_t data_len
);
100 typedef void (dumper
)(const char *label
, const void *data
, size_t data_len
);
102 static int test_encode_decode(const char *type
, EVP_PKEY
*pkey
,
103 const char *output_type
, int selection
,
104 const char *pass
, const char *pcipher
,
105 encoder
*encode_cb
, decoder
*decode_cb
,
106 tester
*test_cb
, checker
*check_cb
,
109 void *encoded
= NULL
;
110 long encoded_len
= 0;
111 EVP_PKEY
*pkey2
= NULL
;
112 void *encoded2
= NULL
;
113 long encoded2_len
= 0;
117 * Encode |pkey|, decode the result into |pkey2|, and finish off by
118 * encoding |pkey2| as well. That last encoding is for checking and
121 if (!encode_cb(&encoded
, &encoded_len
, pkey
, output_type
, selection
,
123 || !check_cb(type
, encoded
, encoded_len
)
124 || !decode_cb((void **)&pkey2
, encoded
, encoded_len
, pass
)
125 || !encode_cb(&encoded2
, &encoded2_len
, pkey2
, output_type
, selection
,
129 if (!TEST_int_eq(EVP_PKEY_eq(pkey
, pkey2
), 1))
133 * Double check the encoding, but only for unprotected keys,
134 * as protected keys have a random component, which makes the output
137 if ((pass
== NULL
&& pcipher
== NULL
)
138 && !test_cb(encoded
, encoded_len
, encoded2
, encoded2_len
))
144 if (encoded
!= NULL
&& encoded_len
!= 0)
145 dump_cb("|pkey| encoded", encoded
, encoded_len
);
146 if (encoded2
!= NULL
&& encoded2_len
!= 0)
147 dump_cb("|pkey2| encoded", encoded2
, encoded2_len
);
150 OPENSSL_free(encoded
);
151 OPENSSL_free(encoded2
);
152 EVP_PKEY_free(pkey2
);
156 /* Encoding and desencoding methods */
158 static int encode_EVP_PKEY_prov(void **encoded
, long *encoded_len
,
160 const char *output_type
, int selection
,
161 const char *pass
, const char *pcipher
)
163 EVP_PKEY
*pkey
= object
;
164 OSSL_ENCODER_CTX
*ectx
= NULL
;
166 BUF_MEM
*mem_buf
= NULL
;
167 const unsigned char *upass
= (const unsigned char *)pass
;
170 if (!TEST_ptr(ectx
= OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey
, output_type
,
174 && !TEST_true(OSSL_ENCODER_CTX_set_passphrase(ectx
, upass
,
177 && !TEST_true(OSSL_ENCODER_CTX_set_cipher(ectx
, pcipher
, NULL
)))
178 || !TEST_ptr(mem_ser
= BIO_new(BIO_s_mem()))
179 || !TEST_true(OSSL_ENCODER_to_bio(ectx
, mem_ser
))
180 || !TEST_true(BIO_get_mem_ptr(mem_ser
, &mem_buf
) > 0)
181 || !TEST_ptr(*encoded
= mem_buf
->data
)
182 || !TEST_long_gt(*encoded_len
= mem_buf
->length
, 0))
185 /* Detach the encoded output */
186 mem_buf
->data
= NULL
;
191 OSSL_ENCODER_CTX_free(ectx
);
195 static int decode_EVP_PKEY_prov(void **object
, void *encoded
, long encoded_len
,
198 EVP_PKEY
*pkey
= NULL
;
199 OSSL_DECODER_CTX
*dctx
= NULL
;
200 BIO
*mem_deser
= NULL
;
201 const unsigned char *upass
= (const unsigned char *)pass
;
204 if (!TEST_ptr(dctx
= OSSL_DECODER_CTX_new_by_EVP_PKEY(&pkey
, NULL
,
207 && !OSSL_DECODER_CTX_set_passphrase(dctx
, upass
, strlen(pass
)))
208 || !TEST_ptr(mem_deser
= BIO_new_mem_buf(encoded
, encoded_len
))
209 || !TEST_true(OSSL_DECODER_from_bio(dctx
, mem_deser
)))
215 OSSL_DECODER_CTX_free(dctx
);
219 static int encode_EVP_PKEY_legacy_PEM(void **encoded
, long *encoded_len
,
221 const char *output_type
, int selection
,
222 const char *pass
, const char *pcipher
)
224 EVP_PKEY
*pkey
= object
;
225 EVP_CIPHER
*cipher
= NULL
;
227 BUF_MEM
*mem_buf
= NULL
;
228 const unsigned char *upass
= (const unsigned char *)pass
;
232 if (pcipher
!= NULL
&& pass
!= NULL
) {
233 passlen
= strlen(pass
);
234 if (!TEST_ptr(cipher
= EVP_CIPHER_fetch(NULL
, pcipher
, NULL
)))
237 if (!TEST_ptr(mem_ser
= BIO_new(BIO_s_mem()))
238 || !TEST_true(PEM_write_bio_PrivateKey_traditional(mem_ser
, pkey
,
242 || !TEST_true(BIO_get_mem_ptr(mem_ser
, &mem_buf
) > 0)
243 || !TEST_ptr(*encoded
= mem_buf
->data
)
244 || !TEST_long_gt(*encoded_len
= mem_buf
->length
, 0))
247 /* Detach the encoded output */
248 mem_buf
->data
= NULL
;
253 EVP_CIPHER_free(cipher
);
257 #ifndef OPENSSL_NO_DSA
258 static int encode_EVP_PKEY_MSBLOB(void **encoded
, long *encoded_len
,
260 ossl_unused
const char *output_type
,
261 ossl_unused
int selection
,
262 ossl_unused
const char *pass
,
263 ossl_unused
const char *pcipher
)
265 EVP_PKEY
*pkey
= object
;
267 BUF_MEM
*mem_buf
= NULL
;
270 if (!TEST_ptr(mem_ser
= BIO_new(BIO_s_mem()))
271 || !TEST_int_ge(i2b_PrivateKey_bio(mem_ser
, pkey
), 0)
272 || !TEST_true(BIO_get_mem_ptr(mem_ser
, &mem_buf
) > 0)
273 || !TEST_ptr(*encoded
= mem_buf
->data
)
274 || !TEST_long_gt(*encoded_len
= mem_buf
->length
, 0))
277 /* Detach the encoded output */
278 mem_buf
->data
= NULL
;
286 static int encode_public_EVP_PKEY_MSBLOB(void **encoded
,
289 ossl_unused
const char *output_type
,
290 ossl_unused
int selection
,
291 ossl_unused
const char *pass
,
292 ossl_unused
const char *pcipher
)
294 EVP_PKEY
*pkey
= object
;
296 BUF_MEM
*mem_buf
= NULL
;
299 if (!TEST_ptr(mem_ser
= BIO_new(BIO_s_mem()))
300 || !TEST_int_ge(i2b_PublicKey_bio(mem_ser
, pkey
), 0)
301 || !TEST_true(BIO_get_mem_ptr(mem_ser
, &mem_buf
) > 0)
302 || !TEST_ptr(*encoded
= mem_buf
->data
)
303 || !TEST_long_gt(*encoded_len
= mem_buf
->length
, 0))
306 /* Detach the encoded output */
307 mem_buf
->data
= NULL
;
315 # ifndef OPENSSL_NO_RC4
316 static pem_password_cb pass_pw
;
317 static int pass_pw(char *buf
, int size
, int rwflag
, void *userdata
)
319 OPENSSL_strlcpy(buf
, userdata
, size
);
320 return strlen(userdata
);
323 static int encode_EVP_PKEY_PVK(void **encoded
, long *encoded_len
,
325 ossl_unused
const char *output_type
,
326 ossl_unused
int selection
,
328 ossl_unused
const char *pcipher
)
330 EVP_PKEY
*pkey
= object
;
332 BUF_MEM
*mem_buf
= NULL
;
333 int enc
= (pass
!= NULL
);
336 if (!TEST_ptr(mem_ser
= BIO_new(BIO_s_mem()))
337 || !TEST_int_ge(i2b_PVK_bio(mem_ser
, pkey
, enc
,
338 pass_pw
, (void *)pass
), 0)
339 || !TEST_true(BIO_get_mem_ptr(mem_ser
, &mem_buf
) > 0)
340 || !TEST_ptr(*encoded
= mem_buf
->data
)
341 || !TEST_long_gt(*encoded_len
= mem_buf
->length
, 0))
344 /* Detach the encoded output */
345 mem_buf
->data
= NULL
;
355 static int test_text(const void *data1
, size_t data1_len
,
356 const void *data2
, size_t data2_len
)
358 return TEST_strn2_eq(data1
, data1_len
, data2
, data2_len
);
361 static int test_mem(const void *data1
, size_t data1_len
,
362 const void *data2
, size_t data2_len
)
364 return TEST_mem_eq(data1
, data1_len
, data2
, data2_len
);
367 /* Test cases and their dumpers / checkers */
369 static void collect_name(const char *name
, void *arg
)
371 char **namelist
= arg
;
375 space
= strlen(name
);
376 if (*namelist
!= NULL
)
377 space
+= strlen(*namelist
) + 2 /* for comma and space */;
378 space
++; /* for terminating null byte */
380 new_namelist
= OPENSSL_realloc(*namelist
, space
);
381 if (new_namelist
== NULL
)
383 if (*namelist
!= NULL
) {
384 strcat(new_namelist
, ", ");
385 strcat(new_namelist
, name
);
387 strcpy(new_namelist
, name
);
389 *namelist
= new_namelist
;
392 static void dump_der(const char *label
, const void *data
, size_t data_len
)
394 test_output_memory(label
, data
, data_len
);
397 static void dump_pem(const char *label
, const void *data
, size_t data_len
)
399 test_output_string(label
, data
, data_len
- 1);
402 static int check_unprotected_PKCS8_DER(const char *type
,
403 const void *data
, size_t data_len
)
405 const unsigned char *datap
= data
;
406 PKCS8_PRIV_KEY_INFO
*p8inf
=
407 d2i_PKCS8_PRIV_KEY_INFO(NULL
, &datap
, data_len
);
410 if (TEST_ptr(p8inf
)) {
411 EVP_PKEY
*pkey
= EVP_PKCS82PKEY(p8inf
);
412 char *namelist
= NULL
;
414 if (TEST_ptr(pkey
)) {
415 if (!(ok
= TEST_true(EVP_PKEY_is_a(pkey
, type
)))) {
416 EVP_PKEY_typenames_do_all(pkey
, collect_name
, &namelist
);
417 if (namelist
!= NULL
)
418 TEST_note("%s isn't any of %s", type
, namelist
);
419 OPENSSL_free(namelist
);
424 PKCS8_PRIV_KEY_INFO_free(p8inf
);
428 static int test_unprotected_via_DER(const char *type
, EVP_PKEY
*key
)
430 return test_encode_decode(type
, key
,
431 "DER", OSSL_KEYMGMT_SELECT_KEYPAIR
432 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
434 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
435 test_mem
, check_unprotected_PKCS8_DER
,
439 static int check_unprotected_PKCS8_PEM(const char *type
,
440 const void *data
, size_t data_len
)
442 static const char expected_pem_header
[] =
443 "-----BEGIN " PEM_STRING_PKCS8INF
"-----";
445 return TEST_strn_eq(data
, expected_pem_header
,
446 sizeof(expected_pem_header
) - 1);
449 static int test_unprotected_via_PEM(const char *type
, EVP_PKEY
*key
)
451 return test_encode_decode(type
, key
,
452 "PEM", OSSL_KEYMGMT_SELECT_KEYPAIR
453 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
455 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
456 test_text
, check_unprotected_PKCS8_PEM
,
460 static int check_unprotected_legacy_PEM(const char *type
,
461 const void *data
, size_t data_len
)
463 static char expected_pem_header
[80];
466 TEST_int_gt(BIO_snprintf(expected_pem_header
,
467 sizeof(expected_pem_header
),
468 "-----BEGIN %s PRIVATE KEY-----", type
), 0)
469 && TEST_strn_eq(data
, expected_pem_header
, strlen(expected_pem_header
));
472 static int test_unprotected_via_legacy_PEM(const char *type
, EVP_PKEY
*key
)
474 return test_encode_decode(type
, key
,
475 "PEM", OSSL_KEYMGMT_SELECT_KEYPAIR
476 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
478 encode_EVP_PKEY_legacy_PEM
, decode_EVP_PKEY_prov
,
479 test_text
, check_unprotected_legacy_PEM
,
483 #ifndef OPENSSL_NO_DSA
484 static int check_MSBLOB(const char *type
, const void *data
, size_t data_len
)
486 const unsigned char *datap
= data
;
487 EVP_PKEY
*pkey
= b2i_PrivateKey(&datap
, data_len
);
488 int ok
= TEST_ptr(pkey
);
494 static int test_unprotected_via_MSBLOB(const char *type
, EVP_PKEY
*key
)
496 return test_encode_decode(type
, key
,
497 "MSBLOB", OSSL_KEYMGMT_SELECT_KEYPAIR
498 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
500 encode_EVP_PKEY_MSBLOB
, decode_EVP_PKEY_prov
,
501 test_mem
, check_MSBLOB
,
505 # ifndef OPENSSL_NO_RC4
506 static int check_PVK(const char *type
, const void *data
, size_t data_len
)
508 const unsigned char *in
= data
;
509 unsigned int saltlen
= 0, keylen
= 0;
510 int ok
= ossl_do_PVK_header(&in
, data_len
, 0, &saltlen
, &keylen
);
515 static int test_unprotected_via_PVK(const char *type
, EVP_PKEY
*key
)
517 return test_encode_decode(type
, key
,
518 "PVK", OSSL_KEYMGMT_SELECT_KEYPAIR
519 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
521 encode_EVP_PKEY_PVK
, decode_EVP_PKEY_prov
,
528 static const char *pass_cipher
= "AES-256-CBC";
529 static const char *pass
= "the holy handgrenade of antioch";
531 static int check_protected_PKCS8_DER(const char *type
,
532 const void *data
, size_t data_len
)
534 const unsigned char *datap
= data
;
535 X509_SIG
*p8
= d2i_X509_SIG(NULL
, &datap
, data_len
);
536 int ok
= TEST_ptr(p8
);
542 static int test_protected_via_DER(const char *type
, EVP_PKEY
*key
)
544 return test_encode_decode(type
, key
,
545 "DER", OSSL_KEYMGMT_SELECT_KEYPAIR
546 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
548 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
549 test_mem
, check_protected_PKCS8_DER
,
553 static int check_protected_PKCS8_PEM(const char *type
,
554 const void *data
, size_t data_len
)
556 static const char expected_pem_header
[] =
557 "-----BEGIN " PEM_STRING_PKCS8
"-----";
559 return TEST_strn_eq(data
, expected_pem_header
,
560 sizeof(expected_pem_header
) - 1);
563 static int test_protected_via_PEM(const char *type
, EVP_PKEY
*key
)
565 return test_encode_decode(type
, key
,
566 "PEM", OSSL_KEYMGMT_SELECT_KEYPAIR
567 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
569 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
570 test_text
, check_protected_PKCS8_PEM
,
574 static int check_protected_legacy_PEM(const char *type
,
575 const void *data
, size_t data_len
)
577 static char expected_pem_header
[80];
580 TEST_int_gt(BIO_snprintf(expected_pem_header
,
581 sizeof(expected_pem_header
),
582 "-----BEGIN %s PRIVATE KEY-----", type
), 0)
583 && TEST_strn_eq(data
, expected_pem_header
, strlen(expected_pem_header
))
584 && TEST_ptr(strstr(data
, "\nDEK-Info: "));
587 static int test_protected_via_legacy_PEM(const char *type
, EVP_PKEY
*key
)
589 return test_encode_decode(type
, key
,
590 "PEM", OSSL_KEYMGMT_SELECT_KEYPAIR
591 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
593 encode_EVP_PKEY_legacy_PEM
, decode_EVP_PKEY_prov
,
594 test_text
, check_protected_legacy_PEM
,
598 #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
599 static int test_protected_via_PVK(const char *type
, EVP_PKEY
*key
)
601 return test_encode_decode(type
, key
,
602 "PVK", OSSL_KEYMGMT_SELECT_KEYPAIR
603 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
605 encode_EVP_PKEY_PVK
, decode_EVP_PKEY_prov
,
606 test_mem
, check_PVK
, dump_der
);
610 static int check_public_DER(const char *type
, const void *data
, size_t data_len
)
612 const unsigned char *datap
= data
;
613 EVP_PKEY
*pkey
= d2i_PUBKEY(NULL
, &datap
, data_len
);
614 int ok
= (TEST_ptr(pkey
) && TEST_true(EVP_PKEY_is_a(pkey
, type
)));
620 static int test_public_via_DER(const char *type
, EVP_PKEY
*key
)
622 return test_encode_decode(type
, key
,
623 "DER", OSSL_KEYMGMT_SELECT_PUBLIC_KEY
624 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
626 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
627 test_mem
, check_public_DER
, dump_der
);
630 static int check_public_PEM(const char *type
, const void *data
, size_t data_len
)
632 static const char expected_pem_header
[] =
633 "-----BEGIN " PEM_STRING_PUBLIC
"-----";
636 TEST_strn_eq(data
, expected_pem_header
,
637 sizeof(expected_pem_header
) - 1);
640 static int test_public_via_PEM(const char *type
, EVP_PKEY
*key
)
642 return test_encode_decode(type
, key
,
643 "PEM", OSSL_KEYMGMT_SELECT_PUBLIC_KEY
644 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
646 encode_EVP_PKEY_prov
, decode_EVP_PKEY_prov
,
647 test_text
, check_public_PEM
, dump_pem
);
650 #ifndef OPENSSL_NO_DSA
651 static int check_public_MSBLOB(const char *type
,
652 const void *data
, size_t data_len
)
654 const unsigned char *datap
= data
;
655 EVP_PKEY
*pkey
= b2i_PublicKey(&datap
, data_len
);
656 int ok
= TEST_ptr(pkey
);
662 static int test_public_via_MSBLOB(const char *type
, EVP_PKEY
*key
)
664 return test_encode_decode(type
, key
,
665 "MSBLOB", OSSL_KEYMGMT_SELECT_PUBLIC_KEY
666 | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS
,
668 encode_public_EVP_PKEY_MSBLOB
,
669 decode_EVP_PKEY_prov
,
670 test_mem
, check_public_MSBLOB
, dump_der
);
674 #define KEYS(KEYTYPE) \
675 static EVP_PKEY *key_##KEYTYPE = NULL
676 #define MAKE_KEYS(KEYTYPE, KEYTYPEstr, params) \
678 && TEST_ptr(key_##KEYTYPE = make_key(KEYTYPEstr, NULL, params))
679 #define FREE_KEYS(KEYTYPE) \
680 EVP_PKEY_free(key_##KEYTYPE); \
682 #define DOMAIN_KEYS(KEYTYPE) \
683 static EVP_PKEY *template_##KEYTYPE = NULL; \
684 static EVP_PKEY *key_##KEYTYPE = NULL
685 #define MAKE_DOMAIN_KEYS(KEYTYPE, KEYTYPEstr, params) \
687 && TEST_ptr(template_##KEYTYPE = \
688 make_template(KEYTYPEstr, params)) \
689 && TEST_ptr(key_##KEYTYPE = \
690 make_key(KEYTYPEstr, template_##KEYTYPE, NULL))
691 #define FREE_DOMAIN_KEYS(KEYTYPE) \
692 EVP_PKEY_free(template_##KEYTYPE); \
693 EVP_PKEY_free(key_##KEYTYPE)
695 #define IMPLEMENT_TEST_SUITE(KEYTYPE, KEYTYPEstr) \
696 static int test_unprotected_##KEYTYPE##_via_DER(void) \
698 return test_unprotected_via_DER(KEYTYPEstr, key_##KEYTYPE); \
700 static int test_unprotected_##KEYTYPE##_via_PEM(void) \
702 return test_unprotected_via_PEM(KEYTYPEstr, key_##KEYTYPE); \
704 static int test_protected_##KEYTYPE##_via_DER(void) \
706 return test_protected_via_DER(KEYTYPEstr, key_##KEYTYPE); \
708 static int test_protected_##KEYTYPE##_via_PEM(void) \
710 return test_protected_via_PEM(KEYTYPEstr, key_##KEYTYPE); \
712 static int test_public_##KEYTYPE##_via_DER(void) \
714 return test_public_via_DER(KEYTYPEstr, key_##KEYTYPE); \
716 static int test_public_##KEYTYPE##_via_PEM(void) \
718 return test_public_via_PEM(KEYTYPEstr, key_##KEYTYPE); \
721 #define ADD_TEST_SUITE(KEYTYPE) \
722 ADD_TEST(test_unprotected_##KEYTYPE##_via_DER); \
723 ADD_TEST(test_unprotected_##KEYTYPE##_via_PEM); \
724 ADD_TEST(test_protected_##KEYTYPE##_via_DER); \
725 ADD_TEST(test_protected_##KEYTYPE##_via_PEM); \
726 ADD_TEST(test_public_##KEYTYPE##_via_DER); \
727 ADD_TEST(test_public_##KEYTYPE##_via_PEM)
729 #define IMPLEMENT_TEST_SUITE_LEGACY(KEYTYPE, KEYTYPEstr) \
730 static int test_unprotected_##KEYTYPE##_via_legacy_PEM(void) \
733 test_unprotected_via_legacy_PEM(KEYTYPEstr, key_##KEYTYPE); \
735 static int test_protected_##KEYTYPE##_via_legacy_PEM(void) \
738 test_protected_via_legacy_PEM(KEYTYPEstr, key_##KEYTYPE); \
741 #define ADD_TEST_SUITE_LEGACY(KEYTYPE) \
742 ADD_TEST(test_unprotected_##KEYTYPE##_via_legacy_PEM); \
743 ADD_TEST(test_protected_##KEYTYPE##_via_legacy_PEM)
745 #ifndef OPENSSL_NO_DSA
746 # define IMPLEMENT_TEST_SUITE_MSBLOB(KEYTYPE, KEYTYPEstr) \
747 static int test_unprotected_##KEYTYPE##_via_MSBLOB(void) \
749 return test_unprotected_via_MSBLOB(KEYTYPEstr, key_##KEYTYPE); \
751 static int test_public_##KEYTYPE##_via_MSBLOB(void) \
753 return test_public_via_MSBLOB(KEYTYPEstr, key_##KEYTYPE); \
756 # define ADD_TEST_SUITE_MSBLOB(KEYTYPE) \
757 ADD_TEST(test_unprotected_##KEYTYPE##_via_MSBLOB); \
758 ADD_TEST(test_public_##KEYTYPE##_via_MSBLOB)
760 # ifndef OPENSSL_NO_RC4
761 # define IMPLEMENT_TEST_SUITE_PVK(KEYTYPE, KEYTYPEstr) \
762 static int test_unprotected_##KEYTYPE##_via_PVK(void) \
764 return test_unprotected_via_PVK(KEYTYPEstr, key_##KEYTYPE); \
766 static int test_protected_##KEYTYPE##_via_PVK(void) \
768 return test_protected_via_PVK(KEYTYPEstr, key_##KEYTYPE); \
771 # define ADD_TEST_SUITE_PVK(KEYTYPE) \
772 ADD_TEST(test_unprotected_##KEYTYPE##_via_PVK); \
773 ADD_TEST(test_protected_##KEYTYPE##_via_PVK)
777 #ifndef OPENSSL_NO_DH
779 IMPLEMENT_TEST_SUITE(DH
, "DH")
781 IMPLEMENT_TEST_SUITE(DHX
, "X9.42 DH")
783 * DH has no support for PEM_write_bio_PrivateKey_traditional(),
784 * so no legacy tests.
787 #ifndef OPENSSL_NO_DSA
789 IMPLEMENT_TEST_SUITE(DSA
, "DSA")
790 IMPLEMENT_TEST_SUITE_LEGACY(DSA
, "DSA")
791 IMPLEMENT_TEST_SUITE_MSBLOB(DSA
, "DSA")
792 # ifndef OPENSSL_NO_RC4
793 IMPLEMENT_TEST_SUITE_PVK(DSA
, "DSA")
796 #ifndef OPENSSL_NO_EC
798 IMPLEMENT_TEST_SUITE(EC
, "EC")
799 IMPLEMENT_TEST_SUITE_LEGACY(EC
, "EC")
800 DOMAIN_KEYS(ECExplicitPrimeNamedCurve
);
801 IMPLEMENT_TEST_SUITE(ECExplicitPrimeNamedCurve
, "EC")
802 IMPLEMENT_TEST_SUITE_LEGACY(ECExplicitPrimeNamedCurve
, "EC")
803 DOMAIN_KEYS(ECExplicitPrime2G
);
804 IMPLEMENT_TEST_SUITE(ECExplicitPrime2G
, "EC")
805 IMPLEMENT_TEST_SUITE_LEGACY(ECExplicitPrime2G
, "EC")
806 # ifndef OPENSSL_NO_EC2M
807 DOMAIN_KEYS(ECExplicitTriNamedCurve
);
808 IMPLEMENT_TEST_SUITE(ECExplicitTriNamedCurve
, "EC")
809 IMPLEMENT_TEST_SUITE_LEGACY(ECExplicitTriNamedCurve
, "EC")
810 DOMAIN_KEYS(ECExplicitTri2G
);
811 IMPLEMENT_TEST_SUITE(ECExplicitTri2G
, "EC")
812 IMPLEMENT_TEST_SUITE_LEGACY(ECExplicitTri2G
, "EC")
815 IMPLEMENT_TEST_SUITE(ED25519
, "ED25519")
817 IMPLEMENT_TEST_SUITE(ED448
, "ED448")
819 IMPLEMENT_TEST_SUITE(X25519
, "X25519")
821 IMPLEMENT_TEST_SUITE(X448
, "X448")
823 * ED25519, ED448, X25519 and X448 have no support for
824 * PEM_write_bio_PrivateKey_traditional(), so no legacy tests.
828 IMPLEMENT_TEST_SUITE(RSA
, "RSA")
829 IMPLEMENT_TEST_SUITE_LEGACY(RSA
, "RSA")
831 IMPLEMENT_TEST_SUITE(RSA_PSS
, "RSA-PSS")
833 * RSA-PSS has no support for PEM_write_bio_PrivateKey_traditional(),
834 * so no legacy tests.
836 #ifndef OPENSSL_NO_DSA
837 IMPLEMENT_TEST_SUITE_MSBLOB(RSA
, "RSA")
838 # ifndef OPENSSL_NO_RC4
839 IMPLEMENT_TEST_SUITE_PVK(RSA
, "RSA")
843 #ifndef OPENSSL_NO_EC
844 /* Explicit parameters that match a named curve */
845 static int do_create_ec_explicit_prime_params(OSSL_PARAM_BLD
*bld
,
846 const unsigned char *gen
,
849 BIGNUM
*a
, *b
, *prime
, *order
;
851 /* Curve prime256v1 */
852 static const unsigned char prime_data
[] = {
853 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
854 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
855 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
856 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
859 static const unsigned char a_data
[] = {
860 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
861 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
862 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
863 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
866 static const unsigned char b_data
[] = {
867 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7,
868 0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98, 0x86, 0xbc,
869 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6,
870 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b
872 static const unsigned char seed
[] = {
873 0xc4, 0x9d, 0x36, 0x08, 0x86, 0xe7, 0x04, 0x93,
874 0x6a, 0x66, 0x78, 0xe1, 0x13, 0x9d, 0x26, 0xb7,
875 0x81, 0x9f, 0x7e, 0x90
877 static const unsigned char order_data
[] = {
878 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
879 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
880 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e,
881 0x84, 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51
883 return TEST_ptr(a
= BN_CTX_get(bnctx
))
884 && TEST_ptr(b
= BN_CTX_get(bnctx
))
885 && TEST_ptr(prime
= BN_CTX_get(bnctx
))
886 && TEST_ptr(order
= BN_CTX_get(bnctx
))
887 && TEST_ptr(BN_bin2bn(prime_data
, sizeof(prime_data
), prime
))
888 && TEST_ptr(BN_bin2bn(a_data
, sizeof(a_data
), a
))
889 && TEST_ptr(BN_bin2bn(b_data
, sizeof(b_data
), b
))
890 && TEST_ptr(BN_bin2bn(order_data
, sizeof(order_data
), order
))
891 && TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld
,
892 OSSL_PKEY_PARAM_EC_FIELD_TYPE
, SN_X9_62_prime_field
,
894 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_P
, prime
))
895 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_A
, a
))
896 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_B
, b
))
897 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
,
898 OSSL_PKEY_PARAM_EC_ORDER
, order
))
899 && TEST_true(OSSL_PARAM_BLD_push_octet_string(bld
,
900 OSSL_PKEY_PARAM_EC_GENERATOR
, gen
, gen_len
))
901 && TEST_true(OSSL_PARAM_BLD_push_octet_string(bld
,
902 OSSL_PKEY_PARAM_EC_SEED
, seed
, sizeof(seed
)))
903 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_COFACTOR
,
907 static int create_ec_explicit_prime_params_namedcurve(OSSL_PARAM_BLD
*bld
)
909 static const unsigned char prime256v1_gen
[] = {
911 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
912 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
913 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
914 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
915 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
916 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
917 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
918 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5
920 return do_create_ec_explicit_prime_params(bld
, prime256v1_gen
,
921 sizeof(prime256v1_gen
));
924 static int create_ec_explicit_prime_params(OSSL_PARAM_BLD
*bld
)
927 static const unsigned char prime256v1_gen2
[] = {
929 0xe4, 0x97, 0x08, 0xbe, 0x7d, 0xfa, 0xa2, 0x9a,
930 0xa3, 0x12, 0x6f, 0xe4, 0xe7, 0xd0, 0x25, 0xe3,
931 0x4a, 0xc1, 0x03, 0x15, 0x8c, 0xd9, 0x33, 0xc6,
932 0x97, 0x42, 0xf5, 0xdc, 0x97, 0xb9, 0xd7, 0x31,
933 0xe9, 0x7d, 0x74, 0x3d, 0x67, 0x6a, 0x3b, 0x21,
934 0x08, 0x9c, 0x31, 0x73, 0xf8, 0xc1, 0x27, 0xc9,
935 0xd2, 0xa0, 0xa0, 0x83, 0x66, 0xe0, 0xc9, 0xda,
936 0xa8, 0xc6, 0x56, 0x2b, 0x94, 0xb1, 0xae, 0x55
938 return do_create_ec_explicit_prime_params(bld
, prime256v1_gen2
,
939 sizeof(prime256v1_gen2
));
942 # ifndef OPENSSL_NO_EC2M
943 static int do_create_ec_explicit_trinomial_params(OSSL_PARAM_BLD
*bld
,
944 const unsigned char *gen
,
947 BIGNUM
*a
, *b
, *poly
, *order
, *cofactor
;
948 /* sect233k1 characteristic-two-field tpBasis */
949 static const unsigned char poly_data
[] = {
950 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
951 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
952 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
954 static const unsigned char a_data
[] = {
955 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
956 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
957 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
959 static const unsigned char b_data
[] = {
960 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
961 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
962 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
964 static const unsigned char order_data
[] = {
965 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
966 0x00, 0x00, 0x00, 0x06, 0x9D, 0x5B, 0xB9, 0x15, 0xBC, 0xD4, 0x6E, 0xFB,
967 0x1A, 0xD5, 0xF1, 0x73, 0xAB, 0xDF
969 static const unsigned char cofactor_data
[]= {
972 return TEST_ptr(a
= BN_CTX_get(bnctx
))
973 && TEST_ptr(b
= BN_CTX_get(bnctx
))
974 && TEST_ptr(poly
= BN_CTX_get(bnctx
))
975 && TEST_ptr(order
= BN_CTX_get(bnctx
))
976 && TEST_ptr(cofactor
= BN_CTX_get(bnctx
))
977 && TEST_ptr(BN_bin2bn(poly_data
, sizeof(poly_data
), poly
))
978 && TEST_ptr(BN_bin2bn(a_data
, sizeof(a_data
), a
))
979 && TEST_ptr(BN_bin2bn(b_data
, sizeof(b_data
), b
))
980 && TEST_ptr(BN_bin2bn(order_data
, sizeof(order_data
), order
))
981 && TEST_ptr(BN_bin2bn(cofactor_data
, sizeof(cofactor_data
), cofactor
))
982 && TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld
,
983 OSSL_PKEY_PARAM_EC_FIELD_TYPE
,
984 SN_X9_62_characteristic_two_field
, 0))
985 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_P
, poly
))
986 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_A
, a
))
987 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_B
, b
))
988 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
,
989 OSSL_PKEY_PARAM_EC_ORDER
, order
))
990 && TEST_true(OSSL_PARAM_BLD_push_octet_string(bld
,
991 OSSL_PKEY_PARAM_EC_GENERATOR
, gen
, gen_len
))
992 && TEST_true(OSSL_PARAM_BLD_push_BN(bld
, OSSL_PKEY_PARAM_EC_COFACTOR
,
996 static int create_ec_explicit_trinomial_params_namedcurve(OSSL_PARAM_BLD
*bld
)
998 static const unsigned char gen
[] = {
1000 0x01, 0x72, 0x32, 0xBA, 0x85, 0x3A, 0x7E, 0x73, 0x1A, 0xF1, 0x29, 0xF2,
1001 0x2F, 0xF4, 0x14, 0x95, 0x63, 0xA4, 0x19, 0xC2, 0x6B, 0xF5, 0x0A, 0x4C,
1002 0x9D, 0x6E, 0xEF, 0xAD, 0x61, 0x26,
1003 0x01, 0xDB, 0x53, 0x7D, 0xEC, 0xE8, 0x19, 0xB7, 0xF7, 0x0F, 0x55, 0x5A,
1004 0x67, 0xC4, 0x27, 0xA8, 0xCD, 0x9B, 0xF1, 0x8A, 0xEB, 0x9B, 0x56, 0xE0,
1005 0xC1, 0x10, 0x56, 0xFA, 0xE6, 0xA3
1007 return do_create_ec_explicit_trinomial_params(bld
, gen
, sizeof(gen
));
1010 static int create_ec_explicit_trinomial_params(OSSL_PARAM_BLD
*bld
)
1012 static const unsigned char gen2
[] = {
1014 0x00, 0xd7, 0xba, 0xd0, 0x26, 0x6c, 0x31, 0x6a, 0x78, 0x76, 0x01, 0xd1,
1015 0x32, 0x4b, 0x8f, 0x30, 0x29, 0x2d, 0x78, 0x30, 0xca, 0x43, 0xaa, 0xf0,
1016 0xa2, 0x5a, 0xd4, 0x0f, 0xb3, 0xf4,
1017 0x00, 0x85, 0x4b, 0x1b, 0x8d, 0x50, 0x10, 0xa5, 0x1c, 0x80, 0xf7, 0x86,
1018 0x40, 0x62, 0x4c, 0x87, 0xd1, 0x26, 0x7a, 0x9c, 0x5c, 0xe9, 0x82, 0x29,
1019 0xd1, 0x67, 0x70, 0x41, 0xea, 0xcb
1021 return do_create_ec_explicit_trinomial_params(bld
, gen2
, sizeof(gen2
));
1023 # endif /* OPENSSL_NO_EC2M */
1024 #endif /* OPENSSL_NO_EC */
1026 int setup_tests(void)
1030 #ifndef OPENSSL_NO_DSA
1031 static size_t qbits
= 160; /* PVK only tolerates 160 Q bits */
1032 static size_t pbits
= 1024; /* With 160 Q bits, we MUST use 1024 P bits */
1033 OSSL_PARAM DSA_params
[] = {
1034 OSSL_PARAM_size_t("pbits", &pbits
),
1035 OSSL_PARAM_size_t("qbits", &qbits
),
1040 #ifndef OPENSSL_NO_EC
1041 static char groupname
[] = "prime256v1";
1042 OSSL_PARAM EC_params
[] = {
1043 OSSL_PARAM_utf8_string("group", groupname
, sizeof(groupname
) - 1),
1048 /* 7 is the default magic number */
1049 static unsigned int rsapss_min_saltlen
= 7;
1050 OSSL_PARAM RSA_PSS_params
[] = {
1051 OSSL_PARAM_uint("saltlen", &rsapss_min_saltlen
),
1055 #ifndef OPENSSL_NO_EC
1056 if (!TEST_ptr(bnctx
= BN_CTX_new_ex(NULL
))
1057 || !TEST_ptr(bld_prime_nc
= OSSL_PARAM_BLD_new())
1058 || !TEST_ptr(bld_prime
= OSSL_PARAM_BLD_new())
1059 || !create_ec_explicit_prime_params_namedcurve(bld_prime_nc
)
1060 || !create_ec_explicit_prime_params(bld_prime
)
1061 || !TEST_ptr(ec_explicit_prime_params_nc
= OSSL_PARAM_BLD_to_param(bld_prime_nc
))
1062 || !TEST_ptr(ec_explicit_prime_params_explicit
= OSSL_PARAM_BLD_to_param(bld_prime
))
1063 # ifndef OPENSSL_NO_EC2M
1064 || !TEST_ptr(bld_tri_nc
= OSSL_PARAM_BLD_new())
1065 || !TEST_ptr(bld_tri
= OSSL_PARAM_BLD_new())
1066 || !create_ec_explicit_trinomial_params_namedcurve(bld_tri_nc
)
1067 || !create_ec_explicit_trinomial_params(bld_tri
)
1068 || !TEST_ptr(ec_explicit_tri_params_nc
= OSSL_PARAM_BLD_to_param(bld_tri_nc
))
1069 || !TEST_ptr(ec_explicit_tri_params_explicit
= OSSL_PARAM_BLD_to_param(bld_tri
))
1075 TEST_info("Generating keys...");
1077 #ifndef OPENSSL_NO_DH
1078 MAKE_DOMAIN_KEYS(DH
, "DH", NULL
);
1079 MAKE_DOMAIN_KEYS(DHX
, "X9.42 DH", NULL
);
1081 #ifndef OPENSSL_NO_DSA
1082 MAKE_DOMAIN_KEYS(DSA
, "DSA", DSA_params
);
1084 #ifndef OPENSSL_NO_EC
1085 MAKE_DOMAIN_KEYS(EC
, "EC", EC_params
);
1086 MAKE_DOMAIN_KEYS(ECExplicitPrimeNamedCurve
, "EC", ec_explicit_prime_params_nc
);
1087 MAKE_DOMAIN_KEYS(ECExplicitPrime2G
, "EC", ec_explicit_prime_params_explicit
);
1088 # ifndef OPENSSL_NO_EC2M
1089 MAKE_DOMAIN_KEYS(ECExplicitTriNamedCurve
, "EC", ec_explicit_tri_params_nc
);
1090 MAKE_DOMAIN_KEYS(ECExplicitTri2G
, "EC", ec_explicit_tri_params_explicit
);
1092 MAKE_KEYS(ED25519
, "ED25519", NULL
);
1093 MAKE_KEYS(ED448
, "ED448", NULL
);
1094 MAKE_KEYS(X25519
, "X25519", NULL
);
1095 MAKE_KEYS(X448
, "X448", NULL
);
1097 MAKE_KEYS(RSA
, "RSA", NULL
);
1098 MAKE_KEYS(RSA_PSS
, "RSA-PSS", RSA_PSS_params
);
1099 TEST_info("Generating key... done");
1102 #ifndef OPENSSL_NO_DH
1104 ADD_TEST_SUITE(DHX
);
1106 * DH has no support for PEM_write_bio_PrivateKey_traditional(),
1107 * so no legacy tests.
1110 #ifndef OPENSSL_NO_DSA
1111 ADD_TEST_SUITE(DSA
);
1112 ADD_TEST_SUITE_LEGACY(DSA
);
1113 ADD_TEST_SUITE_MSBLOB(DSA
);
1114 # ifndef OPENSSL_NO_RC4
1115 ADD_TEST_SUITE_PVK(DSA
);
1118 #ifndef OPENSSL_NO_EC
1120 ADD_TEST_SUITE_LEGACY(EC
);
1121 ADD_TEST_SUITE(ECExplicitPrimeNamedCurve
);
1122 ADD_TEST_SUITE_LEGACY(ECExplicitPrimeNamedCurve
);
1123 ADD_TEST_SUITE(ECExplicitPrime2G
);
1124 ADD_TEST_SUITE_LEGACY(ECExplicitPrime2G
);
1125 # ifndef OPENSSL_NO_EC2M
1126 ADD_TEST_SUITE(ECExplicitTriNamedCurve
);
1127 ADD_TEST_SUITE_LEGACY(ECExplicitTriNamedCurve
);
1128 ADD_TEST_SUITE(ECExplicitTri2G
);
1129 ADD_TEST_SUITE_LEGACY(ECExplicitTri2G
);
1131 ADD_TEST_SUITE(ED25519
);
1132 ADD_TEST_SUITE(ED448
);
1133 ADD_TEST_SUITE(X25519
);
1134 ADD_TEST_SUITE(X448
);
1136 * ED25519, ED448, X25519 and X448 have no support for
1137 * PEM_write_bio_PrivateKey_traditional(), so no legacy tests.
1140 ADD_TEST_SUITE(RSA
);
1141 ADD_TEST_SUITE_LEGACY(RSA
);
1142 ADD_TEST_SUITE(RSA_PSS
);
1144 * RSA-PSS has no support for PEM_write_bio_PrivateKey_traditional(),
1145 * so no legacy tests.
1147 #ifndef OPENSSL_NO_DSA
1148 ADD_TEST_SUITE_MSBLOB(RSA
);
1149 # ifndef OPENSSL_NO_RC4
1150 ADD_TEST_SUITE_PVK(RSA
);
1158 void cleanup_tests(void)
1160 #ifndef OPENSSL_NO_EC
1161 OSSL_PARAM_BLD_free_params(ec_explicit_prime_params_nc
);
1162 OSSL_PARAM_BLD_free_params(ec_explicit_prime_params_explicit
);
1163 OSSL_PARAM_BLD_free(bld_prime_nc
);
1164 OSSL_PARAM_BLD_free(bld_prime
);
1165 # ifndef OPENSSL_NO_EC2M
1166 OSSL_PARAM_BLD_free_params(ec_explicit_tri_params_nc
);
1167 OSSL_PARAM_BLD_free_params(ec_explicit_tri_params_explicit
);
1168 OSSL_PARAM_BLD_free(bld_tri_nc
);
1169 OSSL_PARAM_BLD_free(bld_tri
);
1172 #endif /* OPENSSL_NO_EC */
1174 #ifndef OPENSSL_NO_DH
1175 FREE_DOMAIN_KEYS(DH
);
1176 FREE_DOMAIN_KEYS(DHX
);
1178 #ifndef OPENSSL_NO_DSA
1179 FREE_DOMAIN_KEYS(DSA
);
1181 #ifndef OPENSSL_NO_EC
1182 FREE_DOMAIN_KEYS(EC
);
1183 FREE_DOMAIN_KEYS(ECExplicitPrimeNamedCurve
);
1184 FREE_DOMAIN_KEYS(ECExplicitPrime2G
);
1185 # ifndef OPENSSL_NO_EC2M
1186 FREE_DOMAIN_KEYS(ECExplicitTriNamedCurve
);
1187 FREE_DOMAIN_KEYS(ECExplicitTri2G
);