summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-10-22 12:06:08 +0000
committertb <>2024-10-22 12:06:08 +0000
commit9a39951cf4bf4613184d14df465e249ead2bdc27 (patch)
tree7eb00455a8a1a0d1dd94da11b9821efb1efe78f4 /src
parentbe5e187728b9e1db7125618e3f37ce6a553b5dbd (diff)
downloadopenbsd-9a39951cf4bf4613184d14df465e249ead2bdc27.tar.gz
openbsd-9a39951cf4bf4613184d14df465e249ead2bdc27.tar.bz2
openbsd-9a39951cf4bf4613184d14df465e249ead2bdc27.zip
Provide and use ec_group_get_field_type()
All internal uses of EC_METHOD_get_field_type() and EC_GROUP_method_of() are chained together. Implement this as a single API call that takes a group and use it throughout. Gets rid of another eyesore in this part of the tree. Not that there will be a shortage of eyesores anytime soon... ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/ec/ec_asn1.c4
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c14
-rw-r--r--src/lib/libcrypto/ec/ec_local.h3
-rw-r--r--src/lib/libcrypto/ec/eck_prn.c4
4 files changed, 17 insertions, 8 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c
index 6e97d43c5c..60225f48f9 100644
--- a/src/lib/libcrypto/ec/ec_asn1.c
+++ b/src/lib/libcrypto/ec/ec_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_asn1.c,v 1.76 2024/10/20 10:48:29 tb Exp $ */ 1/* $OpenBSD: ec_asn1.c,v 1.77 2024/10/22 12:06:08 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -570,7 +570,7 @@ ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
570 if (group == NULL || field == NULL) 570 if (group == NULL || field == NULL)
571 goto err; 571 goto err;
572 572
573 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); 573 nid = ec_group_get_field_type(group);
574 if (nid == NID_X9_62_characteristic_two_field) { 574 if (nid == NID_X9_62_characteristic_two_field) {
575 ECerror(EC_R_GF2M_NOT_SUPPORTED); 575 ECerror(EC_R_GF2M_NOT_SUPPORTED);
576 goto err; 576 goto err;
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 1918d0ba52..6da2026662 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.72 2024/10/19 08:29:40 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.73 2024/10/22 12:06:08 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 */
@@ -219,6 +219,15 @@ EC_METHOD_get_field_type(const EC_METHOD *meth)
219} 219}
220LCRYPTO_ALIAS(EC_METHOD_get_field_type); 220LCRYPTO_ALIAS(EC_METHOD_get_field_type);
221 221
222int
223ec_group_get_field_type(const EC_GROUP *group)
224{
225 if (group == NULL || group->meth == NULL)
226 return NID_undef;
227
228 return group->meth->field_type;
229}
230
222/* 231/*
223 * If there is a user-provided cofactor, sanity check and use it. Otherwise 232 * If there is a user-provided cofactor, sanity check and use it. Otherwise
224 * try computing the cofactor from generator order n and field cardinality q. 233 * try computing the cofactor from generator order n and field cardinality q.
@@ -663,8 +672,7 @@ EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
663 BN_CTX *ctx_new = NULL; 672 BN_CTX *ctx_new = NULL;
664 673
665 /* compare the field types */ 674 /* compare the field types */
666 if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) != 675 if (ec_group_get_field_type(a) != ec_group_get_field_type(b))
667 EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
668 return 1; 676 return 1;
669 /* compare the curve name (if present in both) */ 677 /* compare the curve name (if present in both) */
670 if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) && 678 if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h
index b837e291f7..4786f8520b 100644
--- a/src/lib/libcrypto/ec/ec_local.h
+++ b/src/lib/libcrypto/ec/ec_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_local.h,v 1.30 2024/10/18 17:27:07 tb Exp $ */ 1/* $OpenBSD: ec_local.h,v 1.31 2024/10/22 12:06:08 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 */
@@ -356,6 +356,7 @@ int EC_POINT_get_Jprojective_coordinates(const EC_GROUP *group,
356 const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx); 356 const EC_POINT *p, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
357 357
358int ec_group_is_builtin_curve(const EC_GROUP *group); 358int ec_group_is_builtin_curve(const EC_GROUP *group);
359int ec_group_get_field_type(const EC_GROUP *group);
359 360
360/* Public API in OpenSSL */ 361/* Public API in OpenSSL */
361const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group); 362const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c
index 2798d53d0c..847dc0a159 100644
--- a/src/lib/libcrypto/ec/eck_prn.c
+++ b/src/lib/libcrypto/ec/eck_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eck_prn.c,v 1.30 2023/11/21 22:05:33 tb Exp $ */ 1/* $OpenBSD: eck_prn.c,v 1.31 2024/10/22 12:06:08 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -258,7 +258,7 @@ ecpk_print_explicit_parameters(BIO *bp, const EC_GROUP *group, int off)
258 if (!BIO_indent(bp, off, 128)) 258 if (!BIO_indent(bp, off, 128))
259 goto err; 259 goto err;
260 260
261 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); 261 nid = ec_group_get_field_type(group);
262 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(nid)) <= 0) 262 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(nid)) <= 0)
263 goto err; 263 goto err;
264 264