# phpman > man > EVP_PKEY-EC(7)

[EVP_PKEY-EC(7SSL)](https://www.chedong.com/phpMan.php/man/EVPPKEY-EC/7SSL/markdown)                              OpenSSL                             [EVP_PKEY-EC(7SSL)](https://www.chedong.com/phpMan.php/man/EVPPKEY-EC/7SSL/markdown)



## NAME
       EVP_PKEY-EC, EVP_KEYMGMT-EC - EVP_PKEY EC keytype and algorithm support

## DESCRIPTION
       The **EC** keytype is implemented in OpenSSL's default provider.

### 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:

       "group" (**OSSL**___**PKEY**___**PARAM**___**GROUP**___**NAME**) <UTF8 string>
           The curve name.

       "field-type" (**OSSL**___**PKEY**___**PARAM**___**EC**___**FIELD**___**TYPE**) <UTF8 string>
           The value should be either "prime-field" or "characteristic-two-field", which correspond
           to prime field Fp and binary field F2^m.

       "p" (**OSSL**___**PKEY**___**PARAM**___**EC**___**P**) <unsigned integer>
           For a curve over Fp _p_ is the prime for the field. For a curve over F2^m _p_ 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.

       "a" (**OSSL**___**PKEY**___**PARAM**___**EC**___**A**) <unsigned integer>
       "b" (**OSSL**___**PKEY**___**PARAM**___**EC**___**B**) <unsigned integer>
       "seed" (**OSSL**___**PKEY**___**PARAM**___**EC**___**SEED**) <octet string>
           _a_ and _b_ 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

           _seed_ is an optional value that is for information purposes only.  It represents the
           random number seed used to generate the coefficient _b_ from a random number.

       "generator" (**OSSL**___**PKEY**___**PARAM**___**EC**___**GENERATOR**) <octet string>
       "order" (**OSSL**___**PKEY**___**PARAM**___**EC**___**ORDER**) <unsigned integer>
       "cofactor" (**OSSL**___**PKEY**___**PARAM**___**EC**___**COFACTOR**) <unsigned integer>
           The _generator_ 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 _order_ - 1.  _cofactor_ is an optional value.  _order_ multiplied by the
           _cofactor_ gives the number of points on the curve.

       "decoded-from-explicit" (**OSSL**___**PKEY**___**PARAM**___**EC**___**DECODED**___**FROM**___**EXPLICIT**___**PARAMS**) <integer>
           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.

       "use-cofactor-flag" (**OSSL**___**PKEY**___**PARAM**___**USE**___**COFACTOR**___**ECDH**) <integer>
           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).

       "encoding" (**OSSL**___**PKEY**___**PARAM**___**EC**___**ENCODING**) <UTF8 string>
           Set the format used for serializing the EC group parameters.  Valid values are "explicit"
           or "named_curve". The default value is "named_curve".

       "point-format" (**OSSL**___**PKEY**___**PARAM**___**EC**___**POINT**___**CONVERSION**___**FORMAT**) <UTF8 string>
           Sets or gets the point_conversion_form for the _key_. For a description of
           point_conversion_forms please see **EC**___**POINT**___**[new**(3)](https://www.chedong.com/phpMan.php/man/new/3/markdown). Valid values are "uncompressed" or
           "compressed". The default value is "uncompressed".

       "group-check" (**OSSL**___**PKEY**___**PARAM**___**EC**___**GROUP**___**CHECK**___**TYPE**) <UTF8 string>
           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.

       "include-public" (**OSSL**___**PKEY**___**PARAM**___**EC**___**INCLUDE**___**PUBLIC**) <integer>
           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 **EVP**___**[KEYEXCH-ECDH**(7)](https://www.chedong.com/phpMan.php/man/KEYEXCH-ECDH/7/markdown) for the related **OSSL**___**EXCHANGE**___**PARAM**___**EC**___**ECDH**___**COFACTOR**___**MODE**
           parameter that can be set on a per-operation basis.

       "pub" (**OSSL**___**PKEY**___**PARAM**___**PUB**___**KEY**) <octet string>
           The public key value in EC point format.

       "priv" (**OSSL**___**PKEY**___**PARAM**___**PRIV**___**KEY**) <unsigned integer>
           The private key value.

       "encoded-pub-key" (**OSSL**___**PKEY**___**PARAM**___**ENCODED**___**PUBLIC**___**KEY**) <octet string>
           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.

       "qx" (**OSSL**___**PKEY**___**PARAM**___**EC**___**PUB**___**X**) <unsigned integer>
           Used for getting the EC public key X component.

       "qy" (**OSSL**___**PKEY**___**PARAM**___**EC**___**PUB**___**Y**) <unsigned integer>
           Used for getting the EC public key Y component.

       (**OSSL**___**PKEY**___**PARAM**___**DEFAULT**___**DIGEST**) <UTF8 string>
           Getter that returns the default digest name.  (Currently returns "SHA256" as of OpenSSL
           3.0).

       The following Gettable types are also available for the built-in EC algorithm:

       "basis-type" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**TYPE**) <UTF8 string>
           Supports the values "tpBasis" for a trinomial or "ppBasis" for a pentanomial.  This field
           is only used for a binary field F2^m.

       "m" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**M**) <integer>
       "tp" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**TP**___**BASIS**) <integer>
       "k1" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**PP**___**K1**) <integer>
       "k2" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**PP**___**K2**) <integer>
       "k3" (**OSSL**___**PKEY**___**PARAM**___**EC**___**CHAR2**___**PP**___**K3**) <integer>
           These fields are only used for a binary field F2^m.  _m_ is the degree of the binary field.

           _tp_ is the middle bit of a trinomial so its value must be in the range m > tp > 0.

           _k1_, _k2_ and _k3_ are used to get the middle bits of a pentanomial such that m > k3 > k2 > k1
           > 0

## EXAMPLES
       An **EVP**___**PKEY** context can be obtained by calling:

           EVP_PKEY_CTX *pctx =
               EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);

       An **EVP**___**PKEY** 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 **EVP**___**PKEY** 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);

## SEE ALSO
       **EVP**___**EC**___**[gen**(3)](https://www.chedong.com/phpMan.php/man/gen/3/markdown), **EVP**___**[KEYMGMT**(3)](https://www.chedong.com/phpMan.php/man/KEYMGMT/3/markdown), **EVP**___**[PKEY**(3)](https://www.chedong.com/phpMan.php/man/PKEY/3/markdown), [**provider-keymgmt**(7)](https://www.chedong.com/phpMan.php/man/provider-keymgmt/7/markdown), **EVP**___**[SIGNATURE-ECDSA**(7)](https://www.chedong.com/phpMan.php/man/SIGNATURE-ECDSA/7/markdown),
       **EVP**___**[KEYEXCH-ECDH**(7)](https://www.chedong.com/phpMan.php/man/KEYEXCH-ECDH/7/markdown)

## 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 <<https://www.openssl.org/source/license.html>>.



3.0.2                                        2026-04-07                            [EVP_PKEY-EC(7SSL)](https://www.chedong.com/phpMan.php/man/EVPPKEY-EC/7SSL/markdown)
