Skip to content

Commit db421c2

Browse files
davidbenBoringssl LUCI CQ
authored andcommitted
More clearly suggest passing NULL for EC and EC_KEY APIs
We didn't note they could be NULL in some APIs. Also almost all of EC ignores BN_CTX anyway, so we can just say it's ignored. For the handful of functions that don't ignore it, I think we can probably just say it hint that you can pass in NULL and, if you think you have something useful to do with BN_CTX, you probably know what it's used for. (But also we should just remove the EC code's dependency on BN_CTX. BN_CTX is really only useful when you call lots and lots of BIGNUM-using operations in a row, and neither of the remaining such operations fall under that umbrella.) Bug: 42290433 Change-Id: I2766b310ca1d28a67e45354111cc2d90fa45f113 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79988 Reviewed-by: Adam Langley <[email protected]> Auto-Submit: David Benjamin <[email protected]> Commit-Queue: Adam Langley <[email protected]>
1 parent 791b390 commit db421c2

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

include/openssl/ec.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
107107
// EC_GROUP_order_bits returns the number of bits of the order of |group|.
108108
OPENSSL_EXPORT int EC_GROUP_order_bits(const EC_GROUP *group);
109109

110-
// EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using
111-
// |ctx|, if it's not NULL. It returns one on success and zero otherwise.
110+
// EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group|. It returns
111+
// one on success and zero otherwise. |ctx| is ignored and may be NULL.
112112
OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group,
113113
BIGNUM *cofactor, BN_CTX *ctx);
114114

115115
// EC_GROUP_get_curve_GFp gets various parameters about a group. It sets
116116
// |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to
117117
// the parameters of the curve when expressed as y² = x³ + ax + b. Any of the
118118
// output parameters can be NULL. It returns one on success and zero on
119-
// error.
119+
// error. |ctx| is ignored and may be NULL.
120120
OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p,
121121
BIGNUM *out_a, BIGNUM *out_b,
122122
BN_CTX *ctx);
@@ -169,21 +169,21 @@ OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group,
169169

170170
// EC_POINT_is_on_curve returns one if |point| is an element of |group| and
171171
// and zero otherwise or when an error occurs. This is different from OpenSSL,
172-
// which returns -1 on error. If |ctx| is non-NULL, it may be used.
172+
// which returns -1 on error. |ctx| is ignored and may be NULL.
173173
OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group,
174174
const EC_POINT *point, BN_CTX *ctx);
175175

176176
// EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if
177-
// not equal and -1 on error. If |ctx| is not NULL, it may be used.
177+
// not equal and -1 on error. |ctx| is ignored and may be NULL.
178178
OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a,
179179
const EC_POINT *b, BN_CTX *ctx);
180180

181181

182182
// Point conversion.
183183

184184
// EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of
185-
// |point| using |ctx|, if it's not NULL. It returns one on success and zero
186-
// otherwise.
185+
// |point|. It returns one on success and zero otherwise. |ctx| is ignored and
186+
// may be NULL.
187187
//
188188
// Either |x| or |y| may be NULL to skip computing that coordinate. This is
189189
// slightly faster in the common case where only the x-coordinate is needed.
@@ -200,9 +200,8 @@ OPENSSL_EXPORT int EC_POINT_get_affine_coordinates(const EC_GROUP *group,
200200
BN_CTX *ctx);
201201

202202
// EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
203-
// (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
204-
// on success or zero on error. It's considered an error if the point is not on
205-
// the curve.
203+
// (|x|, |y|). |ctx| is ignored and may be NULL. It returns one on success or
204+
// zero on error. It's considered an error if the point is not on the curve.
206205
//
207206
// Note that the corresponding function in OpenSSL versions prior to 1.0.2s does
208207
// not check if the point is on the curve. This is a security-critical check, so
@@ -226,7 +225,7 @@ OPENSSL_EXPORT int EC_POINT_set_affine_coordinates(const EC_GROUP *group,
226225
// EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
227226
// into, at most, |max_out| bytes at |buf|. It returns the number of bytes
228227
// written or zero on error if |buf| is non-NULL, else the number of bytes
229-
// needed. The |ctx| argument may be used if not NULL.
228+
// needed. |ctx| is ignored and may be NULL.
230229
OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
231230
const EC_POINT *point,
232231
point_conversion_form_t form,
@@ -236,30 +235,31 @@ OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
236235
// EC_POINT_point2buf serialises |point| into the X9.62 form given by |form| to
237236
// a newly-allocated buffer and sets |*out_buf| to point to it. It returns the
238237
// length of the result on success or zero on error. The caller must release
239-
// |*out_buf| with |OPENSSL_free| when done.
238+
// |*out_buf| with |OPENSSL_free| when done. |ctx| is ignored and may be NULL.
240239
OPENSSL_EXPORT size_t EC_POINT_point2buf(const EC_GROUP *group,
241240
const EC_POINT *point,
242241
point_conversion_form_t form,
243242
uint8_t **out_buf, BN_CTX *ctx);
244243

245244
// EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the
246-
// serialised point to |cbb|. It returns one on success and zero on error.
245+
// serialised point to |cbb|. It returns one on success and zero on error. |ctx|
246+
// is ignored and may be NULL.
247247
OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group,
248248
const EC_POINT *point,
249249
point_conversion_form_t form,
250250
BN_CTX *ctx);
251251

