Scroll to navigation

EC_KEY_NEW(3) Library Functions Manual EC_KEY_NEW(3)

NAME

EC_KEY_new, EC_KEY_get_flags, EC_KEY_set_flags, EC_KEY_clear_flags, EC_KEY_new_by_curve_name, EC_KEY_free, EC_KEY_copy, EC_KEY_dup, EC_KEY_up_ref, EC_KEY_get0_group, EC_KEY_set_group, EC_KEY_get0_private_key, EC_KEY_set_private_key, EC_KEY_get0_public_key, EC_KEY_set_public_key, EC_KEY_get_enc_flags, EC_KEY_set_enc_flags, EC_KEY_get_conv_form, EC_KEY_set_conv_form, EC_KEY_set_asn1_flag, EC_KEY_precompute_mult, EC_KEY_generate_key, EC_KEY_check_key, EC_KEY_set_public_key_affine_coordinates, EC_KEY_print, EC_KEY_print_fpcreate, destroy and manipulate EC_KEY objects

SYNOPSIS

#include <openssl/ec.h>
#include <openssl/bn.h>

EC_KEY *
EC_KEY_new(void);

int
EC_KEY_get_flags(const EC_KEY *key);

void
EC_KEY_set_flags(EC_KEY *key, int flags);

void
EC_KEY_clear_flags(EC_KEY *key, int flags);

EC_KEY *
EC_KEY_new_by_curve_name(int nid);

void
EC_KEY_free(EC_KEY *key);

EC_KEY *
EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);

EC_KEY *
EC_KEY_dup(const EC_KEY *src);

int
EC_KEY_up_ref(EC_KEY *key);

const EC_GROUP *
EC_KEY_get0_group(const EC_KEY *key);

int
EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);

const BIGNUM *
EC_KEY_get0_private_key(const EC_KEY *key);

int
EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);

const EC_POINT *
EC_KEY_get0_public_key(const EC_KEY *key);

int
EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);

unsigned int
EC_KEY_get_enc_flags(const EC_KEY *key);

void
EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags);

point_conversion_form_t
EC_KEY_get_conv_form(const EC_KEY *key);

void
EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform);

void
EC_KEY_set_asn1_flag(EC_KEY *key, int asn1_flag);

int
EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx);

int
EC_KEY_generate_key(EC_KEY *key);

int
EC_KEY_check_key(const EC_KEY *key);

int
EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y);

int
EC_KEY_print(BIO *bp, const EC_KEY *key, int off);

int
EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);

DESCRIPTION

An EC_KEY represents a public key and (optionally) an associated private key. The public key is a point on a curve represented by an EC_POINT, see EC_POINT_new(3). The private key is simply a BIGNUM, see BN_new(3).

A new EC_KEY (with no associated curve) can be constructed by calling (). The reference count for the newly created EC_KEY is initially set to 1. A curve can be associated with the EC_KEY by calling ().

Alternatively a new EC_KEY can be constructed by calling () and supplying the nid of the associated curve. Refer to EC_GROUP_new(3) for a description of curve names. This function simply wraps calls to EC_KEY_new() and ().

Calling () decrements the reference count for the EC_KEY object and, if it has dropped to zero, then frees the memory associated with it. If key is a NULL pointer, no action occurs.

() copies the contents of the EC_KEY in src into dst.

() creates a new EC_KEY object and copies src into it.

() increments the reference count associated with the EC_KEY object.

() generates a new public and private key for the supplied key object. key must have an EC_GROUP object associated with it before calling this function. The private key is a random integer (0 < priv_key < order, where order is the order of the EC_GROUP object). The public key is an EC_POINT on the curve calculated by multiplying the generator for the curve by the private key.

() performs various sanity checks on the EC_KEY object to confirm that it is valid.

() sets the public key for key based on its affine coordinates, i.e. it constructs an EC_POINT object based on the supplied x and y values and sets the public key to be this EC_POINT. It also performs certain sanity checks on the key to confirm that it is valid.

The functions (), (), (), (), (), and () get and set the EC_GROUP object, the private key and the EC_POINT public key for the key, respectively. The setters copy the group and key objects without sanity checks and it is the caller's responsibility to ensure that the resulting key is valid, for example using EC_KEY_check_key().

