2 * Copyright 2019 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
14 #include "internal/nelem.h"
15 #include <openssl/crypto.h>
16 #include <openssl/bio.h>
17 #include <openssl/bn.h>
18 #include <openssl/rand.h>
19 #include <openssl/err.h>
20 #include <openssl/evp.h>
21 #include <openssl/ec.h>
24 static int pkey_param_types[] = {
28 #ifndef OPENSSL_NO_DSA
36 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
38 static int params_bio_test(int id)
42 EVP_PKEY_CTX *ctx = NULL;
43 EVP_PKEY *params_key = NULL, *out_key = NULL;
44 int type = pkey_param_types[id];
47 TEST_ptr(mem_bio = BIO_new(BIO_s_mem()))
48 && TEST_ptr(ctx = EVP_PKEY_CTX_new_id(type, NULL))
49 && TEST_int_gt(EVP_PKEY_paramgen_init(ctx), 0)
50 && (type != EVP_PKEY_EC
51 || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_secp256k1) > 0)
52 && TEST_int_gt(EVP_PKEY_paramgen(ctx, ¶ms_key), 0)
53 && TEST_int_gt(i2d_KeyParams_bio(mem_bio, params_key), 0)
54 && TEST_ptr(d2i_KeyParams_bio(type, &out_key, mem_bio))
55 && TEST_int_gt(EVP_PKEY_cmp_parameters(out_key, params_key), 0);
58 EVP_PKEY_CTX_free(ctx);
59 EVP_PKEY_free(params_key);
60 EVP_PKEY_free(out_key);
67 #if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
68 TEST_note("No DH/DSA/EC support");
70 ADD_ALL_TESTS(params_bio_test, OSSL_NELEM(pkey_param_types));