7 - EVP_PKEY EC keytype and algorithm support
11 The B<EC> keytype is implemented in OpenSSL's default provider.
13 =head2 Common EC parameters
15 The following Import/Export types are available for the built-in EC algorithm:
19 =item "curve-name" (B<OSSL_PKEY_PARAM_EC_NAME>) <utf8 string>
23 =item "use-cofactor-flag" (B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH>) <integer>
25 Enable Cofactor DH (ECC CDH) if this value is 1, otherwise it uses normal EC DH
26 if the value is zero. The cofactor variant multiplies the shared secret by the
27 EC curve's cofactor (note for some curves the cofactor is 1).
30 See also L<EVP_KEYEXCH-ECDH(7)> for the related
31 B<OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE> parameter that can be set on a
34 =item "pub" (B<OSSL_PKEY_PARAM_PUB_KEY>) <octet string>
36 The public key value in EC point format.
38 =item "priv" (B<OSSL_PKEY_PARAM_PRIV_KEY>) <unsigned integer>
40 The private key value.
42 =item "tls-encoded-pt" (B<OSSL_PKEY_PARAM_TLS_ENCODED_PT>) <octet string>
44 Used for getting and setting the encoding of the EC public key used in key
45 exchange message for the TLS protocol.
51 An B<EVP_PKEY> context can be obtained by calling:
54 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
56 An B<EVP_PKEY> ECDSA or ECDH key can be generated with a "P-256" named group by
62 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
64 EVP_PKEY_keygen_init(gctx);
66 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_EC_NAME,
68 params[1] = OSSL_PARAM_construct_end();
69 EVP_PKEY_CTX_set_params(gctx, params);
71 EVP_PKEY_gen(gctx, &key);
73 EVP_PKEY_print_private(bio_out, key, 0, NULL);
76 EVP_PKEY_CTX_free(gctx);
78 An B<EVP_PKEY> EC CDH (Cofactor Diffie-Hellman) key can be generated with a
79 "K-571" named group by calling:
85 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
89 EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
91 EVP_PKEY_keygen_init(gctx);
93 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_EC_NAME,
96 * This curve has a cofactor that is not 1 - so setting CDH mode changes
97 * the behaviour. For many curves the cofactor is 1 - so setting this has
100 params[1] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH,
102 params[2] = OSSL_PARAM_construct_end();
103 EVP_PKEY_CTX_set_params(gctx, params);
105 EVP_PKEY_gen(gctx, &key);
106 EVP_PKEY_print_private(bio_out, key, 0, NULL);
109 EVP_PKEY_CTX_free(gctx);
115 L<provider-keymgmt(7)>,
116 L<EVP_SIGNATURE-ECDSA(7)>,
117 L<EVP_KEYEXCH-ECDH(7)>
121 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
123 Licensed under the Apache License 2.0 (the "License"). You may not use
124 this file except in compliance with the License. You can obtain a copy
125 in the file LICENSE in the source distribution or at
126 L<https://www.openssl.org/source/license.html>.