Update core_names.h fields and document most fields.
[openssl.git] / doc / man7 / EVP_PKEY-EC.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY-EC,
6 EVP_KEYMGMT-EC
7 - EVP_PKEY EC keytype and algorithm support
8
9 =head1 DESCRIPTION
10
11 The B<EC> keytype is implemented in OpenSSL's default provider.
12
13 =head2 Common EC parameters
14
15 The following Import/Export types are available for the built-in EC algorithm:
16
17 =over 4
18
19 =item "curve-name" (B<OSSL_PKEY_PARAM_EC_NAME>) <utf8 string>
20
21 The EC curve name.
22
23 =item "use-cofactor-flag" (B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH>) <integer>
24
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).
28
29
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
32 per-operation basis.
33
34 =item "pub" (B<OSSL_PKEY_PARAM_PUB_KEY>) <octet string>
35
36 The public key value in EC point format.
37
38 =item "priv" (B<OSSL_PKEY_PARAM_PRIV_KEY>) <unsigned integer>
39
40 The private key value.
41
42 =back
43
44 =head1 EXAMPLES
45
46 An B<EVP_PKEY> context can be obtained by calling:
47
48     EVP_PKEY_CTX *pctx =
49         EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
50
51 An B<EVP_PKEY> ECDSA or ECDH key can be generated with a "P-256" named group by
52 calling:
53
54     EVP_PKEY *key = NULL;
55     OSSL_PARAM params[2];
56     EVP_PKEY_CTX *gctx =
57         EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
58
59     EVP_PKEY_keygen_init(gctx);
60
61     params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_EC_NAME,
62                                                  "P-256", 0);
63     params[1] = OSSL_PARAM_construct_end();
64     EVP_PKEY_CTX_set_params(gctx, params);
65
66     EVP_PKEY_gen(gctx, &key);
67
68     EVP_PKEY_print_private(bio_out, key, 0, NULL);
69     ...
70     EVP_PKEY_free(key);
71     EVP_PKEY_CTX_free(gctx);
72
73 An B<EVP_PKEY> EC CDH (Cofactor Diffie-Hellman) key can be generated with a
74 "K-571" named group by calling:
75
76     int use_cdh = 1;
77     EVP_PKEY *key = NULL;
78     OSSL_PARAM params[3];
79     EVP_PKEY_CTX *gctx =
80         EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
81
82     EVP_PKEY *key = NULL;
83     OSSL_PARAM params[3];
84     EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
85
86     EVP_PKEY_keygen_init(gctx);
87
88     params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_EC_NAME,
89                                                  "K-571", 0);
90     /*
91      * This curve has a cofactor that is not 1 - so setting CDH mode changes
92      * the behaviour. For many curves the cofactor is 1 - so setting this has
93      * no effect.
94      */
95     params[1] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH,
96                                          &use_cdh);
97     params[2] = OSSL_PARAM_construct_end();
98     EVP_PKEY_CTX_set_params(gctx, params);
99
100     EVP_PKEY_gen(gctx, &key);
101     EVP_PKEY_print_private(bio_out, key, 0, NULL);
102     ...
103     EVP_PKEY_free(key);
104     EVP_PKEY_CTX_free(gctx);
105
106 =head1 SEE ALSO
107
108 L<EVP_KEYMGMT(3)>,
109 L<EVP_PKEY(3)>,
110 L<provider-keymgmt(7)>,
111 L<EVP_SIGNATURE-ECDSA(7)>,
112 L<EVP_KEYEXCH-ECDH(7)>
113
114 =head1 COPYRIGHT
115
116 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
117
118 Licensed under the Apache License 2.0 (the "License").  You may not use
119 this file except in compliance with the License.  You can obtain a copy
120 in the file LICENSE in the source distribution or at
121 L<https://www.openssl.org/source/license.html>.
122
123 =cut