diff options
| author | tb <> | 2025-04-25 19:57:12 +0000 |
|---|---|---|
| committer | tb <> | 2025-04-25 19:57:12 +0000 |
| commit | 60904c983d054a3655c2d3ac38828e2b8c9cc067 (patch) | |
| tree | 861ff688d2e1eb96feb6980c81276954e5ebafe4 /src/lib/libcrypto/man/EC_POINT_point2oct.3 | |
| parent | d569ea3a7dd45ac021b0335a24722227abc9bd8d (diff) | |
| download | openbsd-60904c983d054a3655c2d3ac38828e2b8c9cc067.tar.gz openbsd-60904c983d054a3655c2d3ac38828e2b8c9cc067.tar.bz2 openbsd-60904c983d054a3655c2d3ac38828e2b8c9cc067.zip | |
Rework EC documentation
This replaces the giant, poor quality and outdated EC_GROUP_copy.3,
EC_GROUP_new.3, and EC_POINT_new.3 manuals with seven new manuals
written from scratch.
* EC_GROUP_new_by_curve_name() is the entry point for builtin curves,
* EC_GROUP_new_curve_GFp() describes lower level API that should not
usually be needed apart from a handful of accessors.
* EC_GROUP_check() contains two functions that applications should not
need because either you know for certain something is an elliptic
curve (so these checks are pointless) or you should not use it.
* EC_GROUP_get_curve_name() describes some low level ASN.1 footguns
and corresponding getters.
* EC_POINT_new() contains the simple EC_POINT allocation and freeing API
* EC_POINT_get_affine_coordinates() contains the coordinate accessors
* EC_POINT_point2oct() is about encoding elliptic curve points
While all this is quite far from perfect, the diff is getting too big
and it will be easier to improve this in tree. It is definitely more
repetitive than I would like it to be.
Reviews, tweaks and general feedback are of course welcome.
discussed with jsing
Diffstat (limited to 'src/lib/libcrypto/man/EC_POINT_point2oct.3')
| -rw-r--r-- | src/lib/libcrypto/man/EC_POINT_point2oct.3 | 431 |
1 files changed, 431 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EC_POINT_point2oct.3 b/src/lib/libcrypto/man/EC_POINT_point2oct.3 new file mode 100644 index 0000000000..d0663670ee --- /dev/null +++ b/src/lib/libcrypto/man/EC_POINT_point2oct.3 | |||
| @@ -0,0 +1,431 @@ | |||
| 1 | .\" $OpenBSD: EC_POINT_point2oct.3,v 1.1 2025/04/25 19:57:12 tb Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 2025 Theo Buehler <tb@openbsd.org> | ||
| 4 | .\" | ||
| 5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 7 | .\" copyright notice and this permission notice appear in all copies. | ||
| 8 | .\" | ||
| 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | .\" | ||
| 17 | .Dd $Mdocdate: April 25 2025 $ | ||
| 18 | .Dt EC_POINT_POINT2OCT 3 | ||
| 19 | .Os | ||
| 20 | .Sh NAME | ||
| 21 | .Nm EC_POINT_point2oct , | ||
| 22 | .Nm EC_POINT_oct2point , | ||
| 23 | .Nm EC_POINT_point2bn , | ||
| 24 | .Nm EC_POINT_bn2point , | ||
| 25 | .Nm EC_POINT_point2hex , | ||
| 26 | .Nm EC_POINT_hex2point | ||
| 27 | .Nd encode and decode elliptic curve points | ||
| 28 | .Sh SYNOPSIS | ||
| 29 | .In openssl/bn.h | ||
| 30 | .In openssl/ec.h | ||
| 31 | .Bd -literal | ||
| 32 | typedef enum { | ||
| 33 | POINT_CONVERSION_COMPRESSED = 2, | ||
| 34 | POINT_CONVERSION_UNCOMPRESSED = 4, | ||
| 35 | POINT_CONVERSION_HYBRID = 6 | ||
| 36 | } point_conversion_form_t; | ||
| 37 | |||
| 38 | .Ed | ||
| 39 | .Ft size_t | ||
| 40 | .Fo EC_POINT_point2oct | ||
| 41 | .Fa "const EC_GROUP *group" | ||
| 42 | .Fa "const EC_POINT *point" | ||
| 43 | .Fa "point_conversion_form_t form" | ||
| 44 | .Fa "unsigned char *buf" | ||
| 45 | .Fa "size_t len" | ||
| 46 | .Fa "BN_CTX *ctx" | ||
| 47 | .Fc | ||
| 48 | .Ft int | ||
| 49 | .Fo EC_POINT_oct2point | ||
| 50 | .Fa "const EC_GROUP *group" | ||
| 51 | .Fa "EC_POINT *point" | ||
| 52 | .Fa "const unsigned char *buf" | ||
| 53 | .Fa "size_t len" | ||
| 54 | .Fa "BN_CTX *ctx" | ||
| 55 | .Fc | ||
| 56 | .Ft "BIGNUM *" | ||
| 57 | .Fo EC_POINT_point2bn | ||
| 58 | .Fa "const EC_GROUP *group" | ||
| 59 | .Fa "const EC_POINT *point" | ||
| 60 | .Fa "point_conversion_form_t form" | ||
| 61 | .Fa "BIGNUM *bn" | ||
| 62 | .Fa "BN_CTX *ctx" | ||
| 63 | .Fc | ||
| 64 | .Ft "EC_POINT *" | ||
| 65 | .Fo EC_POINT_bn2point | ||
| 66 | .Fa "const EC_GROUP *group" | ||
| 67 | .Fa "const BIGNUM *bn" | ||
| 68 | .Fa "EC_POINT *point" | ||
| 69 | .Fa "BN_CTX *ctx" | ||
| 70 | .Fc | ||
| 71 | .Ft "char *" | ||
| 72 | .Fo EC_POINT_point2hex | ||
| 73 | .Fa "const EC_GROUP *group" | ||
| 74 | .Fa "const EC_POINT *point" | ||
| 75 | .Fa "point_conversion_form_t form" | ||
| 76 | .Fa "BN_CTX *ctx" | ||
| 77 | .Fc | ||
| 78 | .Ft "EC_POINT *" | ||
| 79 | .Fo EC_POINT_hex2point | ||
| 80 | .Fa "const EC_GROUP *group" | ||
| 81 | .Fa "const char *hex" | ||
| 82 | .Fa "EC_POINT *point" | ||
| 83 | .Fa "BN_CTX *ctx" | ||
| 84 | .Fc | ||
| 85 | .Sh DESCRIPTION | ||
| 86 | The | ||
| 87 | .Fa ctx | ||
| 88 | argument of all functions in this manual is optional. | ||
| 89 | .Pp | ||
| 90 | An | ||
| 91 | .Vt EC_POINT | ||
| 92 | object represents a point on the elliptic curve given by an | ||
| 93 | .Vt EC_GROUP | ||
| 94 | object. | ||
| 95 | It is either the point at infinity or it has a representation | ||
| 96 | (x, y) in standard affine coordinates, | ||
| 97 | in which case it satisfies the curve's Weierstrass equation | ||
| 98 | .Dl y^2 = x^3 + ax + b | ||
| 99 | in the prime field of size p. | ||
| 100 | Thus, y is a square root of x^3 + ax + b. | ||
| 101 | Since p > 3 is odd, p - y is another square root | ||
| 102 | with different parity, unless y is zero. | ||
| 103 | Point compression uses that x and the parity of y are enough | ||
| 104 | to compute y using | ||
| 105 | .Xr BN_mod_sqrt 3 . | ||
| 106 | .Pp | ||
| 107 | Field elements are represented as non-negative integers < p | ||
| 108 | in big-endian 2-complement form, zero-padded on the left to the byte | ||
| 109 | length l of p. | ||
| 110 | If X and Y are the representations of x and y, respectively, and P is | ||
| 111 | the parity bit of y, the three encodings of the point (x, y) are | ||
| 112 | the byte strings: | ||
| 113 | .Bl -column "EncodingX" "CompressedX" "UncompressedX" "Hybrid" -offset indent -compact | ||
| 114 | .It Ta Em Compressed Ta Em Uncompressed Ta Em Hybrid | ||
| 115 | .It Encoding Ta 2+P || X Ta 4 || X || Y Ta 6+P || X || Y | ||
| 116 | .It Length Ta 1 + l Ta 1 + 2l Ta 1 + 2l | ||
| 117 | .El | ||
| 118 | where the first octet is the point conversion form | ||
| 119 | combined with the parity bit in the compressed and hybrid encodings. | ||
| 120 | The point at infinity is encoded as a single zero byte. | ||
| 121 | .Pp | ||
| 122 | .Fn EC_POINT_point2oct | ||
| 123 | converts | ||
| 124 | .Fa point | ||
| 125 | into the octet string encoding of type | ||
| 126 | .Fa form . | ||
| 127 | It assumes without checking that | ||
| 128 | .Fa point | ||
| 129 | is a point on the elliptic curve represented by | ||
| 130 | .Fa group | ||
| 131 | and operates in two modes depending on the | ||
| 132 | .Fa buf | ||
| 133 | argument. | ||
| 134 | If | ||
| 135 | .Fa buf | ||
| 136 | is | ||
| 137 | .Dv NULL , | ||
| 138 | .Fn EC_POINT_point2oct | ||
| 139 | returns the length of | ||
| 140 | .Fa point Ns 's | ||
| 141 | encoding of type | ||
| 142 | .Fa form | ||
| 143 | and ignores the | ||
| 144 | .Fa len | ||
| 145 | and | ||
| 146 | .Fa ctx | ||
| 147 | arguments. | ||
| 148 | If | ||
| 149 | .Fa buf | ||
| 150 | is not | ||
| 151 | .Dv NULL | ||
| 152 | and its length | ||
| 153 | .Fa len | ||
| 154 | is sufficiently big, | ||
| 155 | .Fn EC_POINT_point2oct 3 | ||
| 156 | writes the | ||
| 157 | .Fa point Ns 's | ||
| 158 | encoding of type | ||
| 159 | .Fa form | ||
| 160 | to | ||
| 161 | .Fa buf | ||
| 162 | and returns the number of bytes written. | ||
| 163 | Unless | ||
| 164 | .Fa point | ||
| 165 | is the point at infinity, the coordinates to be encoded are calculated using | ||
| 166 | .Xr EC_POINT_get_affine_coordinates 3 . | ||
| 167 | .Pp | ||
| 168 | .Fn EC_POINT_oct2point | ||
| 169 | decodes the octet string representation of a point on | ||
| 170 | .Fa group | ||
| 171 | in | ||
| 172 | .Fa buf | ||
| 173 | of size | ||
| 174 | .Fa len | ||
| 175 | and, if it represents a point on | ||
| 176 | .Fa group , | ||
| 177 | sets it on the caller-provided | ||
| 178 | .Fa point | ||
| 179 | using | ||
| 180 | .Xr EC_POINT_set_to_infinity 3 | ||
| 181 | .Xr EC_POINT_set_compressed_coordinates 3 , | ||
| 182 | or | ||
| 183 | .Xr EC_POINT_set_affine_coordinates 3 . | ||
| 184 | For hybrid encoding the consistency of | ||
| 185 | the parity bit in the leading octet is verified. | ||
| 186 | .Pp | ||
| 187 | .Fn EC_POINT_point2bn | ||
| 188 | returns a | ||
| 189 | .Vt BIGNUM | ||
| 190 | containing the encoding of type | ||
| 191 | .Fa form | ||
| 192 | of the | ||
| 193 | .Fa point | ||
| 194 | on | ||
| 195 | .Fa group . | ||
| 196 | If | ||
| 197 | .Fa bn | ||
| 198 | is | ||
| 199 | .Dv NULL , | ||
| 200 | this | ||
| 201 | .Vt BIGNUM | ||
| 202 | is newly allocated, otherwise the result is copied into | ||
| 203 | .Fa bn | ||
| 204 | and returned. | ||
| 205 | .Fn EC_POINT_point2bn | ||
| 206 | is equivalent to | ||
| 207 | .Fn EC_POINT_point2oct | ||
| 208 | followed by | ||
| 209 | .Xr BN_bin2bn 3 . | ||
| 210 | .Pp | ||
| 211 | .Fn EC_POINT_bn2point | ||
| 212 | assumes that | ||
| 213 | .Fa bn | ||
| 214 | contains the encoding of a point on | ||
| 215 | .Fa group . | ||
| 216 | If | ||
| 217 | .Fa point | ||
| 218 | is | ||
| 219 | .Dv NULL , | ||
| 220 | the result is placed in a newly allocated | ||
| 221 | .Vt EC_POINT , | ||
| 222 | otherwise the result is placed in | ||
| 223 | .Fa point | ||
| 224 | which is then returned. | ||
| 225 | .Fn EC_POINT_bn2point | ||
| 226 | is equivalent to | ||
| 227 | .Xr BN_bn2bin 3 | ||
| 228 | followed by | ||
| 229 | .Fn EC_POINT_oct2point . | ||
| 230 | .Pp | ||
| 231 | .Fn EC_POINT_point2hex | ||
| 232 | returns a printable string containing the hexadecimal encoding of | ||
| 233 | the point encoding of type | ||
| 234 | .Fa form | ||
| 235 | of the | ||
| 236 | .Fa point | ||
| 237 | on | ||
| 238 | .Fa group . | ||
| 239 | The string must be freed by the caller using | ||
| 240 | .Xr free 3 . | ||
| 241 | .Fn EC_POINT_point2hex | ||
| 242 | is equivalent to | ||
| 243 | .Fn EC_POINT_point2bn | ||
| 244 | followed by | ||
| 245 | .Fn BN_bn2hex 3 . | ||
| 246 | .Pp | ||
| 247 | .Fn EC_POINT_hex2point | ||
| 248 | interprets | ||
| 249 | .Fa hex | ||
| 250 | as a hexadecimal encoding of the point encoding of a point on | ||
| 251 | .Fa group . | ||
| 252 | If | ||
| 253 | .Fa point | ||
| 254 | is | ||
| 255 | .Dv NULL , | ||
| 256 | the result is returned in a newly allocated | ||
| 257 | .Vt EC_POINT , | ||
| 258 | otherwise the result is copied into | ||
| 259 | .Fa point , | ||
| 260 | which is then returned. | ||
| 261 | .Fn EC_POINT_hex2point | ||
| 262 | is equivalent to | ||
| 263 | .Xr BN_hex2bn 3 | ||
| 264 | followed by | ||
| 265 | .Fn EC_POINT_bn2point . | ||
| 266 | .Sh RETURN VALUES | ||
| 267 | If | ||
| 268 | .Fa buf | ||
| 269 | is | ||
| 270 | .Dv NULL , | ||
| 271 | .Fn EC_POINT_point2oct | ||
| 272 | returns the length needed to encode the | ||
| 273 | .Fa point | ||
| 274 | on | ||
| 275 | .Fa group , | ||
| 276 | or 0 on error. | ||
| 277 | If | ||
| 278 | .Fa buf | ||
| 279 | is not | ||
| 280 | .Dv NULL , | ||
| 281 | .Fn EC_POINT_point2oct | ||
| 282 | returns the number of bytes written to | ||
| 283 | .Fa buf | ||
| 284 | or 0 on error. | ||
| 285 | Error conditions include that | ||
| 286 | .Fa form | ||
| 287 | is invalid, | ||
| 288 | .Fa len | ||
| 289 | is too small, and memory allocation failure. | ||
| 290 | .Pp | ||
| 291 | .Fn EC_POINT_oct2point | ||
| 292 | returns 1 on success and 0 on error. | ||
| 293 | Error conditions include invalid encoding, | ||
| 294 | .Fa buf | ||
| 295 | does not represent a point on | ||
| 296 | .Fa group , | ||
| 297 | or memory allocation failure. | ||
| 298 | .Pp | ||
| 299 | .Fn EC_POINT_point2bn | ||
| 300 | returns a | ||
| 301 | .Vt BIGNUM | ||
| 302 | containing the encoding of | ||
| 303 | .Fa point | ||
| 304 | or | ||
| 305 | .Dv NULL | ||
| 306 | on error. | ||
| 307 | The returned | ||
| 308 | .Vt BIGNUM | ||
| 309 | is either | ||
| 310 | .Fa in_bn | ||
| 311 | or a newly allocated one which must be freed by the caller. | ||
| 312 | Error conditions include those of | ||
| 313 | .Fn EC_POINT_point2oct , | ||
| 314 | .Xr BN_bn2bin 3 , | ||
| 315 | or memory allocation failure. | ||
| 316 | .Pp | ||
| 317 | .Fn EC_POINT_bn2point | ||
| 318 | returns an | ||
| 319 | .Vt EC_POINT | ||
| 320 | corresponding to the encoding in | ||
| 321 | .Fa bn | ||
| 322 | or | ||
| 323 | .Dv NULL | ||
| 324 | on error. | ||
| 325 | The returned | ||
| 326 | .Vt EC_POINT | ||
| 327 | is either | ||
| 328 | .Fa in_point | ||
| 329 | or a newly allocated one which must be freed by the caller. | ||
| 330 | Error conditions include those of | ||
| 331 | .Xr BN_bn2bin 3 , | ||
| 332 | .Fn EC_POINT_oct2point , | ||
| 333 | or memory allocation failure. | ||
| 334 | .Pp | ||
| 335 | .Fn EC_POINT_point2hex | ||
| 336 | returns a newly allocated string or | ||
| 337 | .Dv NULL | ||
| 338 | on error. | ||
| 339 | Error conditions include those of | ||
| 340 | .Fn EC_POINT_point2bn | ||
| 341 | or | ||
| 342 | .Xr BN_bn2hex 3 . | ||
| 343 | .Pp | ||
| 344 | .Fn EC_POINT_hex2point | ||
| 345 | returns an | ||
| 346 | .Vt EC_POINT | ||
| 347 | containing the decoded point on | ||
| 348 | .Fa group | ||
| 349 | or | ||
| 350 | .Dv NULL | ||
| 351 | on error. | ||
| 352 | The returned | ||
| 353 | .Vt EC_POINT | ||
| 354 | is either | ||
| 355 | .Fa in_point | ||
| 356 | or a newly allocated one which must be freed by the caller. | ||
| 357 | Error conditions are those of | ||
| 358 | .Xr BN_hex2bn 3 , | ||
| 359 | or | ||
| 360 | .Fn EC_POINT_bn2point . | ||
| 361 | .Sh SEE ALSO | ||
| 362 | .Xr BN_mod_sqrt 3 , | ||
| 363 | .Xr BN_new 3 , | ||
| 364 | .Xr BN_num_bits 3 , | ||
| 365 | .Xr crypto 3 , | ||
| 366 | .Xr d2i_ECPKParameters 3 , | ||
| 367 | .Xr EC_GROUP_check 3 , | ||
| 368 | .Xr EC_GROUP_get_curve_name 3 , | ||
| 369 | .Xr EC_GROUP_new_by_curve_name 3 , | ||
| 370 | .Xr EC_GROUP_new_curve_GFp 3 , | ||
| 371 | .Xr EC_KEY_METHOD_new 3 , | ||
| 372 | .Xr EC_KEY_new 3 , | ||
| 373 | .Xr EC_POINT_add 3 , | ||
| 374 | .Xr EC_POINT_get_affine_coordinates 3 , | ||
| 375 | .Xr EC_POINT_new 3 , | ||
| 376 | .Xr ECDH_compute_key 3 , | ||
| 377 | .Xr ECDSA_SIG_new 3 | ||
| 378 | .Sh STANDARDS | ||
| 379 | .Rs | ||
| 380 | .%T SEC 1: Elliptic Curve Cryptography, Version 2.0 | ||
| 381 | .%U https://www.secg.org/sec1-v2.pdf | ||
| 382 | .%D May 21, 2009 | ||
| 383 | .Re | ||
| 384 | .Sh HISTORY | ||
| 385 | .Fn EC_POINT_point2oct | ||
| 386 | and | ||
| 387 | .Fn EC_POINT_oct2point | ||
| 388 | first appeared in OpenSSL 0.9.7 and have been available since | ||
| 389 | .Ox 3.2 . | ||
| 390 | .Pp | ||
| 391 | .Fn EC_POINT_point2bn , | ||
| 392 | .Fn EC_POINT_bn2point , | ||
| 393 | .Fn EC_POINT_point2hex , | ||
| 394 | and | ||
| 395 | .Fn EC_POINT_hex2point | ||
| 396 | first appeared in OpenSSL 0.9.8 and have been available since | ||
| 397 | .Ox 4.5 . | ||
| 398 | .Sh BUGS | ||
| 399 | The | ||
| 400 | .Vt point_conversion_form_t | ||
| 401 | is not properly exposed in the API. | ||
| 402 | There is no representation for the point at infinity nor is there | ||
| 403 | an API interface for the parity bit, | ||
| 404 | forcing applications to invent their own and do bit twiddling in buffers. | ||
| 405 | .Pp | ||
| 406 | The poorly chosen signatures of the functions in this manual result | ||
| 407 | in an unergonomic API, particularly so for | ||
| 408 | .Fn EC_POINT_point2oct | ||
| 409 | and | ||
| 410 | .Fn EC_POINT_oct2point . | ||
| 411 | Due to fundamental misdesign in the EC library, | ||
| 412 | points are not directly linked to the curve they live on. | ||
| 413 | Adding checks that | ||
| 414 | .Fa point | ||
| 415 | lives on | ||
| 416 | .Fa group | ||
| 417 | is too expensive and intrusive, so it is and will continue to be easy | ||
| 418 | to make the EC_POINT_point2* API output nonsense. | ||
| 419 | .Pp | ||
| 420 | .Fn EC_POINT_point2bn | ||
| 421 | and | ||
| 422 | .Fn EC_POINT_bn2point | ||
| 423 | make no sense. | ||
| 424 | They abuse | ||
| 425 | .Vt BIGNUM | ||
| 426 | as a vector type, which is in poor taste. | ||
| 427 | .Pp | ||
| 428 | .Fn EC_POINT_point2hex | ||
| 429 | and | ||
| 430 | .Fn EC_POINT_hex2point | ||
| 431 | use a non-standard encoding format. | ||
