1*4724848cSchristos=pod 2*4724848cSchristos 3*4724848cSchristos=head1 NAME 4*4724848cSchristos 5*4724848cSchristosEC_KEY_get_method, EC_KEY_set_method, 6*4724848cSchristosEC_KEY_new, EC_KEY_get_flags, EC_KEY_set_flags, EC_KEY_clear_flags, 7*4724848cSchristosEC_KEY_new_by_curve_name, EC_KEY_free, EC_KEY_copy, EC_KEY_dup, EC_KEY_up_ref, 8*4724848cSchristosEC_KEY_get0_engine, 9*4724848cSchristosEC_KEY_get0_group, EC_KEY_set_group, EC_KEY_get0_private_key, 10*4724848cSchristosEC_KEY_set_private_key, EC_KEY_get0_public_key, EC_KEY_set_public_key, 11*4724848cSchristosEC_KEY_get_conv_form, 12*4724848cSchristosEC_KEY_set_conv_form, EC_KEY_set_asn1_flag, 13*4724848cSchristosEC_KEY_decoded_from_explicit_params, EC_KEY_precompute_mult, 14*4724848cSchristosEC_KEY_generate_key, EC_KEY_check_key, EC_KEY_set_public_key_affine_coordinates, 15*4724848cSchristosEC_KEY_oct2key, EC_KEY_key2buf, EC_KEY_oct2priv, EC_KEY_priv2oct, 16*4724848cSchristosEC_KEY_priv2buf - Functions for creating, destroying and manipulating 17*4724848cSchristosEC_KEY objects 18*4724848cSchristos 19*4724848cSchristos=head1 SYNOPSIS 20*4724848cSchristos 21*4724848cSchristos #include <openssl/ec.h> 22*4724848cSchristos 23*4724848cSchristos EC_KEY *EC_KEY_new(void); 24*4724848cSchristos int EC_KEY_get_flags(const EC_KEY *key); 25*4724848cSchristos void EC_KEY_set_flags(EC_KEY *key, int flags); 26*4724848cSchristos void EC_KEY_clear_flags(EC_KEY *key, int flags); 27*4724848cSchristos EC_KEY *EC_KEY_new_by_curve_name(int nid); 28*4724848cSchristos void EC_KEY_free(EC_KEY *key); 29*4724848cSchristos EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src); 30*4724848cSchristos EC_KEY *EC_KEY_dup(const EC_KEY *src); 31*4724848cSchristos int EC_KEY_up_ref(EC_KEY *key); 32*4724848cSchristos ENGINE *EC_KEY_get0_engine(const EC_KEY *eckey); 33*4724848cSchristos const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key); 34*4724848cSchristos int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group); 35*4724848cSchristos const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key); 36*4724848cSchristos int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key); 37*4724848cSchristos const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key); 38*4724848cSchristos int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub); 39*4724848cSchristos point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key); 40*4724848cSchristos void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform); 41*4724848cSchristos void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); 42*4724848cSchristos int EC_KEY_decoded_from_explicit_params(const EC_KEY *key); 43*4724848cSchristos int EC_KEY_precompute_mult(EC_KEY *key, BN_CTX *ctx); 44*4724848cSchristos int EC_KEY_generate_key(EC_KEY *key); 45*4724848cSchristos int EC_KEY_check_key(const EC_KEY *key); 46*4724848cSchristos int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x, BIGNUM *y); 47*4724848cSchristos const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key); 48*4724848cSchristos int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth); 49*4724848cSchristos 50*4724848cSchristos int EC_KEY_oct2key(EC_KEY *eckey, const unsigned char *buf, size_t len, BN_CTX *ctx); 51*4724848cSchristos size_t EC_KEY_key2buf(const EC_KEY *eckey, point_conversion_form_t form, 52*4724848cSchristos unsigned char **pbuf, BN_CTX *ctx); 53*4724848cSchristos 54*4724848cSchristos int EC_KEY_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len); 55*4724848cSchristos size_t EC_KEY_priv2oct(const EC_KEY *eckey, unsigned char *buf, size_t len); 56*4724848cSchristos 57*4724848cSchristos size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf); 58*4724848cSchristos 59*4724848cSchristos=head1 DESCRIPTION 60*4724848cSchristos 61*4724848cSchristosAn EC_KEY represents a public key and, optionally, the associated private 62*4724848cSchristoskey. A new EC_KEY with no associated curve can be constructed by calling 63*4724848cSchristosEC_KEY_new(). The reference count for the newly created EC_KEY is initially 64*4724848cSchristosset to 1. A curve can be associated with the EC_KEY by calling 65*4724848cSchristosEC_KEY_set_group(). 66*4724848cSchristos 67*4724848cSchristosAlternatively a new EC_KEY can be constructed by calling 68*4724848cSchristosEC_KEY_new_by_curve_name() and supplying the nid of the associated curve. See 69*4724848cSchristosL<EC_GROUP_new(3)> for a description of curve names. This function simply 70*4724848cSchristoswraps calls to EC_KEY_new() and EC_GROUP_new_by_curve_name(). 71*4724848cSchristos 72*4724848cSchristosCalling EC_KEY_free() decrements the reference count for the EC_KEY object, 73*4724848cSchristosand if it has dropped to zero then frees the memory associated with it. If 74*4724848cSchristosB<key> is NULL nothing is done. 75*4724848cSchristos 76*4724848cSchristosEC_KEY_copy() copies the contents of the EC_KEY in B<src> into B<dest>. 77*4724848cSchristos 78*4724848cSchristosEC_KEY_dup() creates a new EC_KEY object and copies B<ec_key> into it. 79*4724848cSchristos 80*4724848cSchristosEC_KEY_up_ref() increments the reference count associated with the EC_KEY 81*4724848cSchristosobject. 82*4724848cSchristos 83*4724848cSchristosEC_KEY_get0_engine() returns a handle to the ENGINE that has been set for 84*4724848cSchristosthis EC_KEY object. 85*4724848cSchristos 86*4724848cSchristosEC_KEY_generate_key() generates a new public and private key for the supplied 87*4724848cSchristosB<eckey> object. B<eckey> must have an EC_GROUP object associated with it 88*4724848cSchristosbefore calling this function. The private key is a random integer (0 < priv_key 89*4724848cSchristos< order, where I<order> is the order of the EC_GROUP object). The public key is 90*4724848cSchristosan EC_POINT on the curve calculated by multiplying the generator for the 91*4724848cSchristoscurve by the private key. 92*4724848cSchristos 93*4724848cSchristosEC_KEY_check_key() performs various sanity checks on the EC_KEY object to 94*4724848cSchristosconfirm that it is valid. 95*4724848cSchristos 96*4724848cSchristosEC_KEY_set_public_key_affine_coordinates() sets the public key for B<key> based 97*4724848cSchristoson its affine co-ordinates; i.e., it constructs an EC_POINT object based on 98*4724848cSchristosthe supplied B<x> and B<y> values and sets the public key to be this 99*4724848cSchristosEC_POINT. It also performs certain sanity checks on the key to confirm 100*4724848cSchristosthat it is valid. 101*4724848cSchristos 102*4724848cSchristosThe functions EC_KEY_get0_group(), EC_KEY_set_group(), 103*4724848cSchristosEC_KEY_get0_private_key(), EC_KEY_set_private_key(), EC_KEY_get0_public_key(), 104*4724848cSchristosand EC_KEY_set_public_key() get and set the EC_GROUP object, the private key, 105*4724848cSchristosand the EC_POINT public key for the B<key> respectively. The function 106*4724848cSchristosEC_KEY_set_private_key() accepts NULL as the priv_key argument to securely clear 107*4724848cSchristosthe private key component from the EC_KEY. 108*4724848cSchristos 109*4724848cSchristosThe functions EC_KEY_get_conv_form() and EC_KEY_set_conv_form() get and set the 110*4724848cSchristospoint_conversion_form for the B<key>. For a description of 111*4724848cSchristospoint_conversion_forms please see L<EC_POINT_new(3)>. 112*4724848cSchristos 113*4724848cSchristosEC_KEY_set_flags() sets the flags in the B<flags> parameter on the EC_KEY 114*4724848cSchristosobject. Any flags that are already set are left set. The flags currently 115*4724848cSchristosdefined are EC_FLAG_NON_FIPS_ALLOW and EC_FLAG_FIPS_CHECKED. In 116*4724848cSchristosaddition there is the flag EC_FLAG_COFACTOR_ECDH which is specific to ECDH. 117*4724848cSchristosEC_KEY_get_flags() returns the current flags that are set for this EC_KEY. 118*4724848cSchristosEC_KEY_clear_flags() clears the flags indicated by the B<flags> parameter; all 119*4724848cSchristosother flags are left in their existing state. 120*4724848cSchristos 121*4724848cSchristosEC_KEY_set_asn1_flag() sets the asn1_flag on the underlying EC_GROUP object 122*4724848cSchristos(if set). Refer to L<EC_GROUP_copy(3)> for further information on the 123*4724848cSchristosasn1_flag. 124*4724848cSchristos 125*4724848cSchristosEC_KEY_decoded_from_explicit_params() returns 1 if the group of the I<key> was 126*4724848cSchristosdecoded from data with explicitly encoded group parameters, -1 if the I<key> 127*4724848cSchristosis NULL or the group parameters are missing, and 0 otherwise. 128*4724848cSchristos 129*4724848cSchristosEC_KEY_precompute_mult() stores multiples of the underlying EC_GROUP generator 130*4724848cSchristosfor faster point multiplication. See also L<EC_POINT_add(3)>. 131*4724848cSchristos 132*4724848cSchristosEC_KEY_oct2key() and EC_KEY_key2buf() are identical to the functions 133*4724848cSchristosEC_POINT_oct2point() and EC_POINT_point2buf() except they use the public key 134*4724848cSchristosEC_POINT in B<eckey>. 135*4724848cSchristos 136*4724848cSchristosEC_KEY_oct2priv() and EC_KEY_priv2oct() convert between the private key 137*4724848cSchristoscomponent of B<eckey> and octet form. The octet form consists of the content 138*4724848cSchristosoctets of the B<privateKey> OCTET STRING in an B<ECPrivateKey> ASN.1 structure. 139*4724848cSchristos 140*4724848cSchristosThe function EC_KEY_priv2oct() must be supplied with a buffer long enough to 141*4724848cSchristosstore the octet form. The return value provides the number of octets stored. 142*4724848cSchristosCalling the function with a NULL buffer will not perform the conversion but 143*4724848cSchristoswill just return the required buffer length. 144*4724848cSchristos 145*4724848cSchristosThe function EC_KEY_priv2buf() allocates a buffer of suitable length and writes 146*4724848cSchristosan EC_KEY to it in octet format. The allocated buffer is written to B<*pbuf> 147*4724848cSchristosand its length is returned. The caller must free up the allocated buffer with a 148*4724848cSchristoscall to OPENSSL_free(). Since the allocated buffer value is written to B<*pbuf> 149*4724848cSchristosthe B<pbuf> parameter B<MUST NOT> be B<NULL>. 150*4724848cSchristos 151*4724848cSchristosEC_KEY_priv2buf() converts an EC_KEY private key into an allocated buffer. 152*4724848cSchristos 153*4724848cSchristos=head1 RETURN VALUES 154*4724848cSchristos 155*4724848cSchristosEC_KEY_new(), EC_KEY_new_by_curve_name() and EC_KEY_dup() return a pointer to 156*4724848cSchristosthe newly created EC_KEY object, or NULL on error. 157*4724848cSchristos 158*4724848cSchristosEC_KEY_get_flags() returns the flags associated with the EC_KEY object as an 159*4724848cSchristosinteger. 160*4724848cSchristos 161*4724848cSchristosEC_KEY_copy() returns a pointer to the destination key, or NULL on error. 162*4724848cSchristos 163*4724848cSchristosEC_KEY_get0_engine() returns a pointer to an ENGINE, or NULL if it wasn't set. 164*4724848cSchristos 165*4724848cSchristosEC_KEY_up_ref(), EC_KEY_set_group(), EC_KEY_set_public_key(), 166*4724848cSchristosEC_KEY_precompute_mult(), EC_KEY_generate_key(), EC_KEY_check_key(), 167*4724848cSchristosEC_KEY_set_public_key_affine_coordinates(), EC_KEY_oct2key() and 168*4724848cSchristosEC_KEY_oct2priv() return 1 on success or 0 on error. 169*4724848cSchristos 170*4724848cSchristosEC_KEY_set_private_key() returns 1 on success or 0 on error except when the 171*4724848cSchristospriv_key argument is NULL, in that case it returns 0, for legacy compatibility, 172*4724848cSchristosand should not be treated as an error. 173*4724848cSchristos 174*4724848cSchristosEC_KEY_get0_group() returns the EC_GROUP associated with the EC_KEY. 175*4724848cSchristos 176*4724848cSchristosEC_KEY_get0_private_key() returns the private key associated with the EC_KEY. 177*4724848cSchristos 178*4724848cSchristosEC_KEY_get_conv_form() return the point_conversion_form for the EC_KEY. 179*4724848cSchristos 180*4724848cSchristosEC_KEY_key2buf(), EC_KEY_priv2oct() and EC_KEY_priv2buf() return the length 181*4724848cSchristosof the buffer or 0 on error. 182*4724848cSchristos 183*4724848cSchristos=head1 SEE ALSO 184*4724848cSchristos 185*4724848cSchristosL<crypto(7)>, L<EC_GROUP_new(3)>, 186*4724848cSchristosL<EC_GROUP_copy(3)>, L<EC_POINT_new(3)>, 187*4724848cSchristosL<EC_POINT_add(3)>, 188*4724848cSchristosL<EC_GFp_simple_method(3)>, 189*4724848cSchristosL<d2i_ECPKParameters(3)> 190*4724848cSchristos 191*4724848cSchristos=head1 COPYRIGHT 192*4724848cSchristos 193*4724848cSchristosCopyright 2013-2022 The OpenSSL Project Authors. All Rights Reserved. 194*4724848cSchristos 195*4724848cSchristosLicensed under the OpenSSL license (the "License"). You may not use 196*4724848cSchristosthis file except in compliance with the License. You can obtain a copy 197*4724848cSchristosin the file LICENSE in the source distribution or at 198*4724848cSchristosL<https://www.openssl.org/source/license.html>. 199*4724848cSchristos 200*4724848cSchristos=cut 201