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.3431
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
32typedef 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
86The
87.Fa ctx
88argument of all functions in this manual is optional.
89.Pp
90An
91.Vt EC_POINT
92object represents a point on the elliptic curve given by an
93.Vt EC_GROUP
94object.
95It is either the point at infinity or it has a representation
96(x, y) in standard affine coordinates,
97in which case it satisfies the curve's Weierstrass equation
98.Dl y^2 = x^3 + ax + b
99in the prime field of size p.
100Thus, y is a square root of x^3 + ax + b.
101Since p > 3 is odd, p - y is another square root
102with different parity, unless y is zero.
103Point compression uses that x and the parity of y are enough
104to compute y using
105.Xr BN_mod_sqrt 3 .
106.Pp
107Field elements are represented as non-negative integers < p
108in big-endian 2-complement form, zero-padded on the left to the byte
109length l of p.
110If X and Y are the representations of x and y, respectively, and P is
111the parity bit of y, the three encodings of the point (x, y) are
112the 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
118where the first octet is the point conversion form
119combined with the parity bit in the compressed and hybrid encodings.
120The point at infinity is encoded as a single zero byte.
121.Pp
122.Fn EC_POINT_point2oct
123converts
124.Fa point
125into the octet string encoding of type
126.Fa form .
127It assumes without checking that
128.Fa point
129is a point on the elliptic curve represented by
130.Fa group
131and operates in two modes depending on the
132.Fa buf
133argument.
134If
135.Fa buf
136is
137.Dv NULL ,
138.Fn EC_POINT_point2oct
139returns the length of
140.Fa point Ns 's
141encoding of type
142.Fa form
143and ignores the
144.Fa len
145and
146.Fa ctx
147arguments.
148If
149.Fa buf
150is not
151.Dv NULL
152and its length
153.Fa len
154is sufficiently big,
155.Fn EC_POINT_point2oct 3
156writes the
157.Fa point Ns 's
158encoding of type
159.Fa form
160to
161.Fa buf
162and returns the number of bytes written.
163Unless
164.Fa point
165is 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
169decodes the octet string representation of a point on
170.Fa group
171in
172.Fa buf
173of size
174.Fa len
175and, if it represents a point on
176.Fa group ,
177sets it on the caller-provided
178.Fa point
179using
180.Xr EC_POINT_set_to_infinity 3
181.Xr EC_POINT_set_compressed_coordinates 3 ,
182or
183.Xr EC_POINT_set_affine_coordinates 3 .
184For hybrid encoding the consistency of
185the parity bit in the leading octet is verified.
186.Pp
187.Fn EC_POINT_point2bn
188returns a
189.Vt BIGNUM
190containing the encoding of type
191.Fa form
192of the
193.Fa point
194on
195.Fa group .
196If
197.Fa bn
198is
199.Dv NULL ,
200this
201.Vt BIGNUM
202is newly allocated, otherwise the result is copied into
203.Fa bn
204and returned.
205.Fn EC_POINT_point2bn
206is equivalent to
207.Fn EC_POINT_point2oct
208followed by
209.Xr BN_bin2bn 3 .
210.Pp
211.Fn EC_POINT_bn2point
212assumes that
213.Fa bn
214contains the encoding of a point on
215.Fa group .
216If
217.Fa point
218is
219.Dv NULL ,
220the result is placed in a newly allocated
221.Vt EC_POINT ,
222otherwise the result is placed in
223.Fa point
224which is then returned.
225.Fn EC_POINT_bn2point
226is equivalent to
227.Xr BN_bn2bin 3
228followed by
229.Fn EC_POINT_oct2point .
230.Pp
231.Fn EC_POINT_point2hex
232returns a printable string containing the hexadecimal encoding of
233the point encoding of type
234.Fa form
235of the
236.Fa point
237on
238.Fa group .
239The string must be freed by the caller using
240.Xr free 3 .
241.Fn EC_POINT_point2hex
242is equivalent to
243.Fn EC_POINT_point2bn
244followed by
245.Fn BN_bn2hex 3 .
246.Pp
247.Fn EC_POINT_hex2point
248interprets
249.Fa hex
250as a hexadecimal encoding of the point encoding of a point on
251.Fa group .
252If
253.Fa point
254is
255.Dv NULL ,
256the result is returned in a newly allocated
257.Vt EC_POINT ,
258otherwise the result is copied into
259.Fa point ,
260which is then returned.
261.Fn EC_POINT_hex2point
262is equivalent to
263.Xr BN_hex2bn 3
264followed by
265.Fn EC_POINT_bn2point .
266.Sh RETURN VALUES
267If
268.Fa buf
269is
270.Dv NULL ,
271.Fn EC_POINT_point2oct
272returns the length needed to encode the
273.Fa point
274on
275.Fa group ,
276or 0 on error.
277If
278.Fa buf
279is not
280.Dv NULL ,
281.Fn EC_POINT_point2oct
282returns the number of bytes written to
283.Fa buf
284or 0 on error.
285Error conditions include that
286.Fa form
287is invalid,
288.Fa len
289is too small, and memory allocation failure.
290.Pp
291.Fn EC_POINT_oct2point
292returns 1 on success and 0 on error.
293Error conditions include invalid encoding,
294.Fa buf
295does not represent a point on
296.Fa group ,
297or memory allocation failure.
298.Pp
299.Fn EC_POINT_point2bn
300returns a
301.Vt BIGNUM
302containing the encoding of
303.Fa point
304or
305.Dv NULL
306on error.
307The returned
308.Vt BIGNUM
309is either
310.Fa in_bn
311or a newly allocated one which must be freed by the caller.
312Error conditions include those of
313.Fn EC_POINT_point2oct ,
314.Xr BN_bn2bin 3 ,
315or memory allocation failure.
316.Pp
317.Fn EC_POINT_bn2point
318returns an
319.Vt EC_POINT
320corresponding to the encoding in
321.Fa bn
322or
323.Dv NULL
324on error.
325The returned
326.Vt EC_POINT
327is either
328.Fa in_point
329or a newly allocated one which must be freed by the caller.
330Error conditions include those of
331.Xr BN_bn2bin 3 ,
332.Fn EC_POINT_oct2point ,
333or memory allocation failure.
334.Pp
335.Fn EC_POINT_point2hex
336returns a newly allocated string or
337.Dv NULL
338on error.
339Error conditions include those of
340.Fn EC_POINT_point2bn
341or
342.Xr BN_bn2hex 3 .
343.Pp
344.Fn EC_POINT_hex2point
345returns an
346.Vt EC_POINT
347containing the decoded point on
348.Fa group
349or
350.Dv NULL
351on error.
352The returned
353.Vt EC_POINT
354is either
355.Fa in_point
356or a newly allocated one which must be freed by the caller.
357Error conditions are those of
358.Xr BN_hex2bn 3 ,
359or
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
386and
387.Fn EC_POINT_oct2point
388first 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 ,
394and
395.Fn EC_POINT_hex2point
396first appeared in OpenSSL 0.9.8 and have been available since
397.Ox 4.5 .
398.Sh BUGS
399The
400.Vt point_conversion_form_t
401is not properly exposed in the API.
402There is no representation for the point at infinity nor is there
403an API interface for the parity bit,
404forcing applications to invent their own and do bit twiddling in buffers.
405.Pp
406The poorly chosen signatures of the functions in this manual result
407in an unergonomic API, particularly so for
408.Fn EC_POINT_point2oct
409and
410.Fn EC_POINT_oct2point .
411Due to fundamental misdesign in the EC library,
412points are not directly linked to the curve they live on.
413Adding checks that
414.Fa point
415lives on
416.Fa group
417is too expensive and intrusive, so it is and will continue to be easy
418to make the EC_POINT_point2* API output nonsense.
419.Pp
420.Fn EC_POINT_point2bn
421and
422.Fn EC_POINT_bn2point
423make no sense.
424They abuse
425.Vt BIGNUM
426as a vector type, which is in poor taste.
427.Pp
428.Fn EC_POINT_point2hex
429and
430.Fn EC_POINT_hex2point
431use a non-standard encoding format.