252252
// EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format
253-
// serialisation in |buf|. It returns one on success and zero on error. The
254-
// |ctx| argument may be used if not NULL. It's considered an error if |buf|
255-
// does not represent a point on the curve.
253+
// serialisation in |buf|. It returns one on success and zero on error. |ctx|
254+
// may be NULL. It's considered an error if |buf| does not represent a point on
255+
// the curve.
256256
OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
257257
const uint8_t *buf, size_t len,
258258
BN_CTX *ctx);
259259

260260
// EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with
261261
// the given |x| coordinate and the y coordinate specified by |y_bit| (see
262-
// X9.62). It returns one on success and zero otherwise.
262+
// X9.62). It returns one on success and zero otherwise. |ctx| may be NULL.
263263
OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
264264
const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit,
265265
BN_CTX *ctx);
@@ -268,23 +268,23 @@ OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
268268
// Group operations.
269269

270270
// EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and
271-
// zero otherwise. If |ctx| is not NULL, it may be used.
271+
// zero otherwise. |ctx| is ignored and may be NULL.
272272
OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r,
273273
const EC_POINT *a, const EC_POINT *b,
274274
BN_CTX *ctx);
275275

276276
// EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and
277-
// zero otherwise. If |ctx| is not NULL, it may be used.
277+
// zero otherwise. |ctx| is ignored and may be NULL.
278278
OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r,
279279
const EC_POINT *a, BN_CTX *ctx);
280280

281281
// EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and
282-
// zero otherwise. If |ctx| is not NULL, it may be used.
282+
// zero otherwise. |ctx| is ignored and may be NULL.
283283
OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a,
284284
BN_CTX *ctx);
285285

286286
// EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero
287-
// otherwise. If |ctx| is not NULL, it may be used.
287+
// otherwise. |ctx| may be NULL.
288288
OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
289289
const BIGNUM *n, const EC_POINT *q,
290290
const BIGNUM *m, BN_CTX *ctx);
@@ -368,8 +368,8 @@ OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group,
368368
const BIGNUM *cofactor);
369369

370370
// EC_GROUP_get_order sets |*order| to the order of |group|, if it's not
371-
// NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use
372-
// |EC_GROUP_get0_order| instead.
371+
// NULL. It returns one on success and zero otherwise. |ctx| is ignored and may
372+
// be NULL. Use |EC_GROUP_get0_order| instead.
373373
OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order,
374374
BN_CTX *ctx);
375375

include/openssl/ec_key.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ OPENSSL_EXPORT int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key,
130130
// EC_KEY_oct2key decodes |len| bytes from |in| as an EC public key in X9.62
131131
// form. |key| must already have a group configured. On success, it sets the
132132
// public key in |key| to the result and returns one. Otherwise, it returns
133-
// zero.
133+
// zero. |ctx| may be NULL.
134134
OPENSSL_EXPORT int EC_KEY_oct2key(EC_KEY *key, const uint8_t *in, size_t len,
135135
BN_CTX *ctx);
136136

137137
// EC_KEY_key2buf behaves like |EC_POINT_point2buf|, except it encodes the
138-
// public key in |key|.
138+
// public key in |key|. |ctx| is ignored and may be NULL.
139139
OPENSSL_EXPORT size_t EC_KEY_key2buf(const EC_KEY *key,
140140
point_conversion_form_t form,
141141
uint8_t **out_buf, BN_CTX *ctx);

0 commit comments

Comments
 (0)