summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-09-08 17:29:21 +0000
committertb <>2021-09-08 17:29:21 +0000
commit09dc01256be118ca20e96739a541aa5ab2337cb2 (patch)
tree485cf97ff684d5d16d39d0844f1d400d6316796e /src/lib
parent89f6d34cf9f060f82018bcbb76af08958dbebdab (diff)
downloadopenbsd-09dc01256be118ca20e96739a541aa5ab2337cb2.tar.gz
openbsd-09dc01256be118ca20e96739a541aa5ab2337cb2.tar.bz2
openbsd-09dc01256be118ca20e96739a541aa5ab2337cb2.zip
Prepare to provide EC_GROUP_order_bits()
ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ec/ec.h6
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c9
-rw-r--r--src/lib/libcrypto/ec/ec_lcl.h9
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c18
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp224.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp256.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp521.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_nistz256.c3
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c3
11 files changed, 45 insertions, 18 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
index 61b70897f9..b1cba7d6c8 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.24 2021/05/10 16:58:19 tb Exp $ */ 1/* $OpenBSD: ec.h,v 1.25 2021/09/08 17:29:21 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 */
@@ -250,6 +250,10 @@ const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
250 */ 250 */
251int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); 251int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx);
252 252
253#if defined(LIBRESSL_INTERNAL)
254int EC_GROUP_order_bits(const EC_GROUP *group);
255#endif
256
253/** Gets the cofactor of a EC_GROUP 257/** Gets the cofactor of a EC_GROUP
254 * \param group EC_GROUP object 258 * \param group EC_GROUP object
255 * \param cofactor BIGNUM to which the cofactor is copied 259 * \param cofactor BIGNUM to which the cofactor is copied
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index f99615a0d5..9f3b380bfe 100644
--- a/src/lib/libcrypto/ec/ec2_smpl.c
+++ b/src/lib/libcrypto/ec/ec2_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_smpl.c,v 1.22 2021/04/20 17:16:37 tb Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.23 2021/09/08 17:29:21 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -88,17 +88,18 @@ EC_GF2m_simple_method(void)
88 .group_set_curve = ec_GF2m_simple_group_set_curve, 88 .group_set_curve = ec_GF2m_simple_group_set_curve,
89 .group_get_curve = ec_GF2m_simple_group_get_curve, 89 .group_get_curve = ec_GF2m_simple_group_get_curve,
90 .group_get_degree = ec_GF2m_simple_group_get_degree, 90 .group_get_degree = ec_GF2m_simple_group_get_degree,
91 .group_order_bits = ec_group_simple_order_bits,
91 .group_check_discriminant = 92 .group_check_discriminant =
92 ec_GF2m_simple_group_check_discriminant, 93 ec_GF2m_simple_group_check_discriminant,
93 .point_init = ec_GF2m_simple_point_init, 94 .point_init = ec_GF2m_simple_point_init,
94 .point_finish = ec_GF2m_simple_point_finish, 95 .point_finish = ec_GF2m_simple_point_finish,
95 .point_clear_finish = ec_GF2m_simple_point_clear_finish, 96 .point_clear_finish = ec_GF2m_simple_point_clear_finish,
96 .point_copy = ec_GF2m_simple_point_copy, 97 .point_copy = ec_GF2m_simple_point_copy,
97 .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity, 98 .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity,
98 .point_set_affine_coordinates = 99 .point_set_affine_coordinates =
99 ec_GF2m_simple_point_set_affine_coordinates, 100 ec_GF2m_simple_point_set_affine_coordinates,
100 .point_get_affine_coordinates = 101 .point_get_affine_coordinates =
101 ec_GF2m_simple_point_get_affine_coordinates, 102 ec_GF2m_simple_point_get_affine_coordinates,
102 .add = ec_GF2m_simple_add, 103 .add = ec_GF2m_simple_add,
103 .dbl = ec_GF2m_simple_dbl, 104 .dbl = ec_GF2m_simple_dbl,
104 .invert = ec_GF2m_simple_invert, 105 .invert = ec_GF2m_simple_invert,
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h
index a0343aa1d2..ced04c7e31 100644
--- a/src/lib/libcrypto/ec/ec_lcl.h
+++ b/src/lib/libcrypto/ec/ec_lcl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lcl.h,v 1.17 2021/04/20 17:32:57 tb Exp $ */ 1/* $OpenBSD: ec_lcl.h,v 1.18 2021/09/08 17:29:21 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 */
@@ -111,7 +111,8 @@ struct ec_method_st {
111 111
112 /* used by EC_GROUP_get_degree: */ 112 /* used by EC_GROUP_get_degree: */
113 int (*group_get_degree)(const EC_GROUP *); 113 int (*group_get_degree)(const EC_GROUP *);
114 114 /* used by EC_GROUP_order_bits: */
115 int (*group_order_bits)(const EC_GROUP *);
115 /* used by EC_GROUP_check: */ 116 /* used by EC_GROUP_check: */
116 int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); 117 int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *);
117 118
@@ -282,7 +283,7 @@ void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **,
282void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **); 283void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **);
283void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **); 284void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **);
284 285
285 286int ec_group_simple_order_bits(const EC_GROUP *group);
286 287
287struct ec_point_st { 288struct ec_point_st {
288 const EC_METHOD *meth; 289 const EC_METHOD *meth;
@@ -297,8 +298,6 @@ struct ec_point_st {
297 int Z_is_one; /* enable optimized point arithmetics for special case */ 298 int Z_is_one; /* enable optimized point arithmetics for special case */
298} /* EC_POINT */; 299} /* EC_POINT */;
299 300
300
301
302/* method functions in ec_mult.c 301/* method functions in ec_mult.c
303 * (ec_lib.c uses these as defaults if group->method->mul is 0) */ 302 * (ec_lib.c uses these as defaults if group->method->mul is 0) */
304int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 303int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index e763e6b70c..994fd2d4c1 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.39 2021/04/20 17:29:21 tb Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.40 2021/09/08 17:29:21 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 */
@@ -401,6 +401,11 @@ EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
401 return !BN_is_zero(order); 401 return !BN_is_zero(order);
402} 402}
403 403
404int
405EC_GROUP_order_bits(const EC_GROUP *group)
406{
407 return group->meth->group_order_bits(group);
408}
404 409
405int 410int
406EC_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)
@@ -1261,6 +1266,17 @@ EC_GROUP_have_precompute_mult(const EC_GROUP * group)
1261 * been performed */ 1266 * been performed */
1262} 1267}
1263 1268
1269int
1270ec_group_simple_order_bits(const EC_GROUP *group)
1271{
1272 /* XXX change group->order to a pointer? */
1273#if 0
1274 if (group->order == NULL)
1275 return 0;
1276#endif
1277 return BN_num_bits(&group->order);
1278}
1279
1264EC_KEY * 1280EC_KEY *
1265ECParameters_dup(EC_KEY *key) 1281ECParameters_dup(EC_KEY *key)
1266{ 1282{
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index f371e3ec8f..0da3083d8e 100644
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_mont.c,v 1.19 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.20 2021/09/08 17:29:21 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 */
@@ -79,6 +79,7 @@ EC_GFp_mont_method(void)
79 .group_set_curve = ec_GFp_mont_group_set_curve, 79 .group_set_curve = ec_GFp_mont_group_set_curve,
80 .group_get_curve = ec_GFp_simple_group_get_curve, 80 .group_get_curve = ec_GFp_simple_group_get_curve,
81 .group_get_degree = ec_GFp_simple_group_get_degree, 81 .group_get_degree = ec_GFp_simple_group_get_degree,
82 .group_order_bits = ec_group_simple_order_bits,
82 .group_check_discriminant = 83 .group_check_discriminant =
83 ec_GFp_simple_group_check_discriminant, 84 ec_GFp_simple_group_check_discriminant,
84 .point_init = ec_GFp_simple_point_init, 85 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
index 14ebe7d126..f7dae16e47 100644
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nist.c,v 1.17 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_nist.c,v 1.18 2021/09/08 17:29:21 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -80,6 +80,7 @@ EC_GFp_nist_method(void)
80 .group_set_curve = ec_GFp_nist_group_set_curve, 80 .group_set_curve = ec_GFp_nist_group_set_curve,
81 .group_get_curve = ec_GFp_simple_group_get_curve, 81 .group_get_curve = ec_GFp_simple_group_get_curve,
82 .group_get_degree = ec_GFp_simple_group_get_degree, 82 .group_get_degree = ec_GFp_simple_group_get_degree,
83 .group_order_bits = ec_group_simple_order_bits,
83 .group_check_discriminant = 84 .group_check_discriminant =
84 ec_GFp_simple_group_check_discriminant, 85 ec_GFp_simple_group_check_discriminant,
85 .point_init = ec_GFp_simple_point_init, 86 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c
index 4ed45df896..9ef9dc3585 100644
--- a/src/lib/libcrypto/ec/ecp_nistp224.c
+++ b/src/lib/libcrypto/ec/ecp_nistp224.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp224.c,v 1.26 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_nistp224.c,v 1.27 2021/09/08 17:29:21 tb Exp $ */
2/* 2/*
3 * Written by Emilia Kasper (Google) for the OpenSSL project. 3 * Written by Emilia Kasper (Google) for the OpenSSL project.
4 */ 4 */
@@ -243,6 +243,7 @@ EC_GFp_nistp224_method(void)
243 .group_set_curve = ec_GFp_nistp224_group_set_curve, 243 .group_set_curve = ec_GFp_nistp224_group_set_curve,
244 .group_get_curve = ec_GFp_simple_group_get_curve, 244 .group_get_curve = ec_GFp_simple_group_get_curve,
245 .group_get_degree = ec_GFp_simple_group_get_degree, 245 .group_get_degree = ec_GFp_simple_group_get_degree,
246 .group_order_bits = ec_group_simple_order_bits,
246 .group_check_discriminant = 247 .group_check_discriminant =
247 ec_GFp_simple_group_check_discriminant, 248 ec_GFp_simple_group_check_discriminant,
248 .point_init = ec_GFp_simple_point_init, 249 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c
index 57b003aefa..e13621c7b6 100644
--- a/src/lib/libcrypto/ec/ecp_nistp256.c
+++ b/src/lib/libcrypto/ec/ecp_nistp256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp256.c,v 1.25 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_nistp256.c,v 1.26 2021/09/08 17:29:21 tb Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1697,6 +1697,7 @@ EC_GFp_nistp256_method(void)
1697 .group_set_curve = ec_GFp_nistp256_group_set_curve, 1697 .group_set_curve = ec_GFp_nistp256_group_set_curve,
1698 .group_get_curve = ec_GFp_simple_group_get_curve, 1698 .group_get_curve = ec_GFp_simple_group_get_curve,
1699 .group_get_degree = ec_GFp_simple_group_get_degree, 1699 .group_get_degree = ec_GFp_simple_group_get_degree,
1700 .group_order_bits = ec_group_simple_order_bits,
1700 .group_check_discriminant = 1701 .group_check_discriminant =
1701 ec_GFp_simple_group_check_discriminant, 1702 ec_GFp_simple_group_check_discriminant,
1702 .point_init = ec_GFp_simple_point_init, 1703 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c
index db2060668c..994c1039d6 100644
--- a/src/lib/libcrypto/ec/ecp_nistp521.c
+++ b/src/lib/libcrypto/ec/ecp_nistp521.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp521.c,v 1.26 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_nistp521.c,v 1.27 2021/09/08 17:29:21 tb Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1587,6 +1587,7 @@ EC_GFp_nistp521_method(void)
1587 .group_set_curve = ec_GFp_nistp521_group_set_curve, 1587 .group_set_curve = ec_GFp_nistp521_group_set_curve,
1588 .group_get_curve = ec_GFp_simple_group_get_curve, 1588 .group_get_curve = ec_GFp_simple_group_get_curve,
1589 .group_get_degree = ec_GFp_simple_group_get_degree, 1589 .group_get_degree = ec_GFp_simple_group_get_degree,
1590 .group_order_bits = ec_group_simple_order_bits,
1590 .group_check_discriminant = 1591 .group_check_discriminant =
1591 ec_GFp_simple_group_check_discriminant, 1592 ec_GFp_simple_group_check_discriminant,
1592 .point_init = ec_GFp_simple_point_init, 1593 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_nistz256.c b/src/lib/libcrypto/ec/ecp_nistz256.c
index 619249964b..05a16b8c07 100644
--- a/src/lib/libcrypto/ec/ecp_nistz256.c
+++ b/src/lib/libcrypto/ec/ecp_nistz256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistz256.c,v 1.9 2021/04/20 17:28:18 tb Exp $ */ 1/* $OpenBSD: ecp_nistz256.c,v 1.10 2021/09/08 17:29:21 tb Exp $ */
2/* Copyright (c) 2014, Intel Corporation. 2/* Copyright (c) 2014, Intel Corporation.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 4 * Permission to use, copy, modify, and/or distribute this software for any
@@ -1152,6 +1152,7 @@ EC_GFp_nistz256_method(void)
1152 .group_set_curve = ec_GFp_mont_group_set_curve, 1152 .group_set_curve = ec_GFp_mont_group_set_curve,
1153 .group_get_curve = ec_GFp_simple_group_get_curve, 1153 .group_get_curve = ec_GFp_simple_group_get_curve,
1154 .group_get_degree = ec_GFp_simple_group_get_degree, 1154 .group_get_degree = ec_GFp_simple_group_get_degree,
1155 .group_order_bits = ec_group_simple_order_bits,
1155 .group_check_discriminant = 1156 .group_check_discriminant =
1156 ec_GFp_simple_group_check_discriminant, 1157 ec_GFp_simple_group_check_discriminant,
1157 .point_init = ec_GFp_simple_point_init, 1158 .point_init = ec_GFp_simple_point_init,
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index 96ab5bd44e..1d0b1d6106 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.32 2021/04/20 17:38:02 tb Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.33 2021/09/08 17:29:21 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.
@@ -80,6 +80,7 @@ EC_GFp_simple_method(void)
80 .group_set_curve = ec_GFp_simple_group_set_curve, 80 .group_set_curve = ec_GFp_simple_group_set_curve,
81 .group_get_curve = ec_GFp_simple_group_get_curve, 81 .group_get_curve = ec_GFp_simple_group_get_curve,
82 .group_get_degree = ec_GFp_simple_group_get_degree, 82 .group_get_degree = ec_GFp_simple_group_get_degree,
83 .group_order_bits = ec_group_simple_order_bits,
83 .group_check_discriminant = 84 .group_check_discriminant =
84 ec_GFp_simple_group_check_discriminant, 85 ec_GFp_simple_group_check_discriminant,
85 .point_init = ec_GFp_simple_point_init, 86 .point_init = ec_GFp_simple_point_init,