summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_smpl.c
diff options
context:
space:
mode:
authortb <>2022-11-19 07:29:29 +0000
committertb <>2022-11-19 07:29:29 +0000
commit97ff0b8011f923270c9adb50e24c2b4c4a533238 (patch)
tree744c8fadca050ecfeaa626562148788777b42d2f /src/lib/libcrypto/ec/ecp_smpl.c
parentb197546e7fd8128aedea248a6196a0d25734b937 (diff)
downloadopenbsd-97ff0b8011f923270c9adb50e24c2b4c4a533238.tar.gz
openbsd-97ff0b8011f923270c9adb50e24c2b4c4a533238.tar.bz2
openbsd-97ff0b8011f923270c9adb50e24c2b4c4a533238.zip
Fix an annoying quirk in the EC code
Dealing with elliptic curves makes some people think that it would be kind of neat to multiply types with variable names. Sometimes. Only in function definitions.
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index c9d73bd629..55fb46869d 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_smpl.c,v 1.35 2022/11/19 07:00:57 tb Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.36 2022/11/19 07:29:29 tb Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -131,7 +131,7 @@ EC_GFp_simple_method(void)
131 131
132 132
133int 133int
134ec_GFp_simple_group_init(EC_GROUP * group) 134ec_GFp_simple_group_init(EC_GROUP *group)
135{ 135{
136 BN_init(&group->field); 136 BN_init(&group->field);
137 BN_init(&group->a); 137 BN_init(&group->a);
@@ -142,7 +142,7 @@ ec_GFp_simple_group_init(EC_GROUP * group)
142 142
143 143
144void 144void
145ec_GFp_simple_group_finish(EC_GROUP * group) 145ec_GFp_simple_group_finish(EC_GROUP *group)
146{ 146{
147 BN_free(&group->field); 147 BN_free(&group->field);
148 BN_free(&group->a); 148 BN_free(&group->a);
@@ -151,7 +151,7 @@ ec_GFp_simple_group_finish(EC_GROUP * group)
151 151
152 152
153void 153void
154ec_GFp_simple_group_clear_finish(EC_GROUP * group) 154ec_GFp_simple_group_clear_finish(EC_GROUP *group)
155{ 155{
156 BN_clear_free(&group->field); 156 BN_clear_free(&group->field);
157 BN_clear_free(&group->a); 157 BN_clear_free(&group->a);
@@ -160,7 +160,7 @@ ec_GFp_simple_group_clear_finish(EC_GROUP * group)
160 160
161 161
162int 162int
163ec_GFp_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src) 163ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
164{ 164{
165 if (!BN_copy(&dest->field, &src->field)) 165 if (!BN_copy(&dest->field, &src->field))
166 return 0; 166 return 0;
@@ -176,8 +176,8 @@ ec_GFp_simple_group_copy(EC_GROUP * dest, const EC_GROUP * src)
176 176
177 177
178int 178int
179ec_GFp_simple_group_set_curve(EC_GROUP * group, 179ec_GFp_simple_group_set_curve(EC_GROUP *group,
180 const BIGNUM * p, const BIGNUM * a, const BIGNUM * b, BN_CTX * ctx) 180 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
181{ 181{
182 int ret = 0; 182 int ret = 0;
183 BN_CTX *new_ctx = NULL; 183 BN_CTX *new_ctx = NULL;
@@ -233,7 +233,7 @@ ec_GFp_simple_group_set_curve(EC_GROUP * group,
233 233
234 234
235int 235int
236ec_GFp_simple_group_get_curve(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, BIGNUM * b, BN_CTX * ctx) 236ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
237{ 237{
238 int ret = 0; 238 int ret = 0;
239 BN_CTX *new_ctx = NULL; 239 BN_CTX *new_ctx = NULL;
@@ -277,14 +277,14 @@ ec_GFp_simple_group_get_curve(const EC_GROUP * group, BIGNUM * p, BIGNUM * a, BI
277 277
278 278
279int 279int
280ec_GFp_simple_group_get_degree(const EC_GROUP * group) 280ec_GFp_simple_group_get_degree(const EC_GROUP *group)
281{ 281{
282 return BN_num_bits(&group->field); 282 return BN_num_bits(&group->field);
283} 283}
284 284
285 285
286int 286int
287ec_GFp_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) 287ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
288{ 288{
289 int ret = 0; 289 int ret = 0;
290 BIGNUM *a, *b, *order, *tmp_1, *tmp_2; 290 BIGNUM *a, *b, *order, *tmp_1, *tmp_2;
@@ -372,7 +372,7 @@ ec_GFp_simple_point_init(EC_POINT * point)
372 372
373 373
374void 374void
375ec_GFp_simple_point_finish(EC_POINT * point) 375ec_GFp_simple_point_finish(EC_POINT *point)
376{ 376{
377 BN_free(&point->X); 377 BN_free(&point->X);
378 BN_free(&point->Y); 378 BN_free(&point->Y);
@@ -381,7 +381,7 @@ ec_GFp_simple_point_finish(EC_POINT * point)
381 381
382 382
383void 383void
384ec_GFp_simple_point_clear_finish(EC_POINT * point) 384ec_GFp_simple_point_clear_finish(EC_POINT *point)
385{ 385{
386 BN_clear_free(&point->X); 386 BN_clear_free(&point->X);
387 BN_clear_free(&point->Y); 387 BN_clear_free(&point->Y);
@@ -391,7 +391,7 @@ ec_GFp_simple_point_clear_finish(EC_POINT * point)
391 391
392 392
393int 393int
394ec_GFp_simple_point_copy(EC_POINT * dest, const EC_POINT * src) 394ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
395{ 395{
396 if (!BN_copy(&dest->X, &src->X)) 396 if (!BN_copy(&dest->X, &src->X))
397 return 0; 397 return 0;
@@ -406,7 +406,7 @@ ec_GFp_simple_point_copy(EC_POINT * dest, const EC_POINT * src)
406 406
407 407
408int 408int
409ec_GFp_simple_point_set_to_infinity(const EC_GROUP * group, EC_POINT * point) 409ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
410{ 410{
411 point->Z_is_one = 0; 411 point->Z_is_one = 0;
412 BN_zero(&point->Z); 412 BN_zero(&point->Z);
@@ -515,8 +515,8 @@ ec_GFp_simple_get_Jprojective_coordinates(const EC_GROUP *group,
515} 515}
516 516
517int 517int
518ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * point, 518ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
519 const BIGNUM * x, const BIGNUM * y, BN_CTX * ctx) 519 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
520{ 520{
521 if (x == NULL || y == NULL) { 521 if (x == NULL || y == NULL) {
522 /* unlike for projective coordinates, we do not tolerate this */ 522 /* unlike for projective coordinates, we do not tolerate this */
@@ -528,8 +528,8 @@ ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * po
528} 528}
529 529
530int 530int
531ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POINT * point, 531ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,
532 BIGNUM * x, BIGNUM * y, BN_CTX * ctx) 532 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
533{ 533{
534 BN_CTX *new_ctx = NULL; 534 BN_CTX *new_ctx = NULL;
535 BIGNUM *Z, *Z_1, *Z_2, *Z_3; 535 BIGNUM *Z, *Z_1, *Z_2, *Z_3;
@@ -635,7 +635,7 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POIN
635} 635}
636 636
637int 637int
638ec_GFp_simple_add(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, const EC_POINT * b, BN_CTX * ctx) 638ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
639{ 639{
640 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); 640 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
641 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); 641 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
@@ -824,7 +824,7 @@ ec_GFp_simple_add(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, cons
824 824
825 825
826int 826int
827ec_GFp_simple_dbl(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, BN_CTX * ctx) 827ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
828{ 828{
829 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); 829 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
830 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); 830 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
@@ -966,7 +966,7 @@ ec_GFp_simple_dbl(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, BN_C
966 966
967 967
968int 968int
969ec_GFp_simple_invert(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) 969ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
970{ 970{
971 if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y)) 971 if (EC_POINT_is_at_infinity(group, point) > 0 || BN_is_zero(&point->Y))
972 /* point is its own inverse */ 972 /* point is its own inverse */
@@ -977,14 +977,14 @@ ec_GFp_simple_invert(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx)
977 977
978 978
979int 979int
980ec_GFp_simple_is_at_infinity(const EC_GROUP * group, const EC_POINT * point) 980ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
981{ 981{
982 return BN_is_zero(&point->Z); 982 return BN_is_zero(&point->Z);
983} 983}
984 984
985 985
986int 986int
987ec_GFp_simple_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ctx) 987ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
988{ 988{
989 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); 989 int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
990 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); 990 int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
@@ -1087,7 +1087,7 @@ ec_GFp_simple_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX
1087 1087
1088 1088
1089int 1089int
1090ec_GFp_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT * b, BN_CTX * ctx) 1090ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
1091{ 1091{
1092 /* 1092 /*
1093 * return values: -1 error 0 equal (in affine coordinates) 1 1093 * return values: -1 error 0 equal (in affine coordinates) 1
@@ -1189,7 +1189,7 @@ ec_GFp_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT * b
1189 1189
1190 1190
1191int 1191int
1192ec_GFp_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx) 1192ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1193{ 1193{
1194 BN_CTX *new_ctx = NULL; 1194 BN_CTX *new_ctx = NULL;
1195 BIGNUM *x, *y; 1195 BIGNUM *x, *y;
@@ -1227,7 +1227,7 @@ ec_GFp_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx
1227 1227
1228 1228
1229int 1229int
1230ec_GFp_simple_points_make_affine(const EC_GROUP * group, size_t num, EC_POINT * points[], BN_CTX * ctx) 1230ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
1231{ 1231{
1232 BN_CTX *new_ctx = NULL; 1232 BN_CTX *new_ctx = NULL;
1233 BIGNUM *tmp0, *tmp1; 1233 BIGNUM *tmp0, *tmp1;
@@ -1402,13 +1402,13 @@ ec_GFp_simple_points_make_affine(const EC_GROUP * group, size_t num, EC_POINT *
1402 1402
1403 1403
1404int 1404int
1405ec_GFp_simple_field_mul(const EC_GROUP * group, BIGNUM * r, const BIGNUM * a, const BIGNUM * b, BN_CTX * ctx) 1405ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1406{ 1406{
1407 return BN_mod_mul(r, a, b, &group->field, ctx); 1407 return BN_mod_mul(r, a, b, &group->field, ctx);
1408} 1408}
1409 1409
1410int 1410int
1411ec_GFp_simple_field_sqr(const EC_GROUP * group, BIGNUM * r, const BIGNUM * a, BN_CTX * ctx) 1411ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
1412{ 1412{
1413 return BN_mod_sqr(r, a, &group->field, ctx); 1413 return BN_mod_sqr(r, a, &group->field, ctx);
1414} 1414}