From c827a8a4ea864ebc2b03b1710148fb5c896dfe66 Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 19 Oct 2024 08:26:03 +0000 Subject: [PATCH] Move EC_GROUP_check() to ec_lib.c EC_GROUP_check() is quite simple. It doesn't need to use its own file. --- lib/libcrypto/Makefile | 3 +- lib/libcrypto/ec/ec_check.c | 112 ------------------------------------ lib/libcrypto/ec/ec_lib.c | 57 +++++++++++++++++- 3 files changed, 57 insertions(+), 115 deletions(-) delete mode 100644 lib/libcrypto/ec/ec_check.c diff --git a/lib/libcrypto/Makefile b/lib/libcrypto/Makefile index d3be27ade1a..6a1d125950e 100644 --- a/lib/libcrypto/Makefile +++ b/lib/libcrypto/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.213 2024/10/18 11:12:10 tb Exp $ +# $OpenBSD: Makefile,v 1.214 2024/10/19 08:26:03 tb Exp $ LIB= crypto LIBREBUILD=y @@ -281,7 +281,6 @@ SRCS+= dsa_prn.c # ec/ SRCS+= ec_ameth.c SRCS+= ec_asn1.c -SRCS+= ec_check.c SRCS+= ec_curve.c SRCS+= ec_err.c SRCS+= ec_key.c diff --git a/lib/libcrypto/ec/ec_check.c b/lib/libcrypto/ec/ec_check.c deleted file mode 100644 index 0f98ef613c9..00000000000 --- a/lib/libcrypto/ec/ec_check.c +++ /dev/null @@ -1,112 +0,0 @@ -/* $OpenBSD: ec_check.c,v 1.15 2023/07/07 13:54:45 beck Exp $ */ -/* ==================================================================== - * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@openssl.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -#include "ec_local.h" -#include - -int -EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx_in) -{ - BN_CTX *ctx; - EC_POINT *point = NULL; - const BIGNUM *order; - int ret = 0; - - if ((ctx = ctx_in) == NULL) - ctx = BN_CTX_new(); - if (ctx == NULL) - goto err; - - /* check the discriminant */ - if (!EC_GROUP_check_discriminant(group, ctx)) { - ECerror(EC_R_DISCRIMINANT_IS_ZERO); - goto err; - } - /* check the generator */ - if (group->generator == NULL) { - ECerror(EC_R_UNDEFINED_GENERATOR); - goto err; - } - if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) { - ECerror(EC_R_POINT_IS_NOT_ON_CURVE); - goto err; - } - /* check the order of the generator */ - if ((point = EC_POINT_new(group)) == NULL) - goto err; - if ((order = EC_GROUP_get0_order(group)) == NULL) - goto err; - if (BN_is_zero(order)) { - ECerror(EC_R_UNDEFINED_ORDER); - goto err; - } - if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) - goto err; - if (EC_POINT_is_at_infinity(group, point) <= 0) { - ECerror(EC_R_INVALID_GROUP_ORDER); - goto err; - } - - ret = 1; - - err: - if (ctx != ctx_in) - BN_CTX_free(ctx); - - EC_POINT_free(point); - - return ret; -} -LCRYPTO_ALIAS(EC_GROUP_check); diff --git a/lib/libcrypto/ec/ec_lib.c b/lib/libcrypto/ec/ec_lib.c index 0e5897da9da..e17c4396f79 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.70 2024/10/18 10:57:26 tb Exp $ */ +/* $OpenBSD: ec_lib.c,v 1.71 2024/10/19 08:26:03 tb Exp $ */ /* * Originally written by Bodo Moeller for the OpenSSL project. */ @@ -601,6 +601,61 @@ EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx_in) } LCRYPTO_ALIAS(EC_GROUP_check_discriminant); +int +EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx_in) +{ + BN_CTX *ctx; + EC_POINT *point = NULL; + const BIGNUM *order; + int ret = 0; + + if ((ctx = ctx_in) == NULL) + ctx = BN_CTX_new(); + if (ctx == NULL) + goto err; + + /* check the discriminant */ + if (!EC_GROUP_check_discriminant(group, ctx)) { + ECerror(EC_R_DISCRIMINANT_IS_ZERO); + goto err; + } + /* check the generator */ + if (group->generator == NULL) { + ECerror(EC_R_UNDEFINED_GENERATOR); + goto err; + } + if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) { + ECerror(EC_R_POINT_IS_NOT_ON_CURVE); + goto err; + } + /* check the order of the generator */ + if ((point = EC_POINT_new(group)) == NULL) + goto err; + if ((order = EC_GROUP_get0_order(group)) == NULL) + goto err; + if (BN_is_zero(order)) { + ECerror(EC_R_UNDEFINED_ORDER); + goto err; + } + if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) + goto err; + if (EC_POINT_is_at_infinity(group, point) <= 0) { + ECerror(EC_R_INVALID_GROUP_ORDER); + goto err; + } + + ret = 1; + + err: + if (ctx != ctx_in) + BN_CTX_free(ctx); + + EC_POINT_free(point); + + return ret; +} +LCRYPTO_ALIAS(EC_GROUP_check); + int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) { -- 2.20.1