1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos EC_POINT_set_Jprojective_coordinates_GFp, 6 1.1 christos EC_POINT_point2buf, 7 1.1 christos EC_POINT_new, 8 1.1 christos EC_POINT_free, 9 1.1 christos EC_POINT_clear_free, 10 1.1 christos EC_POINT_copy, 11 1.1 christos EC_POINT_dup, 12 1.1 christos EC_POINT_method_of, 13 1.1 christos EC_POINT_set_to_infinity, 14 1.1 christos EC_POINT_get_Jprojective_coordinates_GFp, 15 1.1 christos EC_POINT_set_affine_coordinates, 16 1.1 christos EC_POINT_get_affine_coordinates, 17 1.1 christos EC_POINT_set_compressed_coordinates, 18 1.1 christos EC_POINT_set_affine_coordinates_GFp, 19 1.1 christos EC_POINT_get_affine_coordinates_GFp, 20 1.1 christos EC_POINT_set_compressed_coordinates_GFp, 21 1.1 christos EC_POINT_set_affine_coordinates_GF2m, 22 1.1 christos EC_POINT_get_affine_coordinates_GF2m, 23 1.1 christos EC_POINT_set_compressed_coordinates_GF2m, 24 1.1 christos EC_POINT_point2oct, 25 1.1 christos EC_POINT_oct2point, 26 1.1 christos EC_POINT_point2bn, 27 1.1 christos EC_POINT_bn2point, 28 1.1 christos EC_POINT_point2hex, 29 1.1 christos EC_POINT_hex2point 30 1.1 christos - Functions for creating, destroying and manipulating EC_POINT objects 31 1.1 christos 32 1.1 christos =head1 SYNOPSIS 33 1.1 christos 34 1.1 christos #include <openssl/ec.h> 35 1.1 christos 36 1.1 christos EC_POINT *EC_POINT_new(const EC_GROUP *group); 37 1.1 christos void EC_POINT_free(EC_POINT *point); 38 1.1 christos void EC_POINT_clear_free(EC_POINT *point); 39 1.1 christos int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src); 40 1.1 christos EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); 41 1.1 christos int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point); 42 1.1 christos int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *p, 43 1.1 christos const BIGNUM *x, const BIGNUM *y, 44 1.1 christos BN_CTX *ctx); 45 1.1 christos int EC_POINT_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, 46 1.1 christos BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 47 1.1 christos int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *p, 48 1.1 christos const BIGNUM *x, int y_bit, 49 1.1 christos BN_CTX *ctx); 50 1.1.1.4 christos size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *p, 51 1.1.1.4 christos point_conversion_form_t form, 52 1.1.1.4 christos unsigned char *buf, size_t len, BN_CTX *ctx); 53 1.1.1.4 christos size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, 54 1.1.1.4 christos point_conversion_form_t form, 55 1.1.1.4 christos unsigned char **pbuf, BN_CTX *ctx); 56 1.1.1.4 christos int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *p, 57 1.1.1.4 christos const unsigned char *buf, size_t len, BN_CTX *ctx); 58 1.1.1.4 christos char *EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *p, 59 1.1.1.4 christos point_conversion_form_t form, BN_CTX *ctx); 60 1.1.1.4 christos EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, const char *hex, 61 1.1.1.4 christos EC_POINT *p, BN_CTX *ctx); 62 1.1.1.4 christos 63 1.1.1.4 christos The following functions have been deprecated since OpenSSL 3.0, and can be 64 1.1.1.4 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 65 1.1.1.4 christos see L<openssl_user_macros(7)>: 66 1.1.1.4 christos 67 1.1.1.4 christos const EC_METHOD *EC_POINT_method_of(const EC_POINT *point); 68 1.1.1.4 christos int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, 69 1.1.1.4 christos EC_POINT *p, 70 1.1.1.4 christos const BIGNUM *x, const BIGNUM *y, 71 1.1.1.4 christos const BIGNUM *z, BN_CTX *ctx); 72 1.1.1.4 christos int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, 73 1.1.1.4 christos const EC_POINT *p, 74 1.1.1.4 christos BIGNUM *x, BIGNUM *y, BIGNUM *z, 75 1.1.1.4 christos BN_CTX *ctx); 76 1.1 christos int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *p, 77 1.1 christos const BIGNUM *x, const BIGNUM *y, 78 1.1 christos BN_CTX *ctx); 79 1.1 christos int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, 80 1.1 christos const EC_POINT *p, 81 1.1 christos BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 82 1.1 christos int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, 83 1.1 christos EC_POINT *p, 84 1.1 christos const BIGNUM *x, int y_bit, 85 1.1 christos BN_CTX *ctx); 86 1.1 christos int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *p, 87 1.1 christos const BIGNUM *x, const BIGNUM *y, 88 1.1 christos BN_CTX *ctx); 89 1.1 christos int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, 90 1.1 christos const EC_POINT *p, 91 1.1 christos BIGNUM *x, BIGNUM *y, BN_CTX *ctx); 92 1.1 christos int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, 93 1.1 christos EC_POINT *p, 94 1.1 christos const BIGNUM *x, int y_bit, 95 1.1 christos BN_CTX *ctx); 96 1.1 christos BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *p, 97 1.1 christos point_conversion_form_t form, BIGNUM *bn, 98 1.1 christos BN_CTX *ctx); 99 1.1 christos EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn, 100 1.1 christos EC_POINT *p, BN_CTX *ctx); 101 1.1 christos 102 1.1 christos =head1 DESCRIPTION 103 1.1 christos 104 1.1 christos An B<EC_POINT> structure represents a point on a curve. A new point is 105 1.1 christos constructed by calling the function EC_POINT_new() and providing the 106 1.1 christos B<group> object that the point relates to. 107 1.1 christos 108 1.1 christos EC_POINT_free() frees the memory associated with the B<EC_POINT>. 109 1.1 christos if B<point> is NULL nothing is done. 110 1.1 christos 111 1.1 christos EC_POINT_clear_free() destroys any sensitive data held within the EC_POINT and 112 1.1 christos then frees its memory. If B<point> is NULL nothing is done. 113 1.1 christos 114 1.1 christos EC_POINT_copy() copies the point B<src> into B<dst>. Both B<src> and B<dst> 115 1.1 christos must use the same B<EC_METHOD>. 116 1.1 christos 117 1.1 christos EC_POINT_dup() creates a new B<EC_POINT> object and copies the content from 118 1.1 christos B<src> to the newly created B<EC_POINT> object. 119 1.1 christos 120 1.1 christos EC_POINT_method_of() obtains the B<EC_METHOD> associated with B<point>. 121 1.1.1.4 christos This function was deprecated in OpenSSL 3.0, since EC_METHOD is no longer a 122 1.1.1.4 christos public concept. 123 1.1 christos 124 1.1 christos A valid point on a curve is the special point at infinity. A point is set to 125 1.1 christos be at infinity by calling EC_POINT_set_to_infinity(). 126 1.1 christos 127 1.1.1.5 christos The affine coordinates for a point describe a point in terms of its x and y 128 1.1 christos position. The function EC_POINT_set_affine_coordinates() sets the B<x> and B<y> 129 1.1.1.5 christos coordinates for the point B<p> defined over the curve given in B<group>. The 130 1.1 christos function EC_POINT_get_affine_coordinates() sets B<x> and B<y>, either of which 131 1.1 christos may be NULL, to the corresponding coordinates of B<p>. 132 1.1 christos 133 1.1 christos The functions EC_POINT_set_affine_coordinates_GFp() and 134 1.1 christos EC_POINT_set_affine_coordinates_GF2m() are synonyms for 135 1.1 christos EC_POINT_set_affine_coordinates(). They are defined for backwards compatibility 136 1.1 christos only and should not be used. 137 1.1 christos 138 1.1 christos The functions EC_POINT_get_affine_coordinates_GFp() and 139 1.1 christos EC_POINT_get_affine_coordinates_GF2m() are synonyms for 140 1.1 christos EC_POINT_get_affine_coordinates(). They are defined for backwards compatibility 141 1.1 christos only and should not be used. 142 1.1 christos 143 1.1.1.5 christos As well as the affine coordinates, a point can alternatively be described in 144 1.1.1.5 christos terms of its Jacobian projective coordinates (for Fp curves only). Jacobian 145 1.1.1.5 christos projective coordinates are expressed as three values x, y and z. Working in 146 1.1.1.5 christos this coordinate system provides more efficient point multiplication 147 1.1.1.5 christos operations. A mapping exists between Jacobian projective coordinates and 148 1.1.1.5 christos affine coordinates. A Jacobian projective coordinate (x, y, z) can be written 149 1.1.1.5 christos as an affine coordinate as (x/(z^2), y/(z^3)). Conversion to Jacobian 150 1.1.1.5 christos projective from affine coordinates is simple. The coordinate (x, y) is mapped 151 1.1.1.4 christos to (x, y, 1). Although deprecated in OpenSSL 3.0 and should no longer be used, 152 1.1.1.5 christos to set or get the projective coordinates in older versions use 153 1.1 christos EC_POINT_set_Jprojective_coordinates_GFp() and 154 1.1 christos EC_POINT_get_Jprojective_coordinates_GFp() respectively. 155 1.1.1.4 christos Modern versions should instead use EC_POINT_set_affine_coordinates() and 156 1.1.1.4 christos EC_POINT_get_affine_coordinates(), performing the conversion manually using the 157 1.1.1.4 christos above maps in such rare circumstances. 158 1.1 christos 159 1.1.1.5 christos Points can also be described in terms of their compressed coordinates. For a 160 1.1 christos point (x, y), for any given value for x such that the point is on the curve 161 1.1.1.3 christos there will only ever be two possible values for y. Therefore, a point can be set 162 1.1 christos using the EC_POINT_set_compressed_coordinates() function where B<x> is the x 163 1.1.1.5 christos coordinate and B<y_bit> is a value 0 or 1 to identify which of the two 164 1.1 christos possible values for y should be used. 165 1.1 christos 166 1.1 christos The functions EC_POINT_set_compressed_coordinates_GFp() and 167 1.1 christos EC_POINT_set_compressed_coordinates_GF2m() are synonyms for 168 1.1 christos EC_POINT_set_compressed_coordinates(). They are defined for backwards 169 1.1 christos compatibility only and should not be used. 170 1.1 christos 171 1.1 christos In addition B<EC_POINT> can be converted to and from various external 172 1.1 christos representations. The octet form is the binary encoding of the B<ECPoint> 173 1.1 christos structure (as defined in RFC5480 and used in certificates and TLS records): 174 1.1 christos only the content octets are present, the B<OCTET STRING> tag and length are 175 1.1 christos not included. B<BIGNUM> form is the octet form interpreted as a big endian 176 1.1 christos integer converted to a B<BIGNUM> structure. Hexadecimal form is the octet 177 1.1 christos form converted to a NULL terminated character string where each character 178 1.1 christos is one of the printable values 0-9 or A-F (or a-f). 179 1.1 christos 180 1.1 christos The functions EC_POINT_point2oct(), EC_POINT_oct2point(), EC_POINT_point2bn(), 181 1.1 christos EC_POINT_bn2point(), EC_POINT_point2hex() and EC_POINT_hex2point() convert from 182 1.1 christos and to EC_POINTs for the formats: octet, BIGNUM and hexadecimal respectively. 183 1.1 christos 184 1.1.1.2 christos The function EC_POINT_point2oct() encodes the given curve point B<p> as an 185 1.1.1.2 christos octet string into the buffer B<buf> of size B<len>, using the specified 186 1.1.1.2 christos conversion form B<form>. 187 1.1.1.2 christos The encoding conforms with Sec. 2.3.3 of the SECG SEC 1 ("Elliptic Curve 188 1.1.1.2 christos Cryptography") standard. 189 1.1.1.2 christos Similarly the function EC_POINT_oct2point() decodes a curve point into B<p> from 190 1.1.1.2 christos the octet string contained in the given buffer B<buf> of size B<len>, conforming 191 1.1.1.2 christos to Sec. 2.3.4 of the SECG SEC 1 ("Elliptic Curve Cryptography") standard. 192 1.1.1.2 christos 193 1.1.1.2 christos The functions EC_POINT_point2hex() and EC_POINT_point2bn() convert a point B<p>, 194 1.1.1.2 christos respectively, to the hexadecimal or BIGNUM representation of the same 195 1.1.1.2 christos encoding of the function EC_POINT_point2oct(). 196 1.1.1.2 christos Vice versa, similarly to the function EC_POINT_oct2point(), the functions 197 1.1.1.2 christos EC_POINT_hex2point() and EC_POINT_point2bn() decode the hexadecimal or 198 1.1.1.2 christos BIGNUM representation into the EC_POINT B<p>. 199 1.1.1.2 christos 200 1.1.1.2 christos Notice that, according to the standard, the octet string encoding of the point 201 1.1.1.2 christos at infinity for a given curve is fixed to a single octet of value zero and that, 202 1.1.1.2 christos vice versa, a single octet of size zero is decoded as the point at infinity. 203 1.1.1.2 christos 204 1.1 christos The function EC_POINT_point2oct() must be supplied with a buffer long enough to 205 1.1 christos store the octet form. The return value provides the number of octets stored. 206 1.1 christos Calling the function with a NULL buffer will not perform the conversion but 207 1.1 christos will still return the required buffer length. 208 1.1 christos 209 1.1 christos The function EC_POINT_point2buf() allocates a buffer of suitable length and 210 1.1 christos writes an EC_POINT to it in octet format. The allocated buffer is written to 211 1.1 christos B<*pbuf> and its length is returned. The caller must free up the allocated 212 1.1 christos buffer with a call to OPENSSL_free(). Since the allocated buffer value is 213 1.1 christos written to B<*pbuf> the B<pbuf> parameter B<MUST NOT> be B<NULL>. 214 1.1 christos 215 1.1 christos The function EC_POINT_point2hex() will allocate sufficient memory to store the 216 1.1 christos hexadecimal string. It is the caller's responsibility to free this memory with 217 1.1 christos a subsequent call to OPENSSL_free(). 218 1.1 christos 219 1.1 christos =head1 RETURN VALUES 220 1.1 christos 221 1.1 christos EC_POINT_new() and EC_POINT_dup() return the newly allocated EC_POINT or NULL 222 1.1 christos on error. 223 1.1 christos 224 1.1 christos The following functions return 1 on success or 0 on error: EC_POINT_copy(), 225 1.1 christos EC_POINT_set_to_infinity(), EC_POINT_set_Jprojective_coordinates_GFp(), 226 1.1 christos EC_POINT_get_Jprojective_coordinates_GFp(), 227 1.1 christos EC_POINT_set_affine_coordinates_GFp(), EC_POINT_get_affine_coordinates_GFp(), 228 1.1 christos EC_POINT_set_compressed_coordinates_GFp(), 229 1.1 christos EC_POINT_set_affine_coordinates_GF2m(), EC_POINT_get_affine_coordinates_GF2m(), 230 1.1 christos EC_POINT_set_compressed_coordinates_GF2m() and EC_POINT_oct2point(). 231 1.1 christos 232 1.1 christos EC_POINT_method_of returns the EC_METHOD associated with the supplied EC_POINT. 233 1.1 christos 234 1.1 christos EC_POINT_point2oct() and EC_POINT_point2buf() return the length of the required 235 1.1 christos buffer or 0 on error. 236 1.1 christos 237 1.1 christos EC_POINT_point2bn() returns the pointer to the BIGNUM supplied, or NULL on 238 1.1 christos error. 239 1.1 christos 240 1.1 christos EC_POINT_bn2point() returns the pointer to the EC_POINT supplied, or NULL on 241 1.1 christos error. 242 1.1 christos 243 1.1 christos EC_POINT_point2hex() returns a pointer to the hex string, or NULL on error. 244 1.1 christos 245 1.1 christos EC_POINT_hex2point() returns the pointer to the EC_POINT supplied, or NULL on 246 1.1 christos error. 247 1.1 christos 248 1.1 christos =head1 SEE ALSO 249 1.1 christos 250 1.1 christos L<crypto(7)>, L<EC_GROUP_new(3)>, L<EC_GROUP_copy(3)>, 251 1.1 christos L<EC_POINT_add(3)>, L<EC_KEY_new(3)>, 252 1.1 christos L<EC_GFp_simple_method(3)>, L<d2i_ECPKParameters(3)> 253 1.1 christos 254 1.1.1.4 christos =head1 HISTORY 255 1.1.1.4 christos 256 1.1.1.4 christos EC_POINT_method_of(), 257 1.1.1.4 christos EC_POINT_set_Jprojective_coordinates_GFp(), 258 1.1.1.4 christos EC_POINT_get_Jprojective_coordinates_GFp(), 259 1.1.1.4 christos EC_POINT_set_affine_coordinates_GFp(), EC_POINT_get_affine_coordinates_GFp(), 260 1.1.1.4 christos EC_POINT_set_compressed_coordinates_GFp(), 261 1.1.1.4 christos EC_POINT_set_affine_coordinates_GF2m(), EC_POINT_get_affine_coordinates_GF2m(), 262 1.1.1.4 christos EC_POINT_set_compressed_coordinates_GF2m(), 263 1.1.1.4 christos EC_POINT_point2bn(), and EC_POINT_bn2point() were deprecated in OpenSSL 3.0. 264 1.1.1.4 christos 265 1.1.1.4 christos 266 1.1.1.4 christos B<EC_POINT_set_affine_coordinates>, B<EC_POINT_get_affine_coordinates>, 267 1.1.1.4 christos and B<EC_POINT_set_compressed_coordinates> were 268 1.1.1.4 christos added in OpenSSL 1.1.1. 269 1.1.1.4 christos 270 1.1 christos =head1 COPYRIGHT 271 1.1 christos 272 1.1.1.5 christos Copyright 2013-2023 The OpenSSL Project Authors. All Rights Reserved. 273 1.1 christos 274 1.1.1.4 christos Licensed under the Apache License 2.0 (the "License"). You may not use 275 1.1 christos this file except in compliance with the License. You can obtain a copy 276 1.1 christos in the file LICENSE in the source distribution or at 277 1.1 christos L<https://www.openssl.org/source/license.html>. 278 1.1 christos 279 1.1 christos =cut 280