1b077aed3SPierre Pronchery=pod 2b077aed3SPierre Pronchery 3b077aed3SPierre Pronchery=head1 NAME 4b077aed3SPierre Pronchery 5b077aed3SPierre ProncheryEVP_PKEY-EC, 6b077aed3SPierre ProncheryEVP_KEYMGMT-EC 7b077aed3SPierre Pronchery- EVP_PKEY EC keytype and algorithm support 8b077aed3SPierre Pronchery 9b077aed3SPierre Pronchery=head1 DESCRIPTION 10b077aed3SPierre Pronchery 11b077aed3SPierre ProncheryThe B<EC> keytype is implemented in OpenSSL's default provider. 12b077aed3SPierre Pronchery 13b077aed3SPierre Pronchery=head2 Common EC parameters 14b077aed3SPierre Pronchery 15b077aed3SPierre ProncheryThe normal way of specifying domain parameters for an EC curve is via the 16b077aed3SPierre Proncherycurve name "group". For curves with no curve name, explicit parameters can be 17b077aed3SPierre Proncheryused that specify "field-type", "p", "a", "b", "generator" and "order". 18*aa795734SPierre ProncheryExplicit parameters are supported for backwards compatibility reasons, but they 19b077aed3SPierre Proncheryare not compliant with multiple standards (including RFC5915) which only allow 20b077aed3SPierre Proncherynamed curves. 21b077aed3SPierre Pronchery 22b077aed3SPierre ProncheryThe following KeyGen/Gettable/Import/Export types are available for the 23b077aed3SPierre Proncherybuilt-in EC algorithm: 24b077aed3SPierre Pronchery 25b077aed3SPierre Pronchery=over 4 26b077aed3SPierre Pronchery 27b077aed3SPierre Pronchery=item "group" (B<OSSL_PKEY_PARAM_GROUP_NAME>) <UTF8 string> 28b077aed3SPierre Pronchery 29b077aed3SPierre ProncheryThe curve name. 30b077aed3SPierre Pronchery 31b077aed3SPierre Pronchery=item "field-type" (B<OSSL_PKEY_PARAM_EC_FIELD_TYPE>) <UTF8 string> 32b077aed3SPierre Pronchery 33b077aed3SPierre ProncheryThe value should be either "prime-field" or "characteristic-two-field", 34b077aed3SPierre Proncherywhich correspond to prime field Fp and binary field F2^m. 35b077aed3SPierre Pronchery 36b077aed3SPierre Pronchery=item "p" (B<OSSL_PKEY_PARAM_EC_P>) <unsigned integer> 37b077aed3SPierre Pronchery 38b077aed3SPierre ProncheryFor a curve over Fp I<p> is the prime for the field. For a curve over F2^m I<p> 39b077aed3SPierre Proncheryrepresents the irreducible polynomial - each bit represents a term in the 40b077aed3SPierre Proncherypolynomial. Therefore, there will either be three or five bits set dependent on 41b077aed3SPierre Proncherywhether the polynomial is a trinomial or a pentanomial. 42b077aed3SPierre Pronchery 43b077aed3SPierre Pronchery=item "a" (B<OSSL_PKEY_PARAM_EC_A>) <unsigned integer> 44b077aed3SPierre Pronchery 45b077aed3SPierre Pronchery=item "b" (B<OSSL_PKEY_PARAM_EC_B>) <unsigned integer> 46b077aed3SPierre Pronchery 47b077aed3SPierre Pronchery=item "seed" (B<OSSL_PKEY_PARAM_EC_SEED>) <octet string> 48b077aed3SPierre Pronchery 49b077aed3SPierre ProncheryI<a> and I<b> represents the coefficients of the curve 50b077aed3SPierre ProncheryFor Fp: y^2 mod p = x^3 +ax + b mod p OR 51b077aed3SPierre ProncheryFor F2^m: y^2 + xy = x^3 + ax^2 + b 52b077aed3SPierre Pronchery 53b077aed3SPierre ProncheryI<seed> is an optional value that is for information purposes only. 54b077aed3SPierre ProncheryIt represents the random number seed used to generate the coefficient I<b> from a 55b077aed3SPierre Proncheryrandom number. 56b077aed3SPierre Pronchery 57b077aed3SPierre Pronchery=item "generator" (B<OSSL_PKEY_PARAM_EC_GENERATOR>) <octet string> 58b077aed3SPierre Pronchery 59b077aed3SPierre Pronchery=item "order" (B<OSSL_PKEY_PARAM_EC_ORDER>) <unsigned integer> 60b077aed3SPierre Pronchery 61b077aed3SPierre Pronchery=item "cofactor" (B<OSSL_PKEY_PARAM_EC_COFACTOR>) <unsigned integer> 62b077aed3SPierre Pronchery 63b077aed3SPierre ProncheryThe I<generator> is a well defined point on the curve chosen for cryptographic 64b077aed3SPierre Proncheryoperations. The encoding conforms with Sec. 2.3.3 of the SECG SEC 1 ("Elliptic Curve 65b077aed3SPierre ProncheryCryptography") standard. See EC_POINT_oct2point(). 66b077aed3SPierre ProncheryIntegers used for point multiplications will be between 0 and 67b077aed3SPierre ProncheryI<order> - 1. 68b077aed3SPierre ProncheryI<cofactor> is an optional value. 69b077aed3SPierre ProncheryI<order> multiplied by the I<cofactor> gives the number of points on the curve. 70b077aed3SPierre Pronchery 71b077aed3SPierre Pronchery=item "decoded-from-explicit" (B<OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS>) <integer> 72b077aed3SPierre Pronchery 73*aa795734SPierre ProncheryGets a flag indicating whether the key or parameters were decoded from explicit 74b077aed3SPierre Proncherycurve parameters. Set to 1 if so or 0 if a named curve was used. 75b077aed3SPierre Pronchery 76b077aed3SPierre Pronchery=item "use-cofactor-flag" (B<OSSL_PKEY_PARAM_USE_COFACTOR_ECDH>) <integer> 77b077aed3SPierre Pronchery 78b077aed3SPierre ProncheryEnable Cofactor DH (ECC CDH) if this value is 1, otherwise it uses normal EC DH 79b077aed3SPierre Proncheryif the value is zero. The cofactor variant multiplies the shared secret by the 80b077aed3SPierre ProncheryEC curve's cofactor (note for some curves the cofactor is 1). 81b077aed3SPierre Pronchery 82b077aed3SPierre ProncherySee also L<EVP_KEYEXCH-ECDH(7)> for the related 83b077aed3SPierre ProncheryB<OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE> parameter that can be set on a 84b077aed3SPierre Proncheryper-operation basis. 85b077aed3SPierre Pronchery 86b077aed3SPierre Pronchery=item "encoding" (B<OSSL_PKEY_PARAM_EC_ENCODING>) <UTF8 string> 87b077aed3SPierre Pronchery 88b077aed3SPierre ProncherySet the format used for serializing the EC group parameters. 89b077aed3SPierre ProncheryValid values are "explicit" or "named_curve". The default value is "named_curve". 90b077aed3SPierre Pronchery 91b077aed3SPierre Pronchery=item "point-format" (B<OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT>) <UTF8 string> 92b077aed3SPierre Pronchery 93b077aed3SPierre ProncherySets or gets the point_conversion_form for the I<key>. For a description of 94b077aed3SPierre Proncherypoint_conversion_forms please see L<EC_POINT_new(3)>. Valid values are 95b077aed3SPierre Pronchery"uncompressed" or "compressed". The default value is "uncompressed". 96b077aed3SPierre Pronchery 97b077aed3SPierre Pronchery=item "group-check" (B<OSSL_PKEY_PARAM_EC_GROUP_CHECK_TYPE>) <UTF8 string> 98b077aed3SPierre Pronchery 99b077aed3SPierre ProncherySets or Gets the type of group check done when EVP_PKEY_param_check() is called. 100b077aed3SPierre ProncheryValid values are "default", "named" and "named-nist". 101b077aed3SPierre ProncheryThe "named" type checks that the domain parameters match the inbuilt curve parameters, 102*aa795734SPierre Pronchery"named-nist" is similar but also checks that the named curve is a nist curve. 103b077aed3SPierre ProncheryThe "default" type does domain parameter validation for the OpenSSL default provider, 104b077aed3SPierre Proncherybut is equivalent to "named-nist" for the OpenSSL FIPS provider. 105b077aed3SPierre Pronchery 106b077aed3SPierre Pronchery=item "include-public" (B<OSSL_PKEY_PARAM_EC_INCLUDE_PUBLIC>) <integer> 107b077aed3SPierre Pronchery 108b077aed3SPierre ProncherySetting this value to 0 indicates that the public key should not be included when 109b077aed3SPierre Proncheryencoding the private key. The default value of 1 will include the public key. 110b077aed3SPierre Pronchery 111b077aed3SPierre Pronchery=item "pub" (B<OSSL_PKEY_PARAM_PUB_KEY>) <octet string> 112b077aed3SPierre Pronchery 113b077aed3SPierre ProncheryThe public key value in encoded EC point format conforming to Sec. 2.3.3 and 114b077aed3SPierre Pronchery2.3.4 of the SECG SEC 1 ("Elliptic Curve Cryptography") standard. 115b077aed3SPierre ProncheryThis parameter is used when importing or exporting the public key value with the 116b077aed3SPierre ProncheryEVP_PKEY_fromdata() and EVP_PKEY_todata() functions. 117b077aed3SPierre Pronchery 118b077aed3SPierre ProncheryNote, in particular, that the choice of point compression format used for 119b077aed3SPierre Proncheryencoding the exported value via EVP_PKEY_todata() depends on the underlying 120b077aed3SPierre Proncheryprovider implementation. 121b077aed3SPierre ProncheryBefore OpenSSL 3.0.8, the implementation of providers included with OpenSSL always 122b077aed3SPierre Proncheryopted for an encoding in compressed format, unconditionally. 123b077aed3SPierre ProncherySince OpenSSL 3.0.8, the implementation has been changed to honor the 124b077aed3SPierre ProncheryB<OSSL_PKEY_PARAM_EC_POINT_CONVERSION_FORMAT> parameter, if set, or to default 125b077aed3SPierre Proncheryto uncompressed format. 126b077aed3SPierre Pronchery 127b077aed3SPierre Pronchery=item "priv" (B<OSSL_PKEY_PARAM_PRIV_KEY>) <unsigned integer> 128b077aed3SPierre Pronchery 129b077aed3SPierre ProncheryThe private key value. 130b077aed3SPierre Pronchery 131b077aed3SPierre Pronchery=item "encoded-pub-key" (B<OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY>) <octet string> 132b077aed3SPierre Pronchery 133b077aed3SPierre ProncheryUsed for getting and setting the encoding of an EC public key. The public key 134b077aed3SPierre Proncheryis expected to be a point conforming to Sec. 2.3.4 of the SECG SEC 1 ("Elliptic 135b077aed3SPierre ProncheryCurve Cryptography") standard. 136b077aed3SPierre Pronchery 137b077aed3SPierre Pronchery=item "qx" (B<OSSL_PKEY_PARAM_EC_PUB_X>) <unsigned integer> 138b077aed3SPierre Pronchery 139b077aed3SPierre ProncheryUsed for getting the EC public key X component. 140b077aed3SPierre Pronchery 141b077aed3SPierre Pronchery=item "qy" (B<OSSL_PKEY_PARAM_EC_PUB_Y>) <unsigned integer> 142b077aed3SPierre Pronchery 143b077aed3SPierre ProncheryUsed for getting the EC public key Y component. 144b077aed3SPierre Pronchery 145b077aed3SPierre Pronchery=item "default-digest" (B<OSSL_PKEY_PARAM_DEFAULT_DIGEST>) <UTF8 string> 146b077aed3SPierre Pronchery 147b077aed3SPierre ProncheryGetter that returns the default digest name. 148b077aed3SPierre Pronchery(Currently returns "SHA256" as of OpenSSL 3.0). 149b077aed3SPierre Pronchery 150b077aed3SPierre Pronchery=back 151b077aed3SPierre Pronchery 152b077aed3SPierre ProncheryThe following Gettable types are also available for the built-in EC algorithm: 153b077aed3SPierre Pronchery 154b077aed3SPierre Pronchery=over 4 155b077aed3SPierre Pronchery 156b077aed3SPierre Pronchery=item "basis-type" (B<OSSL_PKEY_PARAM_EC_CHAR2_TYPE>) <UTF8 string> 157b077aed3SPierre Pronchery 158b077aed3SPierre ProncherySupports the values "tpBasis" for a trinomial or "ppBasis" for a pentanomial. 159b077aed3SPierre ProncheryThis field is only used for a binary field F2^m. 160b077aed3SPierre Pronchery 161b077aed3SPierre Pronchery=item "m" (B<OSSL_PKEY_PARAM_EC_CHAR2_M>) <integer> 162b077aed3SPierre Pronchery 163b077aed3SPierre Pronchery=item "tp" (B<OSSL_PKEY_PARAM_EC_CHAR2_TP_BASIS>) <integer> 164b077aed3SPierre Pronchery 165b077aed3SPierre Pronchery=item "k1" (B<OSSL_PKEY_PARAM_EC_CHAR2_PP_K1>) <integer> 166b077aed3SPierre Pronchery 167b077aed3SPierre Pronchery=item "k2" (B<OSSL_PKEY_PARAM_EC_CHAR2_PP_K2>) <integer> 168b077aed3SPierre Pronchery 169b077aed3SPierre Pronchery=item "k3" (B<OSSL_PKEY_PARAM_EC_CHAR2_PP_K3>) <integer> 170b077aed3SPierre Pronchery 171b077aed3SPierre ProncheryThese fields are only used for a binary field F2^m. 172b077aed3SPierre ProncheryI<m> is the degree of the binary field. 173b077aed3SPierre Pronchery 174b077aed3SPierre ProncheryI<tp> is the middle bit of a trinomial so its value must be in the 175b077aed3SPierre Proncheryrange m > tp > 0. 176b077aed3SPierre Pronchery 177b077aed3SPierre ProncheryI<k1>, I<k2> and I<k3> are used to get the middle bits of a pentanomial such 178b077aed3SPierre Proncherythat m > k3 > k2 > k1 > 0 179b077aed3SPierre Pronchery 180b077aed3SPierre Pronchery=back 181b077aed3SPierre Pronchery 182b077aed3SPierre Pronchery=head2 EC key validation 183b077aed3SPierre Pronchery 184b077aed3SPierre ProncheryFor EC keys, L<EVP_PKEY_param_check(3)> behaves in the following way: 185b077aed3SPierre ProncheryFor the OpenSSL default provider it uses either 186b077aed3SPierre ProncheryL<EC_GROUP_check(3)> or L<EC_GROUP_check_named_curve(3)> depending on the flag 187b077aed3SPierre ProncheryEC_FLAG_CHECK_NAMED_GROUP. 188b077aed3SPierre ProncheryThe OpenSSL FIPS provider uses L<EC_GROUP_check_named_curve(3)> in order to 189b077aed3SPierre Proncheryconform to SP800-56Ar3 I<Assurances of Domain-Parameter Validity>. 190b077aed3SPierre Pronchery 191b077aed3SPierre ProncheryFor EC keys, L<EVP_PKEY_param_check_quick(3)> is equivalent to 192b077aed3SPierre ProncheryL<EVP_PKEY_param_check(3)>. 193b077aed3SPierre Pronchery 194b077aed3SPierre ProncheryFor EC keys, L<EVP_PKEY_public_check(3)> and L<EVP_PKEY_public_check_quick(3)> 195b077aed3SPierre Proncheryconform to SP800-56Ar3 I<ECC Full Public-Key Validation> and 196b077aed3SPierre ProncheryI<ECC Partial Public-Key Validation> respectively. 197b077aed3SPierre Pronchery 198b077aed3SPierre ProncheryFor EC Keys, L<EVP_PKEY_private_check(3)> and L<EVP_PKEY_pairwise_check(3)> 199b077aed3SPierre Proncheryconform to SP800-56Ar3 I<Private key validity> and 200b077aed3SPierre ProncheryI<Owner Assurance of Pair-wise Consistency> respectively. 201b077aed3SPierre Pronchery 202b077aed3SPierre Pronchery=head1 EXAMPLES 203b077aed3SPierre Pronchery 204b077aed3SPierre ProncheryAn B<EVP_PKEY> context can be obtained by calling: 205b077aed3SPierre Pronchery 206b077aed3SPierre Pronchery EVP_PKEY_CTX *pctx = 207b077aed3SPierre Pronchery EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); 208b077aed3SPierre Pronchery 209b077aed3SPierre ProncheryAn B<EVP_PKEY> ECDSA or ECDH key can be generated with a "P-256" named group by 210b077aed3SPierre Proncherycalling: 211b077aed3SPierre Pronchery 212b077aed3SPierre Pronchery pkey = EVP_EC_gen("P-256"); 213b077aed3SPierre Pronchery 214b077aed3SPierre Proncheryor like this: 215b077aed3SPierre Pronchery 216b077aed3SPierre Pronchery EVP_PKEY *key = NULL; 217b077aed3SPierre Pronchery OSSL_PARAM params[2]; 218b077aed3SPierre Pronchery EVP_PKEY_CTX *gctx = 219b077aed3SPierre Pronchery EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); 220b077aed3SPierre Pronchery 221b077aed3SPierre Pronchery EVP_PKEY_keygen_init(gctx); 222b077aed3SPierre Pronchery 223b077aed3SPierre Pronchery params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, 224b077aed3SPierre Pronchery "P-256", 0); 225b077aed3SPierre Pronchery params[1] = OSSL_PARAM_construct_end(); 226b077aed3SPierre Pronchery EVP_PKEY_CTX_set_params(gctx, params); 227b077aed3SPierre Pronchery 228b077aed3SPierre Pronchery EVP_PKEY_generate(gctx, &key); 229b077aed3SPierre Pronchery 230b077aed3SPierre Pronchery EVP_PKEY_print_private(bio_out, key, 0, NULL); 231b077aed3SPierre Pronchery ... 232b077aed3SPierre Pronchery EVP_PKEY_free(key); 233b077aed3SPierre Pronchery EVP_PKEY_CTX_free(gctx); 234b077aed3SPierre Pronchery 235b077aed3SPierre ProncheryAn B<EVP_PKEY> EC CDH (Cofactor Diffie-Hellman) key can be generated with a 236b077aed3SPierre Pronchery"K-571" named group by calling: 237b077aed3SPierre Pronchery 238b077aed3SPierre Pronchery int use_cdh = 1; 239b077aed3SPierre Pronchery EVP_PKEY *key = NULL; 240b077aed3SPierre Pronchery OSSL_PARAM params[3]; 241b077aed3SPierre Pronchery EVP_PKEY_CTX *gctx = 242b077aed3SPierre Pronchery EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); 243b077aed3SPierre Pronchery 244b077aed3SPierre Pronchery EVP_PKEY_keygen_init(gctx); 245b077aed3SPierre Pronchery 246b077aed3SPierre Pronchery params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, 247b077aed3SPierre Pronchery "K-571", 0); 248b077aed3SPierre Pronchery /* 249b077aed3SPierre Pronchery * This curve has a cofactor that is not 1 - so setting CDH mode changes 250b077aed3SPierre Pronchery * the behaviour. For many curves the cofactor is 1 - so setting this has 251b077aed3SPierre Pronchery * no effect. 252b077aed3SPierre Pronchery */ 253b077aed3SPierre Pronchery params[1] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH, 254b077aed3SPierre Pronchery &use_cdh); 255b077aed3SPierre Pronchery params[2] = OSSL_PARAM_construct_end(); 256b077aed3SPierre Pronchery EVP_PKEY_CTX_set_params(gctx, params); 257b077aed3SPierre Pronchery 258b077aed3SPierre Pronchery EVP_PKEY_generate(gctx, &key); 259b077aed3SPierre Pronchery EVP_PKEY_print_private(bio_out, key, 0, NULL); 260b077aed3SPierre Pronchery ... 261b077aed3SPierre Pronchery EVP_PKEY_free(key); 262b077aed3SPierre Pronchery EVP_PKEY_CTX_free(gctx); 263b077aed3SPierre Pronchery 264b077aed3SPierre Pronchery=head1 SEE ALSO 265b077aed3SPierre Pronchery 266b077aed3SPierre ProncheryL<EVP_EC_gen(3)>, 267b077aed3SPierre ProncheryL<EVP_KEYMGMT(3)>, 268b077aed3SPierre ProncheryL<EVP_PKEY(3)>, 269b077aed3SPierre ProncheryL<provider-keymgmt(7)>, 270b077aed3SPierre ProncheryL<EVP_SIGNATURE-ECDSA(7)>, 271b077aed3SPierre ProncheryL<EVP_KEYEXCH-ECDH(7)> 272b077aed3SPierre Pronchery 273b077aed3SPierre Pronchery=head1 COPYRIGHT 274b077aed3SPierre Pronchery 275b077aed3SPierre ProncheryCopyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved. 276b077aed3SPierre Pronchery 277b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 278b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 279b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 280b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 281b077aed3SPierre Pronchery 282b077aed3SPierre Pronchery=cut 283