=pod =head1 NAME EVP_PKEY-EC, EVP_KEYMGMT-EC - EVP_PKEY EC keytype and algorithm support =head1 DESCRIPTION The B keytype is implemented in OpenSSL's default provider. =head2 Common EC parameters The normal way of specifying domain parameters for an EC curve is via the curve name "group". For curves with no curve name, explicit parameters can be used that specify "field-type", "p", "a", "b", "generator" and "order". Explicit parameters are supported for backwards compability reasons, but they are not compliant with multiple standards (including RFC5915) which only allow named curves. The following KeyGen/Gettable/Import/Export types are available for the built-in EC algorithm: =over 4 =item "group" (B) The curve name. =item "field-type" (B) The value should be either "prime-field" or "characteristic-two-field", which correspond to prime field Fp and binary field F2^m. =item "p" (B) For a curve over Fp I

is the prime for the field. For a curve over F2^m I

represents the irreducible polynomial - each bit represents a term in the polynomial. Therefore, there will either be three or five bits set dependent on whether the polynomial is a trinomial or a pentanomial. =item "a" (B) =item "b" (B) =item "seed" (B) I and I represents the coefficients of the curve For Fp: y^2 mod p = x^3 +ax + b mod p OR For F2^m: y^2 + xy = x^3 + ax^2 + b I is an optional value that is for information purposes only. It represents the random number seed used to generate the coefficient I from a random number. =item "generator" (B) =item "order" (B) =item "cofactor" (B) The I is a well defined point on the curve chosen for cryptographic operations. The encoding conforms with Sec. 2.3.3 of the SECG SEC 1 ("Elliptic Curve Cryptography") standard. See EC_POINT_oct2point(). Integers used for point multiplications will be between 0 and I - 1. I is an optional value. I multiplied by the I gives the number of points on the curve. =item "decoded-from-explicit" (B) Gets a flag indicating wether the key or parameters were decoded from explicit curve parameters. Set to 1 if so or 0 if a named curve was used. =item "use-cofactor-flag" (B) Enable Cofactor DH (ECC CDH) if this value is 1, otherwise it uses normal EC DH if the value is zero. The cofactor variant multiplies the shared secret by the EC curve's cofactor (note for some curves the cofactor is 1). =item "encoding" (B) Set the format used for serializing the EC group parameters. Valid values are "explicit" or "named_curve". The default value is "named_curve". =item "point-format" (B) Sets or gets the point_conversion_form for the I. For a description of point_conversion_forms please see L. Valid values are "uncompressed" or "compressed". The default value is "uncompressed". =item "group-check" (B) Sets or Gets the type of group check done when EVP_PKEY_param_check() is called. Valid values are "default", "named" and "named-nist". The "named" type checks that the domain parameters match the inbuilt curve parameters, "named-nist" is similiar but also checks that the named curve is a nist curve. The "default" type does domain parameter validation for the OpenSSL default provider, but is equivalent to "named-nist" for the OpenSSL fips provider. =item "include-public" (B) Setting this value to 0 indicates that the public key should not be included when encoding the private key. The default value of 1 will include the public key. See also L for the related B parameter that can be set on a per-operation basis. =item "pub" (B) The public key value in EC point format. =item "priv" (B) The private key value. =item "encoded-pub-key" (B) Used for getting and setting the encoding of an EC public key. The public key is expected to be a point conforming to Sec. 2.3.4 of the SECG SEC 1 ("Elliptic Curve Cryptography") standard. =item "qx" (B) Used for getting the EC public key X component. =item "qy" (B) Used for getting the EC public key Y component. =item (B) Getter that returns the default digest name. (Currently returns "SHA256" as of OpenSSL 3.0). =back The following Gettable types are also available for the built-in EC algorithm: =over 4 =item "basis-type" (B) Supports the values "tpBasis" for a trinomial or "ppBasis" for a pentanomial. This field is only used for a binary field F2^m. =item "m" (B) =item "tp" (B) =item "k1" (B) =item "k2" (B) =item "k3" (B) These fields are only used for a binary field F2^m. I is the degree of the binary field. I is the middle bit of a trinomial so its value must be in the range m > tp > 0. I, I and I are used to get the middle bits of a pentanomial such that m > k3 > k2 > k1 > 0 =back =head1 EXAMPLES An B context can be obtained by calling: EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); An B ECDSA or ECDH key can be generated with a "P-256" named group by calling: pkey = EVP_EC_gen("P-256"); or like this: EVP_PKEY *key = NULL; OSSL_PARAM params[2]; EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); EVP_PKEY_keygen_init(gctx); params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, "P-256", 0); params[1] = OSSL_PARAM_construct_end(); EVP_PKEY_CTX_set_params(gctx, params); EVP_PKEY_generate(gctx, &key); EVP_PKEY_print_private(bio_out, key, 0, NULL); ... EVP_PKEY_free(key); EVP_PKEY_CTX_free(gctx); An B EC CDH (Cofactor Diffie-Hellman) key can be generated with a "K-571" named group by calling: int use_cdh = 1; EVP_PKEY *key = NULL; OSSL_PARAM params[3]; EVP_PKEY_CTX *gctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL); EVP_PKEY_keygen_init(gctx); params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, "K-571", 0); /* * This curve has a cofactor that is not 1 - so setting CDH mode changes * the behaviour. For many curves the cofactor is 1 - so setting this has * no effect. */ params[1] = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_USE_COFACTOR_ECDH, &use_cdh); params[2] = OSSL_PARAM_construct_end(); EVP_PKEY_CTX_set_params(gctx, params); EVP_PKEY_generate(gctx, &key); EVP_PKEY_print_private(bio_out, key, 0, NULL); ... EVP_PKEY_free(key); EVP_PKEY_CTX_free(gctx); =head1 SEE ALSO L, L, L, L, L, L =head1 COPYRIGHT Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut