From: tb Date: Wed, 8 Sep 2021 17:29:21 +0000 (+0000) Subject: Prepare to provide EC_GROUP_order_bits() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=70b8897aa6925f865a5c9a54bfdfacc9aa8dd391;p=openbsd Prepare to provide EC_GROUP_order_bits() ok jsing --- diff --git a/lib/libcrypto/ec/ec.h b/lib/libcrypto/ec/ec.h index 61b70897f9c..b1cba7d6c8b 100644 --- a/lib/libcrypto/ec/ec.h +++ b/lib/libcrypto/ec/ec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ec.h,v 1.24 2021/05/10 16:58:19 tb Exp $ */ +/* $OpenBSD: ec.h,v 1.25 2021/09/08 17:29:21 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -250,6 +250,10 @@ const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); */ int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx); +#if defined(LIBRESSL_INTERNAL) +int EC_GROUP_order_bits(const EC_GROUP *group); +#endif + /** Gets the cofactor of a EC_GROUP * \param group EC_GROUP object * \param cofactor BIGNUM to which the cofactor is copied diff --git a/lib/libcrypto/ec/ec2_smpl.c b/lib/libcrypto/ec/ec2_smpl.c index f99615a0d54..9f3b380bfeb 100644 --- a/lib/libcrypto/ec/ec2_smpl.c +++ b/lib/libcrypto/ec/ec2_smpl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec2_smpl.c,v 1.22 2021/04/20 17:16:37 tb Exp $ */ +/* $OpenBSD: ec2_smpl.c,v 1.23 2021/09/08 17:29:21 tb Exp $ */ /* ==================================================================== * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. * @@ -88,17 +88,18 @@ EC_GF2m_simple_method(void) .group_set_curve = ec_GF2m_simple_group_set_curve, .group_get_curve = ec_GF2m_simple_group_get_curve, .group_get_degree = ec_GF2m_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = - ec_GF2m_simple_group_check_discriminant, + ec_GF2m_simple_group_check_discriminant, .point_init = ec_GF2m_simple_point_init, .point_finish = ec_GF2m_simple_point_finish, .point_clear_finish = ec_GF2m_simple_point_clear_finish, .point_copy = ec_GF2m_simple_point_copy, .point_set_to_infinity = ec_GF2m_simple_point_set_to_infinity, .point_set_affine_coordinates = - ec_GF2m_simple_point_set_affine_coordinates, + ec_GF2m_simple_point_set_affine_coordinates, .point_get_affine_coordinates = - ec_GF2m_simple_point_get_affine_coordinates, + ec_GF2m_simple_point_get_affine_coordinates, .add = ec_GF2m_simple_add, .dbl = ec_GF2m_simple_dbl, .invert = ec_GF2m_simple_invert, diff --git a/lib/libcrypto/ec/ec_lcl.h b/lib/libcrypto/ec/ec_lcl.h index a0343aa1d2e..ced04c7e314 100644 --- a/lib/libcrypto/ec/ec_lcl.h +++ b/lib/libcrypto/ec/ec_lcl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lcl.h,v 1.17 2021/04/20 17:32:57 tb Exp $ */ +/* $OpenBSD: ec_lcl.h,v 1.18 2021/09/08 17:29:21 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -111,7 +111,8 @@ struct ec_method_st { /* used by EC_GROUP_get_degree: */ int (*group_get_degree)(const EC_GROUP *); - + /* used by EC_GROUP_order_bits: */ + int (*group_order_bits)(const EC_GROUP *); /* used by EC_GROUP_check: */ int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); @@ -282,7 +283,7 @@ void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **, void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **); void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **); - +int ec_group_simple_order_bits(const EC_GROUP *group); struct ec_point_st { const EC_METHOD *meth; @@ -297,8 +298,6 @@ struct ec_point_st { int Z_is_one; /* enable optimized point arithmetics for special case */ } /* EC_POINT */; - - /* method functions in ec_mult.c * (ec_lib.c uses these as defaults if group->method->mul is 0) */ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, diff --git a/lib/libcrypto/ec/ec_lib.c b/lib/libcrypto/ec/ec_lib.c index e763e6b70c9..994fd2d4c1a 100644 --- a/lib/libcrypto/ec/ec_lib.c +++ b/lib/libcrypto/ec/ec_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_lib.c,v 1.39 2021/04/20 17:29:21 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.40 2021/09/08 17:29:21 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -401,6 +401,11 @@ EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx) return !BN_is_zero(order); } +int +EC_GROUP_order_bits(const EC_GROUP *group) +{ + return group->meth->group_order_bits(group); +} int EC_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) * been performed */ } +int +ec_group_simple_order_bits(const EC_GROUP *group) +{ + /* XXX change group->order to a pointer? */ +#if 0 + if (group->order == NULL) + return 0; +#endif + return BN_num_bits(&group->order); +} + EC_KEY * ECParameters_dup(EC_KEY *key) { diff --git a/lib/libcrypto/ec/ecp_mont.c b/lib/libcrypto/ec/ecp_mont.c index f371e3ec8f8..0da3083d8e4 100644 --- a/lib/libcrypto/ec/ecp_mont.c +++ b/lib/libcrypto/ec/ecp_mont.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_mont.c,v 1.19 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_mont.c,v 1.20 2021/09/08 17:29:21 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -79,6 +79,7 @@ EC_GFp_mont_method(void) .group_set_curve = ec_GFp_mont_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_nist.c b/lib/libcrypto/ec/ecp_nist.c index 14ebe7d126e..f7dae16e47e 100644 --- a/lib/libcrypto/ec/ecp_nist.c +++ b/lib/libcrypto/ec/ecp_nist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_nist.c,v 1.17 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_nist.c,v 1.18 2021/09/08 17:29:21 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -80,6 +80,7 @@ EC_GFp_nist_method(void) .group_set_curve = ec_GFp_nist_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_nistp224.c b/lib/libcrypto/ec/ecp_nistp224.c index 4ed45df8962..9ef9dc3585c 100644 --- a/lib/libcrypto/ec/ecp_nistp224.c +++ b/lib/libcrypto/ec/ecp_nistp224.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_nistp224.c,v 1.26 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_nistp224.c,v 1.27 2021/09/08 17:29:21 tb Exp $ */ /* * Written by Emilia Kasper (Google) for the OpenSSL project. */ @@ -243,6 +243,7 @@ EC_GFp_nistp224_method(void) .group_set_curve = ec_GFp_nistp224_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_nistp256.c b/lib/libcrypto/ec/ecp_nistp256.c index 57b003aefa7..e13621c7b60 100644 --- a/lib/libcrypto/ec/ecp_nistp256.c +++ b/lib/libcrypto/ec/ecp_nistp256.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_nistp256.c,v 1.25 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_nistp256.c,v 1.26 2021/09/08 17:29:21 tb Exp $ */ /* * Written by Adam Langley (Google) for the OpenSSL project */ @@ -1697,6 +1697,7 @@ EC_GFp_nistp256_method(void) .group_set_curve = ec_GFp_nistp256_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_nistp521.c b/lib/libcrypto/ec/ecp_nistp521.c index db2060668c2..994c1039d64 100644 --- a/lib/libcrypto/ec/ecp_nistp521.c +++ b/lib/libcrypto/ec/ecp_nistp521.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_nistp521.c,v 1.26 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_nistp521.c,v 1.27 2021/09/08 17:29:21 tb Exp $ */ /* * Written by Adam Langley (Google) for the OpenSSL project */ @@ -1587,6 +1587,7 @@ EC_GFp_nistp521_method(void) .group_set_curve = ec_GFp_nistp521_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_nistz256.c b/lib/libcrypto/ec/ecp_nistz256.c index 619249964be..05a16b8c074 100644 --- a/lib/libcrypto/ec/ecp_nistz256.c +++ b/lib/libcrypto/ec/ecp_nistz256.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_nistz256.c,v 1.9 2021/04/20 17:28:18 tb Exp $ */ +/* $OpenBSD: ecp_nistz256.c,v 1.10 2021/09/08 17:29:21 tb Exp $ */ /* Copyright (c) 2014, Intel Corporation. * * Permission to use, copy, modify, and/or distribute this software for any @@ -1152,6 +1152,7 @@ EC_GFp_nistz256_method(void) .group_set_curve = ec_GFp_mont_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init, diff --git a/lib/libcrypto/ec/ecp_smpl.c b/lib/libcrypto/ec/ecp_smpl.c index 96ab5bd44eb..1d0b1d6106b 100644 --- a/lib/libcrypto/ec/ecp_smpl.c +++ b/lib/libcrypto/ec/ecp_smpl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_smpl.c,v 1.32 2021/04/20 17:38:02 tb Exp $ */ +/* $OpenBSD: ecp_smpl.c,v 1.33 2021/09/08 17:29:21 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -80,6 +80,7 @@ EC_GFp_simple_method(void) .group_set_curve = ec_GFp_simple_group_set_curve, .group_get_curve = ec_GFp_simple_group_get_curve, .group_get_degree = ec_GFp_simple_group_get_degree, + .group_order_bits = ec_group_simple_order_bits, .group_check_discriminant = ec_GFp_simple_group_check_discriminant, .point_init = ec_GFp_simple_point_init,