The functions () and () get and set the value of the encoding flags for the key. There are two encoding flags currently defined: EC_PKEY_NO_PARAMETERS and EC_PKEY_NO_PUBKEY. These flags define the behaviour of how the key is converted into ASN.1 in a call to (). If EC_PKEY_NO_PARAMETERS is set then the public parameters for the curve are not encoded along with the private key. If EC_PKEY_NO_PUBKEY is set then the public key is not encoded along with the private key.

The format of the external representation of the public key written by i2d_ECPrivateKey(3), such as whether it is stored in a compressed form or not, is described by the point_conversion_form. See EC_GROUP_copy(3) for a description of point_conversion_form.

When reading a private key encoded without an associated public key, for example if EC_PKEY_NO_PUBKEY was used, d2i_ECPrivateKey(3) generates the missing public key automatically. Private keys encoded without parameters, for example if EC_PKEY_NO_PARAMETERS was used, cannot be loaded using d2i_ECPrivateKey(3).

The functions () and () get and set the point_conversion_form for the key. For a description of point_conversion_form refer to EC_GROUP_copy(3).

() sets the flags in the flags parameter on the EC_KEY object. Any flags that are already set are left set. The currently defined standard flags are EC_FLAG_NON_FIPS_ALLOW and EC_FLAG_FIPS_CHECKED. In addition there is the ECDH-specific flag EC_FLAG_COFACTOR_ECDH. () returns the current flags that are set for this EC_KEY. () clears the flags indicated by the flags parameter. All other flags are left in their existing state.

() sets the asn1_flag on the underlying EC_GROUP object (if set). Refer to EC_GROUP_copy(3) for further information on the asn1_flag.

() stores multiples of the underlying EC_GROUP generator for faster point multiplication. See also EC_POINT_add(3).

() and () print out the content of key to the BIO bp or to the FILE pointer fp, respectively. Each line is indented by indent spaces.

RETURN VALUES

EC_KEY_new(), EC_KEY_new_by_curve_name(), and EC_KEY_dup() return a pointer to the newly created EC_KEY object or NULL on error.

EC_KEY_get_flags() returns the flags associated with the EC_KEY object.

EC_KEY_copy() returns a pointer to the destination key or NULL on error. In the latter case, part of the content may already have been copied.

EC_KEY_up_ref(), EC_KEY_set_group(), EC_KEY_set_private_key(), EC_KEY_set_public_key(), EC_KEY_precompute_mult(), EC_KEY_generate_key(), EC_KEY_check_key(), EC_KEY_set_public_key_affine_coordinates(), EC_KEY_print(), and EC_KEY_print_fp() return 1 on success or 0 on error.

EC_KEY_get0_group() returns the EC_GROUP associated with the EC_KEY.

EC_KEY_get0_private_key() and EC_KEY_get0_public_key() return the private or public keys, respectively, associated with the EC_KEY.

EC_KEY_get_enc_flags() returns the value of the current encoding flags for the EC_KEY.

EC_KEY_get_conv_form() returns the point_conversion_form for the EC_KEY.

SEE ALSO

d2i_ECPKParameters(3), EC_GFp_simple_method(3), EC_GROUP_copy(3), EC_GROUP_new(3), EC_KEY_METHOD_new(3), EC_POINT_add(3), EC_POINT_new(3), ECDH_compute_key(3), ECDSA_SIG_new(3), EVP_PKEY_set1_EC_KEY(3)

HISTORY

EC_KEY_new(), EC_KEY_new_by_curve_name(), EC_KEY_free(), EC_KEY_copy(), EC_KEY_dup(), EC_KEY_up_ref(), EC_KEY_get0_group(), EC_KEY_set_group(), EC_KEY_get0_private_key(), EC_KEY_set_private_key(), EC_KEY_get0_public_key(), EC_KEY_set_public_key(), EC_KEY_get_enc_flags(), EC_KEY_set_enc_flags(), EC_KEY_get_conv_form(), EC_KEY_set_conv_form(), EC_KEY_set_asn1_flag(), EC_KEY_precompute_mult(), EC_KEY_generate_key(), EC_KEY_check_key(), EC_KEY_print(), and EC_KEY_print_fp() first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5.

EC_KEY_get_flags(), EC_KEY_set_flags(), EC_KEY_clear_flags(), and EC_KEY_set_public_key_affine_coordinates() first appeared in OpenSSL 1.0.1 and have been available since OpenBSD 5.3.

July 14, 2024 Linux 6.4.0-150600.23.25-default