summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EC_POINT_point2oct.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/EC_POINT_point2oct.3')
-rw-r--r--src/lib/libcrypto/man/EC_POINT_point2oct.3434
1 files changed, 434 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..ac89c9b1d4
--- /dev/null
+++ b/src/lib/libcrypto/man/EC_POINT_point2oct.3
@@ -0,0 +1,434 @@
1.\" $OpenBSD: EC_POINT_point2oct.3,v 1.6 2025/06/13 18:34:00 schwarze 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: June 13 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.Lb libcrypto
30.In openssl/bn.h
31.In openssl/ec.h
32.Bd -literal
33typedef enum {
34 POINT_CONVERSION_COMPRESSED = 2,
35 POINT_CONVERSION_UNCOMPRESSED = 4,
36 POINT_CONVERSION_HYBRID = 6
37} point_conversion_form_t;
38
39.Ed
40.Ft size_t
41.Fo EC_POINT_point2oct
42.Fa "const EC_GROUP *group"
43.Fa "const EC_POINT *point"
44.Fa "point_conversion_form_t form"
45.Fa "unsigned char *buf"
46.Fa "size_t len"
47.Fa "BN_CTX *ctx"
48.Fc
49.Ft int
50.Fo EC_POINT_oct2point
51.Fa "const EC_GROUP *group"
52.Fa "EC_POINT *point"
53.Fa "const unsigned char *buf"
54.Fa "size_t len"
55.Fa "BN_CTX *ctx"
56.Fc
57.Ft BIGNUM *
58.Fo EC_POINT_point2bn
59.Fa "const EC_GROUP *group"
60.Fa "const EC_POINT *point"
61.Fa "point_conversion_form_t form"
62.Fa "BIGNUM *bn"
63.Fa "BN_CTX *ctx"
64.Fc
65.Ft EC_POINT *
66.Fo EC_POINT_bn2point
67.Fa "const EC_GROUP *group"
68.Fa "const BIGNUM *bn"
69.Fa "EC_POINT *point"
70.Fa "BN_CTX *ctx"
71.Fc
72.Ft char *
73.Fo EC_POINT_point2hex
74.Fa "const EC_GROUP *group"
75.Fa "const EC_POINT *point"
76.Fa "point_conversion_form_t form"
77.Fa "BN_CTX *ctx"
78.Fc
79.Ft EC_POINT *
80.Fo EC_POINT_hex2point
81.Fa "const EC_GROUP *group"
82.Fa "const char *hex"
83.Fa "EC_POINT *point"
84.Fa "BN_CTX *ctx"
85.Fc
86.Sh DESCRIPTION
87The
88.Fa ctx
89argument of all functions in this manual is optional.
90.Pp
91An
92.Vt EC_POINT
93object represents a point on the elliptic curve given by an
94.Vt EC_GROUP
95object.
96It is either the point at infinity or it has a representation
97(x, y) in standard affine coordinates,
98in which case it satisfies the curve's Weierstrass equation
99.Pp
100.Dl y^2 = x^3 + ax + b
101.Pp
102in the prime field of size p.
103Thus, y is a square root of x^3 + ax + b.
104Since p > 3 is odd, p - y is another square root
105with different parity, unless y is zero.
106Point compression uses that x and the parity of y are enough
107to compute y using
108.Xr BN_mod_sqrt 3 .
109.Pp
110Field elements are represented as non-negative integers < p
111in big-endian 2-complement form, zero-padded on the left to the byte
112length l of p.
113If X and Y are the representations of x and y, respectively, and P is
114the parity bit of y, the three encodings of the point (x, y) are
115the byte strings:
116.Bl -column "EncodingX" "CompressedX" "UncompressedX" "Hybrid" -offset indent -compact
117.It Ta Em Compressed Ta Em Uncompressed Ta Em Hybrid
118.It Encoding Ta 2+P || X Ta 4 || X || Y Ta 6+P || X || Y
119.It Length Ta 1 + l Ta 1 + 2l Ta 1 + 2l
120.El
121where the first octet is the point conversion form
122combined with the parity bit in the compressed and hybrid encodings.
123The point at infinity is encoded as a single zero byte.
124.Pp
125.Fn EC_POINT_point2oct
126converts
127.Fa point
128into the octet string encoding of type
129.Fa form .
130It assumes without checking that
131.Fa point
132is a point on the elliptic curve represented by
133.Fa group
134and operates in two modes depending on the
135.Fa buf
136argument.
137If
138.Fa buf
139is
140.Dv NULL ,
141.Fn EC_POINT_point2oct
142returns the length of
143.Fa point Ns 's
144encoding of type
145.Fa form
146and ignores the
147.Fa len
148and
149.Fa ctx
150arguments.
151If
152.Fa buf
153is not
154.Dv NULL
155and its length
156.Fa len
157is sufficiently big,
158.Fn EC_POINT_point2oct
159writes the
160.Fa point Ns 's
161encoding of type
162.Fa form
163to
164.Fa buf
165and returns the number of bytes written.
166Unless
167.Fa point
168is the point at infinity, the coordinates to be encoded are calculated using
169.Xr EC_POINT_get_affine_coordinates 3 .
170.Pp
171.Fn EC_POINT_oct2point
172decodes the octet string representation of a point on
173.Fa group
174in
175.Fa buf
176of size
177.Fa len
178and, if it represents a point on
179.Fa group ,
180sets it on the caller-provided
181.Fa point
182using
183.Xr EC_POINT_set_to_infinity 3
184.Xr EC_POINT_set_compressed_coordinates 3 ,
185or
186.Xr EC_POINT_set_affine_coordinates 3 .
187For hybrid encoding the consistency of
188the parity bit in the leading octet is verified.
189.Pp
190.Fn EC_POINT_point2bn
191returns a
192.Vt BIGNUM
193containing the encoding of type
194.Fa form
195of the
196.Fa point
197on
198.Fa group .
199If
200.Fa bn
201is
202.Dv NULL ,
203this
204.Vt BIGNUM
205is newly allocated, otherwise the result is copied into
206.Fa bn
207and returned.
208.Fn EC_POINT_point2bn
209is equivalent to
210.Fn EC_POINT_point2oct
211followed by
212.Xr BN_bin2bn 3 .
213.Pp
214.Fn EC_POINT_bn2point
215assumes that
216.Fa bn
217contains the encoding of a point on
218.Fa group .
219If
220.Fa point
221is
222.Dv NULL ,
223the result is placed in a newly allocated
224.Vt EC_POINT ,
225otherwise the result is placed in
226.Fa point
227which is then returned.
228.Fn EC_POINT_bn2point
229is equivalent to
230.Xr BN_bn2bin 3
231followed by
232.Fn EC_POINT_oct2point .
233.Pp
234.Fn EC_POINT_point2hex
235returns a printable string containing the hexadecimal encoding of
236the point encoding of type
237.Fa form
238of the
239.Fa point
240on
241.Fa group .
242The string must be freed by the caller using
243.Xr free 3 .
244.Fn EC_POINT_point2hex
245is equivalent to
246.Fn EC_POINT_point2bn
247followed by
248.Xr BN_bn2hex 3 .
249.Pp
250.Fn EC_POINT_hex2point
251interprets
252.Fa hex
253as a hexadecimal encoding of the point encoding of a point on
254.Fa group .
255If
256.Fa point
257is
258.Dv NULL ,
259the result is returned in a newly allocated
260.Vt EC_POINT ,
261otherwise the result is copied into
262.Fa point ,
263which is then returned.
264.Fn EC_POINT_hex2point
265is equivalent to
266.Xr BN_hex2bn 3
267followed by
268.Fn EC_POINT_bn2point .
269.Sh RETURN VALUES
270If
271.Fa buf
272is
273.Dv NULL ,
274.Fn EC_POINT_point2oct
275returns the length needed to encode the
276.Fa point
277on
278.Fa group ,
279or 0 on error.
280If
281.Fa buf
282is not
283.Dv NULL ,
284.Fn EC_POINT_point2oct
285returns the number of bytes written to
286.Fa buf
287or 0 on error.
288Error conditions include that
289.Fa form
290is invalid,
291.Fa len
292is too small, and memory allocation failure.
293.Pp
294.Fn EC_POINT_oct2point
295returns 1 on success and 0 on error.
296Error conditions include invalid encoding,
297.Fa buf
298does not represent a point on
299.Fa group ,
300or memory allocation failure.
301.Pp
302.Fn EC_POINT_point2bn
303returns a
304.Vt BIGNUM
305containing the encoding of
306.Fa point
307or
308.Dv NULL
309on error.
310The returned
311.Vt BIGNUM
312is either
313.Fa bn
314or a newly allocated one which must be freed by the caller.
315Error conditions include those of
316.Fn EC_POINT_point2oct ,
317.Xr BN_bn2bin 3 ,
318or memory allocation failure.
319.Pp
320.Fn EC_POINT_bn2point
321returns an
322.Vt EC_POINT
323corresponding to the encoding in
324.Fa bn
325or
326.Dv NULL
327on error.
328The returned
329.Vt EC_POINT
330is either
331.Fa point
332or a newly allocated one which must be freed by the caller.
333Error conditions include those of
334.Xr BN_bn2bin 3 ,
335.Fn EC_POINT_oct2point ,
336or memory allocation failure.
337.Pp
338.Fn EC_POINT_point2hex
339returns a newly allocated string or
340.Dv NULL
341on error.
342Error conditions include those of
343.Fn EC_POINT_point2bn
344or
345.Xr BN_bn2hex 3 .
346.Pp
347.Fn EC_POINT_hex2point
348returns an
349.Vt EC_POINT
350containing the decoded point on
351.Fa group
352or
353.Dv NULL
354on error.
355The returned
356.Vt EC_POINT
357is either
358.Fa point
359or a newly allocated one which must be freed by the caller.
360Error conditions are those of
361.Xr BN_hex2bn 3 ,
362or
363.Fn EC_POINT_bn2point .
364.Sh SEE ALSO
365.Xr BN_mod_sqrt 3 ,
366.Xr BN_new 3 ,
367.Xr BN_num_bits 3 ,
368.Xr crypto 3 ,
369.Xr d2i_ECPKParameters 3 ,
370.Xr EC_GROUP_check 3 ,
371.Xr EC_GROUP_get_curve_name 3 ,
372.Xr EC_GROUP_new_by_curve_name 3 ,
373.Xr EC_GROUP_new_curve_GFp 3 ,
374.Xr EC_KEY_METHOD_new 3 ,
375.Xr EC_KEY_new 3 ,
376.Xr EC_POINT_add 3 ,
377.Xr EC_POINT_get_affine_coordinates 3 ,
378.Xr EC_POINT_new 3 ,
379.Xr ECDH_compute_key 3 ,
380.Xr ECDSA_SIG_new 3
381.Sh STANDARDS
382.Rs
383.%T SEC 1: Elliptic Curve Cryptography, Version 2.0
384.%U https://www.secg.org/sec1-v2.pdf
385.%D May 21, 2009
386.Re
387.Sh HISTORY
388.Fn EC_POINT_point2oct
389and
390.Fn EC_POINT_oct2point
391first appeared in OpenSSL 0.9.7 and have been available since
392.Ox 3.2 .
393.Pp
394.Fn EC_POINT_point2bn ,
395.Fn EC_POINT_bn2point ,
396.Fn EC_POINT_point2hex ,
397and
398.Fn EC_POINT_hex2point
399first appeared in OpenSSL 0.9.8 and have been available since
400.Ox 4.5 .
401.Sh BUGS
402The
403.Vt point_conversion_form_t
404is not properly exposed in the API.
405There is no representation for the point at infinity nor is there
406an API interface for the parity bit,
407forcing applications to invent their own and do bit twiddling in buffers.
408.Pp
409The poorly chosen signatures of the functions in this manual result
410in an unergonomic API, particularly so for
411.Fn EC_POINT_point2oct
412and
413.Fn EC_POINT_oct2point .
414Due to fundamental misdesign in the EC library,
415points are not directly linked to the curve they live on.
416Adding checks that
417.Fa point
418lives on
419.Fa group
420is too expensive and intrusive, so it is and will continue to be easy
421to make the EC_POINT_point2* API output nonsense.
422.Pp
423.Fn EC_POINT_point2bn
424and
425.Fn EC_POINT_bn2point
426make no sense.
427They abuse
428.Vt BIGNUM
429as a vector type, which is in poor taste.
430.Pp
431.Fn EC_POINT_point2hex
432and
433.Fn EC_POINT_hex2point
434use a non-standard encoding format.