summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-04-26 13:12:51 +0000
committertb <>2023-04-26 13:12:51 +0000
commitcec7d1174b0f85cfc05c43a707b91775cd4cac4a (patch)
treea688d96c5729a8201ab22ce56744f2849094a580 /src
parent3897ed1652bd01906e2eea757683ae60f400317e (diff)
downloadopenbsd-cec7d1174b0f85cfc05c43a707b91775cd4cac4a.tar.gz
openbsd-cec7d1174b0f85cfc05c43a707b91775cd4cac4a.tar.bz2
openbsd-cec7d1174b0f85cfc05c43a707b91775cd4cac4a.zip
Clean up ec.h a little.
The doxygen comments are either obvious or otherwise unhelpful and generally an eye sore. Go read the manpage if the header isn't enough.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/ec/ec.h217
1 files changed, 31 insertions, 186 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
index 1afbe0ad16..0589e36d98 100644
--- a/src/lib/libcrypto/ec/ec.h
+++ b/src/lib/libcrypto/ec/ec.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec.h,v 1.38 2023/04/25 19:53:30 tb Exp $ */ 1/* $OpenBSD: ec.h,v 1.39 2023/04/26 13:12:51 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -14,7 +14,7 @@
14 * are met: 14 * are met:
15 * 15 *
16 * 1. Redistributions of source code must retain the above copyright 16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer. 17 * notice, this list of conditions and the following disclaimer.
18 * 18 *
19 * 2. Redistributions in binary form must reproduce the above copyright 19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in 20 * notice, this list of conditions and the following disclaimer in
@@ -62,15 +62,14 @@
62/* ==================================================================== 62/* ====================================================================
63 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 63 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
64 * 64 *
65 * Portions of the attached software ("Contribution") are developed by 65 * Portions of the attached software ("Contribution") are developed by
66 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 66 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
67 * 67 *
68 * The Contribution is licensed pursuant to the OpenSSL open source 68 * The Contribution is licensed pursuant to the OpenSSL open source
69 * license provided above. 69 * license provided above.
70 * 70 *
71 * The elliptic curve binary polynomial software is originally written by 71 * The elliptic curve binary polynomial software is originally written by
72 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. 72 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
73 *
74 */ 73 */
75 74
76#ifndef HEADER_EC_H 75#ifndef HEADER_EC_H
@@ -93,149 +92,45 @@ extern "C" {
93# endif 92# endif
94#endif 93#endif
95 94
96
97#ifndef OPENSSL_ECC_MAX_FIELD_BITS 95#ifndef OPENSSL_ECC_MAX_FIELD_BITS
98#define OPENSSL_ECC_MAX_FIELD_BITS 661 96#define OPENSSL_ECC_MAX_FIELD_BITS 661
99#endif 97#endif
100 98
101/** Enum for the point conversion form as defined in X9.62 (ECDSA) 99/* Elliptic point conversion form as per X9.62, page 4 and section 4.4.2. */
102 * for the encoding of a elliptic curve point (x,y) */
103typedef enum { 100typedef enum {
104 /** the point is encoded as z||x, where the octet z specifies
105 * which solution of the quadratic equation y is */
106 POINT_CONVERSION_COMPRESSED = 2, 101 POINT_CONVERSION_COMPRESSED = 2,
107 /** the point is encoded as z||x||y, where z is the octet 0x02 */
108 POINT_CONVERSION_UNCOMPRESSED = 4, 102 POINT_CONVERSION_UNCOMPRESSED = 4,
109 /** the point is encoded as z||x||y, where the octet z specifies
110 * which solution of the quadratic equation y is */
111 POINT_CONVERSION_HYBRID = 6 103 POINT_CONVERSION_HYBRID = 6
112} point_conversion_form_t; 104} point_conversion_form_t;
113 105
114
115typedef struct ec_method_st EC_METHOD; 106typedef struct ec_method_st EC_METHOD;
116 107typedef struct ec_group_st EC_GROUP;
117typedef struct ec_group_st
118 /*
119 EC_METHOD *meth;
120 -- field definition
121 -- curve coefficients
122 -- optional generator with associated information (order, cofactor)
123 -- optional extra data (precomputed table for fast computation of multiples of generator)
124 -- ASN1 stuff
125 */
126 EC_GROUP;
127
128typedef struct ec_point_st EC_POINT; 108typedef struct ec_point_st EC_POINT;
129 109
130
131/********************************************************************/
132/* EC_METHODs for curves over GF(p) */
133/********************************************************************/
134
135/** Returns the basic GFp ec methods which provides the basis for the
136 * optimized methods.
137 * \return EC_METHOD object
138 */
139const EC_METHOD *EC_GFp_simple_method(void); 110const EC_METHOD *EC_GFp_simple_method(void);
140
141/** Returns GFp methods using montgomery multiplication.
142 * \return EC_METHOD object
143 */
144const EC_METHOD *EC_GFp_mont_method(void); 111const EC_METHOD *EC_GFp_mont_method(void);
145 112
146
147/********************************************************************/
148/* EC_GROUP functions */
149/********************************************************************/
150
151/** Creates a new EC_GROUP object
152 * \param meth EC_METHOD to use
153 * \return newly created EC_GROUP object or NULL in case of an error.
154 */
155EC_GROUP *EC_GROUP_new(const EC_METHOD *meth); 113EC_GROUP *EC_GROUP_new(const EC_METHOD *meth);
156
157/** Frees a EC_GROUP object
158 * \param group EC_GROUP object to be freed.
159 */
160void EC_GROUP_free(EC_GROUP *group); 114void EC_GROUP_free(EC_GROUP *group);
161
162/** Clears and frees a EC_GROUP object
163 * \param group EC_GROUP object to be cleared and freed.
164 */
165#ifndef LIBRESSL_INTERNAL 115#ifndef LIBRESSL_INTERNAL
166void EC_GROUP_clear_free(EC_GROUP *group); 116void EC_GROUP_clear_free(EC_GROUP *group);
167#endif 117#endif
168 118
169/** Copies EC_GROUP objects. Note: both EC_GROUPs must use the same EC_METHOD.
170 * \param dst destination EC_GROUP object
171 * \param src source EC_GROUP object
172 * \return 1 on success and 0 if an error occurred.
173 */
174int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src); 119int EC_GROUP_copy(EC_GROUP *dst, const EC_GROUP *src);
175
176/** Creates a new EC_GROUP object and copies the copies the content
177 * form src to the newly created EC_KEY object
178 * \param src source EC_GROUP object
179 * \return newly created EC_GROUP object or NULL in case of an error.
180 */
181EC_GROUP *EC_GROUP_dup(const EC_GROUP *src); 120EC_GROUP *EC_GROUP_dup(const EC_GROUP *src);
182 121
183/** Returns the EC_METHOD of the EC_GROUP object.
184 * \param group EC_GROUP object
185 * \return EC_METHOD used in this EC_GROUP object.
186 */
187const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); 122const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
188
189/** Returns the field type of the EC_METHOD.
190 * \param meth EC_METHOD object
191 * \return NID of the underlying field type OID.
192 */
193int EC_METHOD_get_field_type(const EC_METHOD *meth); 123int EC_METHOD_get_field_type(const EC_METHOD *meth);
194 124
195/** Sets the generator and it's order/cofactor of a EC_GROUP object. 125int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
196 * \param group EC_GROUP object 126 const BIGNUM *order, const BIGNUM *cofactor);
197 * \param generator EC_POINT object with the generator.
198 * \param order the order of the group generated by the generator.
199 * \param cofactor the index of the sub-group generated by the generator
200 * in the group of all points on the elliptic curve.
201 * \return 1 on success and 0 if an error occurred
202 */
203int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
204
205/** Returns the generator of a EC_GROUP object.
206 * \param group EC_GROUP object
207 * \return the currently used generator (possibly NULL).
208 */
209const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); 127const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
210 128
211/** Gets the order of a EC_GROUP
212 * \param group EC_GROUP object
213 * \param order BIGNUM to which the order is copied
214 * \param ctx BN_CTX object (optional)
215 * \return 1 on success and 0 if an error occurred
216 */
217int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); 129int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
218
219int EC_GROUP_order_bits(const EC_GROUP *group); 130int EC_GROUP_order_bits(const EC_GROUP *group);
220
221/** Gets the cofactor of a EC_GROUP
222 * \param group EC_GROUP object
223 * \param cofactor BIGNUM to which the cofactor is copied
224 * \param ctx BN_CTX object (optional)
225 * \return 1 on success and 0 if an error occurred
226 */
227int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx); 131int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
228 132
229/** Sets the name of a EC_GROUP object
230 * \param group EC_GROUP object
231 * \param nid NID of the curve name OID
232 */
233void EC_GROUP_set_curve_name(EC_GROUP *group, int nid); 133void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
234
235/** Returns the curve name of a EC_GROUP object
236 * \param group EC_GROUP object
237 * \return NID of the curve name OID or 0 if not set.
238 */
239int EC_GROUP_get_curve_name(const EC_GROUP *group); 134int EC_GROUP_get_curve_name(const EC_GROUP *group);
240 135
241void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); 136void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
@@ -252,88 +147,38 @@ int EC_GROUP_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
252 const BIGNUM *b, BN_CTX *ctx); 147 const BIGNUM *b, BN_CTX *ctx);
253int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, 148int EC_GROUP_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b,
254 BN_CTX *ctx); 149 BN_CTX *ctx);
255#if !defined(LIBRESSL_INTERNAL)
256/** Sets the parameter of a ec over GFp defined by y^2 = x^3 + a*x + b
257 * \param group EC_GROUP object
258 * \param p BIGNUM with the prime number
259 * \param a BIGNUM with parameter a of the equation
260 * \param b BIGNUM with parameter b of the equation
261 * \param ctx BN_CTX object (optional)
262 * \return 1 on success and 0 if an error occurred
263 */
264int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
265 150
266/** Gets the parameter of the ec over GFp defined by y^2 = x^3 + a*x + b 151#if !defined(LIBRESSL_INTERNAL)
267 * \param group EC_GROUP object 152int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
268 * \param p BIGNUM for the prime number 153 const BIGNUM *b, BN_CTX *ctx);
269 * \param a BIGNUM for parameter a of the equation 154int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
270 * \param b BIGNUM for parameter b of the equation 155 BIGNUM *b, BN_CTX *ctx);
271 * \param ctx BN_CTX object (optional)
272 * \return 1 on success and 0 if an error occurred
273 */
274int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
275#endif 156#endif
276 157
277/** Returns the number of bits needed to represent a field element
278 * \param group EC_GROUP object
279 * \return number of bits needed to represent a field element
280 */
281int EC_GROUP_get_degree(const EC_GROUP *group); 158int EC_GROUP_get_degree(const EC_GROUP *group);
282 159
283/** Checks whether the parameter in the EC_GROUP define a valid ec group
284 * \param group EC_GROUP object
285 * \param ctx BN_CTX object (optional)
286 * \return 1 if group is a valid ec group and 0 otherwise
287 */
288int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx); 160int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
289
290/** Checks whether the discriminant of the elliptic curve is zero or not
291 * \param group EC_GROUP object
292 * \param ctx BN_CTX object (optional)
293 * \return 1 if the discriminant is not zero and 0 otherwise
294 */
295int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx); 161int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx);
296 162
297/** Compares two EC_GROUP objects 163/* Compare two EC_GROUPs. Returns 0 if both groups are equal, 1 otherwise. */
298 * \param a first EC_GROUP object
299 * \param b second EC_GROUP object
300 * \param ctx BN_CTX object (optional)
301 * \return 0 if both groups are equal and 1 otherwise
302 */
303int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx); 164int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx);
304 165
305/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*() 166EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
306 * after choosing an appropriate EC_METHOD */ 167 const BIGNUM *b, BN_CTX *ctx);
307
308/** Creates a new EC_GROUP object with the specified parameters defined
309 * over GFp (defined by the equation y^2 = x^3 + a*x + b)
310 * \param p BIGNUM with the prime number
311 * \param a BIGNUM with the parameter a of the equation
312 * \param b BIGNUM with the parameter b of the equation
313 * \param ctx BN_CTX object (optional)
314 * \return newly created EC_GROUP object with the specified parameters
315 */
316EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
317/** Creates a EC_GROUP object with a curve specified by a NID
318 * \param nid NID of the OID of the curve name
319 * \return newly created EC_GROUP object with specified curve or NULL
320 * if an error occurred
321 */
322EC_GROUP *EC_GROUP_new_by_curve_name(int nid); 168EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
323 169
324
325/********************************************************************/ 170/********************************************************************/
326/* handling of internal curves */ 171/* handling of internal curves */
327/********************************************************************/ 172/********************************************************************/
328 173
329typedef struct { 174typedef struct {
330 int nid; 175 int nid;
331 const char *comment; 176 const char *comment;
332 } EC_builtin_curve; 177 } EC_builtin_curve;
333 178
334/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number 179/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
335 * of all available curves or zero if a error occurred. 180 * of all available curves or zero if a error occurred.
336 * In case r ist not zero nitems EC_builtin_curve structures 181 * In case r ist not zero nitems EC_builtin_curve structures
337 * are filled with the data of the first nitems internal groups */ 182 * are filled with the data of the first nitems internal groups */
338size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 183size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
339 184
@@ -373,11 +218,11 @@ int EC_POINT_copy(EC_POINT *dst, const EC_POINT *src);
373 * EC_POINT 218 * EC_POINT
374 * \param src source EC_POINT object 219 * \param src source EC_POINT object
375 * \param group underlying the EC_GROUP object 220 * \param group underlying the EC_GROUP object
376 * \return newly created EC_POINT object or NULL if an error occurred 221 * \return newly created EC_POINT object or NULL if an error occurred
377 */ 222 */
378EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group); 223EC_POINT *EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group);
379 224
380/** Returns the EC_METHOD used in EC_POINT object 225/** Returns the EC_METHOD used in EC_POINT object
381 * \param point EC_POINT object 226 * \param point EC_POINT object
382 * \return the EC_METHOD used 227 * \return the EC_METHOD used
383 */ 228 */
@@ -504,7 +349,7 @@ EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
504/* functions for doing EC_POINT arithmetic */ 349/* functions for doing EC_POINT arithmetic */
505/********************************************************************/ 350/********************************************************************/
506 351
507/** Computes the sum of two EC_POINT 352/** Computes the sum of two EC_POINT
508 * \param group underlying EC_GROUP object 353 * \param group underlying EC_GROUP object
509 * \param r EC_POINT object for the result (r = a + b) 354 * \param r EC_POINT object for the result (r = a + b)
510 * \param a EC_POINT object with the first summand 355 * \param a EC_POINT object with the first summand
@@ -517,7 +362,7 @@ int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC
517/** Computes the double of a EC_POINT 362/** Computes the double of a EC_POINT
518 * \param group underlying EC_GROUP object 363 * \param group underlying EC_GROUP object
519 * \param r EC_POINT object for the result (r = 2 * a) 364 * \param r EC_POINT object for the result (r = 2 * a)
520 * \param a EC_POINT object 365 * \param a EC_POINT object
521 * \param ctx BN_CTX object (optional) 366 * \param ctx BN_CTX object (optional)
522 * \return 1 on success and 0 if an error occurred 367 * \return 1 on success and 0 if an error occurred
523 */ 368 */
@@ -538,7 +383,7 @@ int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx);
538 */ 383 */
539int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p); 384int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
540 385
541/** Checks whether the point is on the curve 386/** Checks whether the point is on the curve
542 * \param group underlying EC_GROUP object 387 * \param group underlying EC_GROUP object
543 * \param point EC_POINT object to check 388 * \param point EC_POINT object to check
544 * \param ctx BN_CTX object (optional) 389 * \param ctx BN_CTX object (optional)
@@ -546,7 +391,7 @@ int EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *p);
546 */ 391 */
547int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx); 392int EC_POINT_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx);
548 393
549/** Compares two EC_POINTs 394/** Compares two EC_POINTs
550 * \param group underlying EC_GROUP object 395 * \param group underlying EC_GROUP object
551 * \param a first EC_POINT object 396 * \param a first EC_POINT object
552 * \param b second EC_POINT object 397 * \param b second EC_POINT object
@@ -654,7 +499,7 @@ void EC_KEY_clear_flags(EC_KEY *key, int flags);
654/** Creates a new EC_KEY object using a named curve as underlying 499/** Creates a new EC_KEY object using a named curve as underlying
655 * EC_GROUP object. 500 * EC_GROUP object.
656 * \param nid NID of the named curve. 501 * \param nid NID of the named curve.
657 * \return EC_KEY object or NULL if an error occurred. 502 * \return EC_KEY object or NULL if an error occurred.
658 */ 503 */
659EC_KEY *EC_KEY_new_by_curve_name(int nid); 504EC_KEY *EC_KEY_new_by_curve_name(int nid);
660 505
@@ -732,7 +577,7 @@ void EC_KEY_set_conv_form(EC_KEY *eckey, point_conversion_form_t cform);
732/* wrapper functions for the underlying EC_GROUP object */ 577/* wrapper functions for the underlying EC_GROUP object */
733void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag); 578void EC_KEY_set_asn1_flag(EC_KEY *eckey, int asn1_flag);
734 579
735/** Creates a table of pre-computed multiples of the generator to 580/** Creates a table of pre-computed multiples of the generator to
736 * accelerate further EC_KEY operations. 581 * accelerate further EC_KEY operations.
737 * \param key EC_KEY object 582 * \param key EC_KEY object
738 * \param ctx BN_CTX object (optional) 583 * \param ctx BN_CTX object (optional)
@@ -838,7 +683,7 @@ int ECParameters_print(BIO *bp, const EC_KEY *key);
838/** Prints out the contents of a EC_KEY object 683/** Prints out the contents of a EC_KEY object
839 * \param bp BIO object to which the information is printed 684 * \param bp BIO object to which the information is printed
840 * \param key EC_KEY object 685 * \param key EC_KEY object
841 * \param off line offset 686 * \param off line offset
842 * \return 1 on success and 0 if an error occurred 687 * \return 1 on success and 0 if an error occurred
843 */ 688 */
844int EC_KEY_print(BIO *bp, const EC_KEY *key, int off); 689int EC_KEY_print(BIO *bp, const EC_KEY *key, int off);
@@ -854,7 +699,7 @@ int ECParameters_print_fp(FILE *fp, const EC_KEY *key);
854/** Prints out the contents of a EC_KEY object 699/** Prints out the contents of a EC_KEY object
855 * \param fp file descriptor to which the information is printed 700 * \param fp file descriptor to which the information is printed
856 * \param key EC_KEY object 701 * \param key EC_KEY object
857 * \param off line offset 702 * \param off line offset
858 * \return 1 on success and 0 if an error occurred 703 * \return 1 on success and 0 if an error occurred
859 */ 704 */
860int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off); 705int EC_KEY_print_fp(FILE *fp, const EC_KEY *key, int off);