1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimEC_POINT_set_Jprojective_coordinates_GFp, 6e71b7053SJung-uk KimEC_POINT_point2buf, 7e71b7053SJung-uk KimEC_POINT_new, 8e71b7053SJung-uk KimEC_POINT_free, 9e71b7053SJung-uk KimEC_POINT_clear_free, 10e71b7053SJung-uk KimEC_POINT_copy, 11e71b7053SJung-uk KimEC_POINT_dup, 12e71b7053SJung-uk KimEC_POINT_method_of, 13e71b7053SJung-uk KimEC_POINT_set_to_infinity, 14e71b7053SJung-uk KimEC_POINT_get_Jprojective_coordinates_GFp, 15e71b7053SJung-uk KimEC_POINT_set_affine_coordinates, 16e71b7053SJung-uk KimEC_POINT_get_affine_coordinates, 17e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates, 18e71b7053SJung-uk KimEC_POINT_set_affine_coordinates_GFp, 19e71b7053SJung-uk KimEC_POINT_get_affine_coordinates_GFp, 20e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates_GFp, 21e71b7053SJung-uk KimEC_POINT_set_affine_coordinates_GF2m, 22e71b7053SJung-uk KimEC_POINT_get_affine_coordinates_GF2m, 23e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates_GF2m, 24e71b7053SJung-uk KimEC_POINT_point2oct, 25e71b7053SJung-uk KimEC_POINT_oct2point, 26e71b7053SJung-uk KimEC_POINT_point2bn, 27e71b7053SJung-uk KimEC_POINT_bn2point, 28e71b7053SJung-uk KimEC_POINT_point2hex, 29e71b7053SJung-uk KimEC_POINT_hex2point 30e71b7053SJung-uk Kim- Functions for creating, destroying and manipulating EC_POINT objects 31e71b7053SJung-uk Kim 32e71b7053SJung-uk Kim=head1 SYNOPSIS 33e71b7053SJung-uk Kim 34e71b7053SJung-uk Kim #include <openssl/ec.h> 35e71b7053SJung-uk Kim 36e71b7053SJung-uk Kim EC_POINT *EC_POINT_new(const EC_GROUP *group); 37e71b7053SJung-uk Kim void EC_POINT_free(EC_POINT *point); 38e71b7053SJung-uk Kim void EC_POINT_clear_free(EC_POINT *point); 39e71b7053SJung-uk Kim int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); 40e71b7053SJung-uk Kim EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); 41e71b7053SJung-uk Kim int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); 42e71b7053SJung-uk Kim int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, 43e71b7053SJung-uk Kim const BIGNUM *x, const BIGNUM *y, 44e71b7053SJung-uk Kim BN_CTX *ctx); 45e71b7053SJung-uk Kim int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, 46e71b7053SJung-uk Kim BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 47e71b7053SJung-uk Kim int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, 48e71b7053SJung-uk Kim const BIGNUM *x, int y_bit, 49e71b7053SJung-uk Kim BN_CTX *ctx); 50*b077aed3SPierre Pronchery size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, 51*b077aed3SPierre Pronchery point_conversion_form_t form, 52*b077aed3SPierre Pronchery unsigned char *buf, size_t len, BN_CTX *ctx); 53*b077aed3SPierre Pronchery size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, 54*b077aed3SPierre Pronchery point_conversion_form_t form, 55*b077aed3SPierre Pronchery unsigned char **pbuf, BN_CTX *ctx); 56*b077aed3SPierre Pronchery int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, 57*b077aed3SPierre Pronchery const unsigned char *buf, size_t len, BN_CTX *ctx); 58*b077aed3SPierre Pronchery char *EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *p, 59*b077aed3SPierre Pronchery point_conversion_form_t form, BN_CTX *ctx); 60*b077aed3SPierre Pronchery EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, const char *hex, 61*b077aed3SPierre Pronchery EC_POINT *p, BN_CTX *ctx); 62*b077aed3SPierre Pronchery 63*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be 64*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 65*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>: 66*b077aed3SPierre Pronchery 67*b077aed3SPierre Pronchery const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); 68*b077aed3SPierre Pronchery int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, 69*b077aed3SPierre Pronchery EC_POINT *p, 70*b077aed3SPierre Pronchery const BIGNUM *x, const BIGNUM *y, 71*b077aed3SPierre Pronchery const BIGNUM *z, BN_CTX *ctx); 72*b077aed3SPierre Pronchery int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, 73*b077aed3SPierre Pronchery const EC_POINT *p, 74*b077aed3SPierre Pronchery BIGNUM *x, BIGNUM *y, BIGNUM *z, 75*b077aed3SPierre Pronchery BN_CTX *ctx); 76e71b7053SJung-uk Kim int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, 77e71b7053SJung-uk Kim const BIGNUM *x, const BIGNUM *y, 78e71b7053SJung-uk Kim BN_CTX *ctx); 79e71b7053SJung-uk Kim int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, 80e71b7053SJung-uk Kim const EC_POINT *p, 81e71b7053SJung-uk Kim BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 82e71b7053SJung-uk Kim int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, 83e71b7053SJung-uk Kim EC_POINT *p, 84e71b7053SJung-uk Kim const BIGNUM *x, int y_bit, 85e71b7053SJung-uk Kim BN_CTX *ctx); 86e71b7053SJung-uk Kim int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, 87e71b7053SJung-uk Kim const BIGNUM *x, const BIGNUM *y, 88e71b7053SJung-uk Kim BN_CTX *ctx); 89e71b7053SJung-uk Kim int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, 90e71b7053SJung-uk Kim const EC_POINT *p, 91e71b7053SJung-uk Kim BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 92e71b7053SJung-uk Kim int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, 93e71b7053SJung-uk Kim EC_POINT *p, 94e71b7053SJung-uk Kim const BIGNUM *x, int y_bit, 95e71b7053SJung-uk Kim BN_CTX *ctx); 96e71b7053SJung-uk Kim BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *p, 97e71b7053SJung-uk Kim point_conversion_form_t form, BIGNUM *bn, 98e71b7053SJung-uk Kim BN_CTX *ctx); 99e71b7053SJung-uk Kim EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn, 100e71b7053SJung-uk Kim EC_POINT *p, BN_CTX *ctx); 101e71b7053SJung-uk Kim 102e71b7053SJung-uk Kim=head1 DESCRIPTION 103e71b7053SJung-uk Kim 104e71b7053SJung-uk KimAn B<EC_POINT> structure represents a point on a curve. A new point is 105e71b7053SJung-uk Kimconstructed by calling the function EC_POINT_new() and providing the 106e71b7053SJung-uk KimB<group> object that the point relates to. 107e71b7053SJung-uk Kim 108e71b7053SJung-uk KimEC_POINT_free() frees the memory associated with the B<EC_POINT>. 109e71b7053SJung-uk Kimif B<point> is NULL nothing is done. 110e71b7053SJung-uk Kim 111e71b7053SJung-uk KimEC_POINT_clear_free() destroys any sensitive data held within the EC_POINT and 112e71b7053SJung-uk Kimthen frees its memory. If B<point> is NULL nothing is done. 113e71b7053SJung-uk Kim 114e71b7053SJung-uk KimEC_POINT_copy() copies the point B<src> into B<dst>. Both B<src> and B<dst> 115e71b7053SJung-uk Kimmust use the same B<EC_METHOD>. 116e71b7053SJung-uk Kim 117e71b7053SJung-uk KimEC_POINT_dup() creates a new B<EC_POINT> object and copies the content from 118e71b7053SJung-uk KimB<src> to the newly created B<EC_POINT> object. 119e71b7053SJung-uk Kim 120e71b7053SJung-uk KimEC_POINT_method_of() obtains the B<EC_METHOD> associated with B<point>. 121*b077aed3SPierre ProncheryThis function was deprecated in OpenSSL 3.0, since EC_METHOD is no longer a 122*b077aed3SPierre Proncherypublic concept. 123e71b7053SJung-uk Kim 124e71b7053SJung-uk KimA valid point on a curve is the special point at infinity. A point is set to 125e71b7053SJung-uk Kimbe at infinity by calling EC_POINT_set_to_infinity(). 126e71b7053SJung-uk Kim 127*b077aed3SPierre ProncheryThe affine coordinates for a point describe a point in terms of its x and y 128e71b7053SJung-uk Kimposition. The function EC_POINT_set_affine_coordinates() sets the B<x> and B<y> 129*b077aed3SPierre Proncherycoordinates for the point B<p> defined over the curve given in B<group>. The 130e71b7053SJung-uk Kimfunction EC_POINT_get_affine_coordinates() sets B<x> and B<y>, either of which 131e71b7053SJung-uk Kimmay be NULL, to the corresponding coordinates of B<p>. 132e71b7053SJung-uk Kim 133e71b7053SJung-uk KimThe functions EC_POINT_set_affine_coordinates_GFp() and 134e71b7053SJung-uk KimEC_POINT_set_affine_coordinates_GF2m() are synonyms for 135e71b7053SJung-uk KimEC_POINT_set_affine_coordinates(). They are defined for backwards compatibility 136e71b7053SJung-uk Kimonly and should not be used. 137e71b7053SJung-uk Kim 138e71b7053SJung-uk KimThe functions EC_POINT_get_affine_coordinates_GFp() and 139e71b7053SJung-uk KimEC_POINT_get_affine_coordinates_GF2m() are synonyms for 140e71b7053SJung-uk KimEC_POINT_get_affine_coordinates(). They are defined for backwards compatibility 141e71b7053SJung-uk Kimonly and should not be used. 142e71b7053SJung-uk Kim 143*b077aed3SPierre ProncheryAs well as the affine coordinates, a point can alternatively be described in 144*b077aed3SPierre Proncheryterms of its Jacobian projective coordinates (for Fp curves only). Jacobian 145*b077aed3SPierre Proncheryprojective coordinates are expressed as three values x, y and z. Working in 146*b077aed3SPierre Proncherythis coordinate system provides more efficient point multiplication 147*b077aed3SPierre Proncheryoperations. A mapping exists between Jacobian projective coordinates and 148*b077aed3SPierre Proncheryaffine coordinates. A Jacobian projective coordinate (x, y, z) can be written 149*b077aed3SPierre Proncheryas an affine coordinate as (x/(z^2), y/(z^3)). Conversion to Jacobian 150*b077aed3SPierre Proncheryprojective from affine coordinates is simple. The coordinate (x, y) is mapped 151*b077aed3SPierre Proncheryto (x, y, 1). Although deprecated in OpenSSL 3.0 and should no longer be used, 152*b077aed3SPierre Proncheryto set or get the projective coordinates in older versions use 153e71b7053SJung-uk KimEC_POINT_set_Jprojective_coordinates_GFp() and 154e71b7053SJung-uk KimEC_POINT_get_Jprojective_coordinates_GFp() respectively. 155*b077aed3SPierre ProncheryModern versions should instead use EC_POINT_set_affine_coordinates() and 156*b077aed3SPierre ProncheryEC_POINT_get_affine_coordinates(), performing the conversion manually using the 157*b077aed3SPierre Proncheryabove maps in such rare circumstances. 158e71b7053SJung-uk Kim 159*b077aed3SPierre ProncheryPoints can also be described in terms of their compressed coordinates. For a 160e71b7053SJung-uk Kimpoint (x, y), for any given value for x such that the point is on the curve 16158f35182SJung-uk Kimthere will only ever be two possible values for y. Therefore, a point can be set 162e71b7053SJung-uk Kimusing the EC_POINT_set_compressed_coordinates() function where B<x> is the x 163*b077aed3SPierre Proncherycoordinate and B<y_bit> is a value 0 or 1 to identify which of the two 164e71b7053SJung-uk Kimpossible values for y should be used. 165e71b7053SJung-uk Kim 166e71b7053SJung-uk KimThe functions EC_POINT_set_compressed_coordinates_GFp() and 167e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates_GF2m() are synonyms for 168e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates(). They are defined for backwards 169e71b7053SJung-uk Kimcompatibility only and should not be used. 170e71b7053SJung-uk Kim 171e71b7053SJung-uk KimIn addition B<EC_POINT> can be converted to and from various external 172e71b7053SJung-uk Kimrepresentations. The octet form is the binary encoding of the B<ECPoint> 173e71b7053SJung-uk Kimstructure (as defined in RFC5480 and used in certificates and TLS records): 174e71b7053SJung-uk Kimonly the content octets are present, the B<OCTET STRING> tag and length are 175e71b7053SJung-uk Kimnot included. B<BIGNUM> form is the octet form interpreted as a big endian 176e71b7053SJung-uk Kiminteger converted to a B<BIGNUM> structure. Hexadecimal form is the octet 177e71b7053SJung-uk Kimform converted to a NULL terminated character string where each character 178e71b7053SJung-uk Kimis one of the printable values 0-9 or A-F (or a-f). 179e71b7053SJung-uk Kim 180e71b7053SJung-uk KimThe functions EC_POINT_point2oct(), EC_POINT_oct2point(), EC_POINT_point2bn(), 181e71b7053SJung-uk KimEC_POINT_bn2point(), EC_POINT_point2hex() and EC_POINT_hex2point() convert from 182e71b7053SJung-uk Kimand to EC_POINTs for the formats: octet, BIGNUM and hexadecimal respectively. 183e71b7053SJung-uk Kim 18417f01e99SJung-uk KimThe function EC_POINT_point2oct() encodes the given curve point B<p> as an 18517f01e99SJung-uk Kimoctet string into the buffer B<buf> of size B<len>, using the specified 18617f01e99SJung-uk Kimconversion form B<form>. 18717f01e99SJung-uk KimThe encoding conforms with Sec. 2.3.3 of the SECG SEC 1 ("Elliptic Curve 18817f01e99SJung-uk KimCryptography") standard. 18917f01e99SJung-uk KimSimilarly the function EC_POINT_oct2point() decodes a curve point into B<p> from 19017f01e99SJung-uk Kimthe octet string contained in the given buffer B<buf> of size B<len>, conforming 19117f01e99SJung-uk Kimto Sec. 2.3.4 of the SECG SEC 1 ("Elliptic Curve Cryptography") standard. 19217f01e99SJung-uk Kim 19317f01e99SJung-uk KimThe functions EC_POINT_point2hex() and EC_POINT_point2bn() convert a point B<p>, 19417f01e99SJung-uk Kimrespectively, to the hexadecimal or BIGNUM representation of the same 19517f01e99SJung-uk Kimencoding of the function EC_POINT_point2oct(). 19617f01e99SJung-uk KimVice versa, similarly to the function EC_POINT_oct2point(), the functions 19717f01e99SJung-uk KimEC_POINT_hex2point() and EC_POINT_point2bn() decode the hexadecimal or 19817f01e99SJung-uk KimBIGNUM representation into the EC_POINT B<p>. 19917f01e99SJung-uk Kim 20017f01e99SJung-uk KimNotice that, according to the standard, the octet string encoding of the point 20117f01e99SJung-uk Kimat infinity for a given curve is fixed to a single octet of value zero and that, 20217f01e99SJung-uk Kimvice versa, a single octet of size zero is decoded as the point at infinity. 20317f01e99SJung-uk Kim 204e71b7053SJung-uk KimThe function EC_POINT_point2oct() must be supplied with a buffer long enough to 205e71b7053SJung-uk Kimstore the octet form. The return value provides the number of octets stored. 206e71b7053SJung-uk KimCalling the function with a NULL buffer will not perform the conversion but 207e71b7053SJung-uk Kimwill still return the required buffer length. 208e71b7053SJung-uk Kim 209e71b7053SJung-uk KimThe function EC_POINT_point2buf() allocates a buffer of suitable length and 210e71b7053SJung-uk Kimwrites an EC_POINT to it in octet format. The allocated buffer is written to 211e71b7053SJung-uk KimB<*pbuf> and its length is returned. The caller must free up the allocated 212e71b7053SJung-uk Kimbuffer with a call to OPENSSL_free(). Since the allocated buffer value is 213e71b7053SJung-uk Kimwritten to B<*pbuf> the B<pbuf> parameter B<MUST NOT> be B<NULL>. 214e71b7053SJung-uk Kim 215e71b7053SJung-uk KimThe function EC_POINT_point2hex() will allocate sufficient memory to store the 216e71b7053SJung-uk Kimhexadecimal string. It is the caller's responsibility to free this memory with 217e71b7053SJung-uk Kima subsequent call to OPENSSL_free(). 218e71b7053SJung-uk Kim 219e71b7053SJung-uk Kim=head1 RETURN VALUES 220e71b7053SJung-uk Kim 221e71b7053SJung-uk KimEC_POINT_new() and EC_POINT_dup() return the newly allocated EC_POINT or NULL 222e71b7053SJung-uk Kimon error. 223e71b7053SJung-uk Kim 224e71b7053SJung-uk KimThe following functions return 1 on success or 0 on error: EC_POINT_copy(), 225e71b7053SJung-uk KimEC_POINT_set_to_infinity(), EC_POINT_set_Jprojective_coordinates_GFp(), 226e71b7053SJung-uk KimEC_POINT_get_Jprojective_coordinates_GFp(), 227e71b7053SJung-uk KimEC_POINT_set_affine_coordinates_GFp(), EC_POINT_get_affine_coordinates_GFp(), 228e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates_GFp(), 229e71b7053SJung-uk KimEC_POINT_set_affine_coordinates_GF2m(), EC_POINT_get_affine_coordinates_GF2m(), 230e71b7053SJung-uk KimEC_POINT_set_compressed_coordinates_GF2m() and EC_POINT_oct2point(). 231e71b7053SJung-uk Kim 232e71b7053SJung-uk KimEC_POINT_method_of returns the EC_METHOD associated with the supplied EC_POINT. 233e71b7053SJung-uk Kim 234e71b7053SJung-uk KimEC_POINT_point2oct() and EC_POINT_point2buf() return the length of the required 235e71b7053SJung-uk Kimbuffer or 0 on error. 236e71b7053SJung-uk Kim 237e71b7053SJung-uk KimEC_POINT_point2bn() returns the pointer to the BIGNUM supplied, or NULL on 238e71b7053SJung-uk Kimerror. 239e71b7053SJung-uk Kim 240e71b7053SJung-uk KimEC_POINT_bn2point() returns the pointer to the EC_POINT supplied, or NULL on 241e71b7053SJung-uk Kimerror. 242e71b7053SJung-uk Kim 243e71b7053SJung-uk KimEC_POINT_point2hex() returns a pointer to the hex string, or NULL on error. 244e71b7053SJung-uk Kim 245e71b7053SJung-uk KimEC_POINT_hex2point() returns the pointer to the EC_POINT supplied, or NULL on 246e71b7053SJung-uk Kimerror. 247e71b7053SJung-uk Kim 248e71b7053SJung-uk Kim=head1 SEE ALSO 249e71b7053SJung-uk Kim 250e71b7053SJung-uk KimL<crypto(7)>, L<EC_GROUP_new(3)>, L<EC_GROUP_copy(3)>, 251e71b7053SJung-uk KimL<EC_POINT_add(3)>, L<EC_KEY_new(3)>, 252e71b7053SJung-uk KimL<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)> 253e71b7053SJung-uk Kim 254*b077aed3SPierre Pronchery=head1 HISTORY 255*b077aed3SPierre Pronchery 256*b077aed3SPierre ProncheryEC_POINT_method_of(), 257*b077aed3SPierre ProncheryEC_POINT_set_Jprojective_coordinates_GFp(), 258*b077aed3SPierre ProncheryEC_POINT_get_Jprojective_coordinates_GFp(), 259*b077aed3SPierre ProncheryEC_POINT_set_affine_coordinates_GFp(), EC_POINT_get_affine_coordinates_GFp(), 260*b077aed3SPierre ProncheryEC_POINT_set_compressed_coordinates_GFp(), 261*b077aed3SPierre ProncheryEC_POINT_set_affine_coordinates_GF2m(), EC_POINT_get_affine_coordinates_GF2m(), 262*b077aed3SPierre ProncheryEC_POINT_set_compressed_coordinates_GF2m(), 263*b077aed3SPierre ProncheryEC_POINT_point2bn(), and EC_POINT_bn2point() were deprecated in OpenSSL 3.0. 264*b077aed3SPierre Pronchery 265*b077aed3SPierre Pronchery 266*b077aed3SPierre ProncheryB<EC_POINT_set_affine_coordinates>, B<EC_POINT_get_affine_coordinates>, 267*b077aed3SPierre Proncheryand B<EC_POINT_set_compressed_coordinates> were 268*b077aed3SPierre Proncheryadded in OpenSSL 1.1.1. 269*b077aed3SPierre Pronchery 270e71b7053SJung-uk Kim=head1 COPYRIGHT 271e71b7053SJung-uk Kim 272*b077aed3SPierre ProncheryCopyright 2013-2023 The OpenSSL Project Authors. All Rights Reserved. 273e71b7053SJung-uk Kim 274*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 275e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 276e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 277e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 278e71b7053SJung-uk Kim 279e71b7053SJung-uk Kim=cut 280