summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 7cc69f8154..45df1329ff 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.41 2021/09/12 16:23:19 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.42 2022/03/29 13:44:06 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 */
@@ -114,7 +114,7 @@ EC_GROUP_new(const EC_METHOD * meth)
114} 114}
115 115
116 116
117void 117void
118EC_GROUP_free(EC_GROUP * group) 118EC_GROUP_free(EC_GROUP * group)
119{ 119{
120 if (!group) 120 if (!group)
@@ -135,7 +135,7 @@ EC_GROUP_free(EC_GROUP * group)
135} 135}
136 136
137 137
138void 138void
139EC_GROUP_clear_free(EC_GROUP * group) 139EC_GROUP_clear_free(EC_GROUP * group)
140{ 140{
141 if (!group) 141 if (!group)
@@ -157,7 +157,7 @@ EC_GROUP_clear_free(EC_GROUP * group)
157} 157}
158 158
159 159
160int 160int
161EC_GROUP_copy(EC_GROUP * dest, const EC_GROUP * src) 161EC_GROUP_copy(EC_GROUP * dest, const EC_GROUP * src)
162{ 162{
163 EC_EXTRA_DATA *d; 163 EC_EXTRA_DATA *d;
@@ -247,7 +247,7 @@ EC_GROUP_method_of(const EC_GROUP *group)
247} 247}
248 248
249 249
250int 250int
251EC_METHOD_get_field_type(const EC_METHOD *meth) 251EC_METHOD_get_field_type(const EC_METHOD *meth)
252{ 252{
253 return meth->field_type; 253 return meth->field_type;
@@ -300,7 +300,7 @@ ec_guess_cofactor(EC_GROUP *group)
300 if (!BN_copy(q, &group->field)) 300 if (!BN_copy(q, &group->field))
301 goto err; 301 goto err;
302 } 302 }
303 303
304 /* 304 /*
305 * Compute 305 * Compute
306 * h = \lfloor (q + 1)/n \rceil = \lfloor (q + 1 + n/2) / n \rfloor. 306 * h = \lfloor (q + 1)/n \rceil = \lfloor (q + 1 + n/2) / n \rfloor.
@@ -328,7 +328,7 @@ ec_guess_cofactor(EC_GROUP *group)
328 return ret; 328 return ret;
329} 329}
330 330
331int 331int
332EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, 332EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
333 const BIGNUM *order, const BIGNUM *cofactor) 333 const BIGNUM *order, const BIGNUM *cofactor)
334{ 334{
@@ -392,7 +392,7 @@ EC_GROUP_get0_generator(const EC_GROUP *group)
392} 392}
393 393
394 394
395int 395int
396EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) 396EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
397{ 397{
398 if (!BN_copy(order, &group->order)) 398 if (!BN_copy(order, &group->order))
@@ -407,7 +407,7 @@ EC_GROUP_order_bits(const EC_GROUP *group)
407 return group->meth->group_order_bits(group); 407 return group->meth->group_order_bits(group);
408} 408}
409 409
410int 410int
411EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx) 411EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
412{ 412{
413 if (!BN_copy(cofactor, &group->cofactor)) 413 if (!BN_copy(cofactor, &group->cofactor))
@@ -417,35 +417,35 @@ EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
417} 417}
418 418
419 419
420void 420void
421EC_GROUP_set_curve_name(EC_GROUP * group, int nid) 421EC_GROUP_set_curve_name(EC_GROUP * group, int nid)
422{ 422{
423 group->curve_name = nid; 423 group->curve_name = nid;
424} 424}
425 425
426 426
427int 427int
428EC_GROUP_get_curve_name(const EC_GROUP * group) 428EC_GROUP_get_curve_name(const EC_GROUP * group)
429{ 429{
430 return group->curve_name; 430 return group->curve_name;
431} 431}
432 432
433 433
434void 434void
435EC_GROUP_set_asn1_flag(EC_GROUP * group, int flag) 435EC_GROUP_set_asn1_flag(EC_GROUP * group, int flag)
436{ 436{
437 group->asn1_flag = flag; 437 group->asn1_flag = flag;
438} 438}
439 439
440 440
441int 441int
442EC_GROUP_get_asn1_flag(const EC_GROUP * group) 442EC_GROUP_get_asn1_flag(const EC_GROUP * group)
443{ 443{
444 return group->asn1_flag; 444 return group->asn1_flag;
445} 445}
446 446
447 447
448void 448void
449EC_GROUP_set_point_conversion_form(EC_GROUP * group, 449EC_GROUP_set_point_conversion_form(EC_GROUP * group,
450 point_conversion_form_t form) 450 point_conversion_form_t form)
451{ 451{
@@ -453,14 +453,14 @@ EC_GROUP_set_point_conversion_form(EC_GROUP * group,
453} 453}
454 454
455 455
456point_conversion_form_t 456point_conversion_form_t
457EC_GROUP_get_point_conversion_form(const EC_GROUP * group) 457EC_GROUP_get_point_conversion_form(const EC_GROUP * group)
458{ 458{
459 return group->asn1_form; 459 return group->asn1_form;
460} 460}
461 461
462 462
463size_t 463size_t
464EC_GROUP_set_seed(EC_GROUP * group, const unsigned char *p, size_t len) 464EC_GROUP_set_seed(EC_GROUP * group, const unsigned char *p, size_t len)
465{ 465{
466 if (group->seed) { 466 if (group->seed) {
@@ -487,7 +487,7 @@ EC_GROUP_get0_seed(const EC_GROUP * group)
487} 487}
488 488
489 489
490size_t 490size_t
491EC_GROUP_get_seed_len(const EC_GROUP * group) 491EC_GROUP_get_seed_len(const EC_GROUP * group)
492{ 492{
493 return group->seed_len; 493 return group->seed_len;
@@ -545,7 +545,7 @@ EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a,
545} 545}
546#endif 546#endif
547 547
548int 548int
549EC_GROUP_get_degree(const EC_GROUP * group) 549EC_GROUP_get_degree(const EC_GROUP * group)
550{ 550{
551 if (group->meth->group_get_degree == 0) { 551 if (group->meth->group_get_degree == 0) {
@@ -556,7 +556,7 @@ EC_GROUP_get_degree(const EC_GROUP * group)
556} 556}
557 557
558 558
559int 559int
560EC_GROUP_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) 560EC_GROUP_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
561{ 561{
562 if (group->meth->group_check_discriminant == 0) { 562 if (group->meth->group_check_discriminant == 0) {
@@ -567,7 +567,7 @@ EC_GROUP_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
567} 567}
568 568
569 569
570int 570int
571EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx) 571EC_GROUP_cmp(const EC_GROUP * a, const EC_GROUP * b, BN_CTX * ctx)
572{ 572{
573 int r = 0; 573 int r = 0;
@@ -660,7 +660,7 @@ ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx)
660} 660}
661 661
662/* this has 'package' visibility */ 662/* this has 'package' visibility */
663int 663int
664EC_EX_DATA_set_data(EC_EXTRA_DATA ** ex_data, void *data, 664EC_EX_DATA_set_data(EC_EXTRA_DATA ** ex_data, void *data,
665 void *(*dup_func) (void *), 665 void *(*dup_func) (void *),
666 void (*free_func) (void *), 666 void (*free_func) (void *),
@@ -716,7 +716,7 @@ EC_EX_DATA_get_data(const EC_EXTRA_DATA * ex_data,
716} 716}
717 717
718/* this has 'package' visibility */ 718/* this has 'package' visibility */
719void 719void
720EC_EX_DATA_free_data(EC_EXTRA_DATA ** ex_data, 720EC_EX_DATA_free_data(EC_EXTRA_DATA ** ex_data,
721 void *(*dup_func) (void *), 721 void *(*dup_func) (void *),
722 void (*free_func) (void *), 722 void (*free_func) (void *),
@@ -743,7 +743,7 @@ EC_EX_DATA_free_data(EC_EXTRA_DATA ** ex_data,
743} 743}
744 744
745/* this has 'package' visibility */ 745/* this has 'package' visibility */
746void 746void
747EC_EX_DATA_clear_free_data(EC_EXTRA_DATA ** ex_data, 747EC_EX_DATA_clear_free_data(EC_EXTRA_DATA ** ex_data,
748 void *(*dup_func) (void *), 748 void *(*dup_func) (void *),
749 void (*free_func) (void *), 749 void (*free_func) (void *),
@@ -770,7 +770,7 @@ EC_EX_DATA_clear_free_data(EC_EXTRA_DATA ** ex_data,
770} 770}
771 771
772/* this has 'package' visibility */ 772/* this has 'package' visibility */
773void 773void
774EC_EX_DATA_free_all_data(EC_EXTRA_DATA ** ex_data) 774EC_EX_DATA_free_all_data(EC_EXTRA_DATA ** ex_data)
775{ 775{
776 EC_EXTRA_DATA *d; 776 EC_EXTRA_DATA *d;
@@ -791,7 +791,7 @@ EC_EX_DATA_free_all_data(EC_EXTRA_DATA ** ex_data)
791} 791}
792 792
793/* this has 'package' visibility */ 793/* this has 'package' visibility */
794void 794void
795EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA ** ex_data) 795EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA ** ex_data)
796{ 796{
797 EC_EXTRA_DATA *d; 797 EC_EXTRA_DATA *d;
@@ -842,7 +842,7 @@ EC_POINT_new(const EC_GROUP * group)
842} 842}
843 843
844 844
845void 845void
846EC_POINT_free(EC_POINT * point) 846EC_POINT_free(EC_POINT * point)
847{ 847{
848 if (!point) 848 if (!point)
@@ -854,7 +854,7 @@ EC_POINT_free(EC_POINT * point)
854} 854}
855 855
856 856
857void 857void
858EC_POINT_clear_free(EC_POINT * point) 858EC_POINT_clear_free(EC_POINT * point)
859{ 859{
860 if (!point) 860 if (!point)
@@ -868,7 +868,7 @@ EC_POINT_clear_free(EC_POINT * point)
868} 868}
869 869
870 870
871int 871int
872EC_POINT_copy(EC_POINT * dest, const EC_POINT * src) 872EC_POINT_copy(EC_POINT * dest, const EC_POINT * src)
873{ 873{
874 if (dest->meth->point_copy == 0) { 874 if (dest->meth->point_copy == 0) {
@@ -913,7 +913,7 @@ EC_POINT_method_of(const EC_POINT * point)
913} 913}
914 914
915 915
916int 916int
917EC_POINT_set_to_infinity(const EC_GROUP * group, EC_POINT * point) 917EC_POINT_set_to_infinity(const EC_GROUP * group, EC_POINT * point)
918{ 918{
919 if (group->meth->point_set_to_infinity == 0) { 919 if (group->meth->point_set_to_infinity == 0) {
@@ -1041,7 +1041,7 @@ EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *poin
1041} 1041}
1042#endif 1042#endif
1043 1043
1044int 1044int
1045EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, 1045EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
1046 const EC_POINT *b, BN_CTX *ctx) 1046 const EC_POINT *b, BN_CTX *ctx)
1047{ 1047{
@@ -1057,7 +1057,7 @@ EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
1057} 1057}
1058 1058
1059 1059
1060int 1060int
1061EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx) 1061EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1062{ 1062{
1063 if (group->meth->dbl == 0) { 1063 if (group->meth->dbl == 0) {
@@ -1072,7 +1072,7 @@ EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
1072} 1072}
1073 1073
1074 1074
1075int 1075int
1076EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx) 1076EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
1077{ 1077{
1078 if (group->meth->invert == 0) { 1078 if (group->meth->invert == 0) {
@@ -1087,7 +1087,7 @@ EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
1087} 1087}
1088 1088
1089 1089
1090int 1090int
1091EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) 1091EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1092{ 1092{
1093 if (group->meth->is_at_infinity == 0) { 1093 if (group->meth->is_at_infinity == 0) {
@@ -1102,7 +1102,7 @@ EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
1102} 1102}
1103 1103
1104 1104
1105int 1105int
1106EC_POINT_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ctx) 1106EC_POINT_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ctx)
1107{ 1107{
1108 if (group->meth->is_on_curve == 0) { 1108 if (group->meth->is_on_curve == 0) {
@@ -1117,7 +1117,7 @@ EC_POINT_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ct
1117} 1117}
1118 1118
1119 1119
1120int 1120int
1121EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, 1121EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
1122 BN_CTX * ctx) 1122 BN_CTX * ctx)
1123{ 1123{
@@ -1133,7 +1133,7 @@ EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
1133} 1133}
1134 1134
1135 1135
1136int 1136int
1137EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) 1137EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1138{ 1138{
1139 if (group->meth->make_affine == 0) { 1139 if (group->meth->make_affine == 0) {
@@ -1148,7 +1148,7 @@ EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1148} 1148}
1149 1149
1150 1150
1151int 1151int
1152EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], 1152EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
1153 BN_CTX *ctx) 1153 BN_CTX *ctx)
1154{ 1154{
@@ -1169,7 +1169,7 @@ EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
1169 1169
1170 1170
1171/* Functions for point multiplication */ 1171/* Functions for point multiplication */
1172int 1172int
1173EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 1173EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1174 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) 1174 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
1175{ 1175{
@@ -1184,22 +1184,22 @@ EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1184 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 1184 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1185 return 0; 1185 return 0;
1186 } 1186 }
1187 1187
1188 /* Either bP or aG + bP, this is sane. */ 1188 /* Either bP or aG + bP, this is sane. */
1189 if (num == 1 && points != NULL && scalars != NULL) 1189 if (num == 1 && points != NULL && scalars != NULL)
1190 return EC_POINT_mul(group, r, scalar, points[0], scalars[0], 1190 return EC_POINT_mul(group, r, scalar, points[0], scalars[0],
1191 ctx); 1191 ctx);
1192 1192
1193 /* aG, this is sane */ 1193 /* aG, this is sane */
1194 if (scalar != NULL && points == NULL && scalars == NULL) 1194 if (scalar != NULL && points == NULL && scalars == NULL)
1195 return EC_POINT_mul(group, r, scalar, NULL, NULL, ctx); 1195 return EC_POINT_mul(group, r, scalar, NULL, NULL, ctx);
1196 1196
1197 /* anything else is an error */ 1197 /* anything else is an error */
1198 ECerror(ERR_R_EC_LIB); 1198 ECerror(ERR_R_EC_LIB);
1199 return 0; 1199 return 0;
1200} 1200}
1201 1201
1202int 1202int
1203EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, 1203EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
1204 const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx) 1204 const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
1205{ 1205{
@@ -1241,13 +1241,13 @@ EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
1241 return group->meth->mul_double_nonct(group, r, g_scalar, 1241 return group->meth->mul_double_nonct(group, r, g_scalar,
1242 p_scalar, point, ctx); 1242 p_scalar, point, ctx);
1243 } 1243 }
1244 1244
1245 /* Anything else is an error. */ 1245 /* Anything else is an error. */
1246 ECerror(ERR_R_EC_LIB); 1246 ECerror(ERR_R_EC_LIB);
1247 return 0; 1247 return 0;
1248} 1248}
1249 1249
1250int 1250int
1251EC_GROUP_precompute_mult(EC_GROUP * group, BN_CTX * ctx) 1251EC_GROUP_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
1252{ 1252{
1253 if (group->meth->precompute_mult != 0) 1253 if (group->meth->precompute_mult != 0)
@@ -1256,7 +1256,7 @@ EC_GROUP_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
1256 return 1; /* nothing to do, so report success */ 1256 return 1; /* nothing to do, so report success */
1257} 1257}
1258 1258
1259int 1259int
1260EC_GROUP_have_precompute_mult(const EC_GROUP * group) 1260EC_GROUP_have_precompute_mult(const EC_GROUP * group)
1261{ 1261{
1262 if (group->meth->have_precompute_mult != 0) 1262 if (group->meth->have_precompute_mult != 0)
@@ -1290,5 +1290,5 @@ ECParameters_dup(EC_KEY *key)
1290 if ((len = i2d_ECParameters(key, &p)) > 0) 1290 if ((len = i2d_ECParameters(key, &p)) > 0)
1291 k = d2i_ECParameters(NULL, (const unsigned char **)&p, len); 1291 k = d2i_ECParameters(NULL, (const unsigned char **)&p, len);
1292 1292
1293 return (k); 1293 return (k);
1294} 1294}