]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man7/EVP_PKEY-EC.pod
Make EVP_PKEY_CTX_[get|set]_ec_paramgen_curve_name more generic
[thirdparty/openssl.git] / doc / man7 / EVP_PKEY-EC.pod
CommitLineData
33df1cfd
RL
1=pod
2
3=head1 NAME
4
b8086652
SL
5EVP_PKEY-EC,
6EVP_KEYMGMT-EC
7- EVP_PKEY EC keytype and algorithm support
33df1cfd
RL
8
9=head1 DESCRIPTION
10
11The B<EC> keytype is implemented in OpenSSL's default provider.
12
13=head2 Common EC parameters
14
15The following Import/Export types are available for the built-in EC algorithm:
16
17=over 4
18
11a1b341 19=item "group-name" (B<OSSL_PKEY_PARAM_GROUP_NAME>) <utf8 string>
33df1cfd 20
11a1b341 21The curve name.
33df1cfd
RL
22
23=item "use-cofactor-flag" (B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH>) <integer>
24
25Enable Cofactor DH (ECC CDH) if this value is 1, otherwise it uses normal EC DH
26if the value is zero. The cofactor variant multiplies the shared secret by the
27EC curve's cofactor (note for some curves the cofactor is 1).
28
33df1cfd 29
b8086652 30See also L<EVP_KEYEXCH-ECDH(7)> for the related
33df1cfd
RL
31B<OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE> parameter that can be set on a
32per-operation basis.
33
34=item "pub" (B<OSSL_PKEY_PARAM_PUB_KEY>) <octet string>
35
36The public key value in EC point format.
37
38=item "priv" (B<OSSL_PKEY_PARAM_PRIV_KEY>) <unsigned integer>
39
40The private key value.
41
6a9bd929
MC
42=item "tls-encoded-pt" (B<OSSL_PKEY_PARAM_TLS_ENCODED_PT>) <octet string>
43
44Used for getting and setting the encoding of the EC public key used in key
45exchange message for the TLS protocol.
46
33df1cfd
RL
47=back
48
49=head1 EXAMPLES
50
51An B<EVP_PKEY> context can be obtained by calling:
52
53 EVP_PKEY_CTX *pctx =
54 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
55
b8086652
SL
56An B<EVP_PKEY> ECDSA or ECDH key can be generated with a "P-256" named group by
57calling:
58
59 EVP_PKEY *key = NULL;
60 OSSL_PARAM params[2];
61 EVP_PKEY_CTX *gctx =
62 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
63
64 EVP_PKEY_keygen_init(gctx);
65
11a1b341 66 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME,
b8086652
SL
67 "P-256", 0);
68 params[1] = OSSL_PARAM_construct_end();
69 EVP_PKEY_CTX_set_params(gctx, params);
70
71 EVP_PKEY_gen(gctx, &key);
72
73 EVP_PKEY_print_private(bio_out, key, 0, NULL);
74 ...
75 EVP_PKEY_free(key);
76 EVP_PKEY_CTX_free(gctx);
77
78An B<EVP_PKEY> EC CDH (Cofactor Diffie-Hellman) key can be generated with a
79"K-571" named group by calling:
80
81 int use_cdh = 1;
82 EVP_PKEY *key = NULL;
83 OSSL_PARAM params[3];
84 EVP_PKEY_CTX *gctx =
85 EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
86
87 EVP_PKEY *key = NULL;
88 OSSL_PARAM params[3];
89 EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
90
91 EVP_PKEY_keygen_init(gctx);
92
11a1b341 93 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME,
b8086652
SL
94 "K-571", 0);
95 /*
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
98 * no effect.
99 */
100 params[1] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH,
101 &use_cdh);
102 params[2] = OSSL_PARAM_construct_end();
103 EVP_PKEY_CTX_set_params(gctx, params);
104
105 EVP_PKEY_gen(gctx, &key);
106 EVP_PKEY_print_private(bio_out, key, 0, NULL);
107 ...
108 EVP_PKEY_free(key);
109 EVP_PKEY_CTX_free(gctx);
110
33df1cfd
RL
111=head1 SEE ALSO
112
b8086652
SL
113L<EVP_KEYMGMT(3)>,
114L<EVP_PKEY(3)>,
115L<provider-keymgmt(7)>,
116L<EVP_SIGNATURE-ECDSA(7)>,
117L<EVP_KEYEXCH-ECDH(7)>
33df1cfd
RL
118
119=head1 COPYRIGHT
120
121Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
122
123Licensed under the Apache License 2.0 (the "License"). You may not use
124this file except in compliance with the License. You can obtain a copy
125in the file LICENSE in the source distribution or at
126L<https://www.openssl.org/source/license.html>.
127
128=cut