From 54199c8ed6cd915425e7a2eb9805a33c4a04bafd Mon Sep 17 00:00:00 2001 From: tb Date: Sun, 25 Jun 2023 18:45:56 +0000 Subject: [PATCH] Remove {ecdh,ecdsa}_check() and {ECDH,ECDSA}_DATA This is now unused code. Removing it will free us up to remove some other ugliness in the ec directory. ok jsing --- lib/libcrypto/ecdh/ech_lib.c | 97 +-------------------------------- lib/libcrypto/ecdh/ech_local.h | 14 +---- lib/libcrypto/ecdsa/ecs_lib.c | 96 +------------------------------- lib/libcrypto/ecdsa/ecs_local.h | 20 +------ 4 files changed, 4 insertions(+), 223 deletions(-) diff --git a/lib/libcrypto/ecdh/ech_lib.c b/lib/libcrypto/ecdh/ech_lib.c index 6e12126034e..f062ec3fdc8 100644 --- a/lib/libcrypto/ecdh/ech_lib.c +++ b/lib/libcrypto/ecdh/ech_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ech_lib.c,v 1.18 2023/06/25 18:27:38 tb Exp $ */ +/* $OpenBSD: ech_lib.c,v 1.19 2023/06/25 18:45:56 tb Exp $ */ /* ==================================================================== * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. * @@ -81,10 +81,6 @@ static const ECDH_METHOD *default_ECDH_method = NULL; -static void *ecdh_data_new(void); -static void *ecdh_data_dup(void *); -static void ecdh_data_free(void *); - void ECDH_set_default_method(const ECDH_METHOD *meth) { @@ -106,97 +102,6 @@ ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) return 0; } -static ECDH_DATA * -ECDH_DATA_new_method(ENGINE *engine) -{ - ECDH_DATA *ret; - - ret = malloc(sizeof(ECDH_DATA)); - if (ret == NULL) { - ECDHerror(ERR_R_MALLOC_FAILURE); - return (NULL); - } - - ret->init = NULL; - - ret->meth = ECDH_get_default_method(); - ret->engine = engine; -#ifndef OPENSSL_NO_ENGINE - if (!ret->engine) - ret->engine = ENGINE_get_default_ECDH(); - if (ret->engine) { - ret->meth = ENGINE_get_ECDH(ret->engine); - if (ret->meth == NULL) { - ECDHerror(ERR_R_ENGINE_LIB); - ENGINE_finish(ret->engine); - free(ret); - return NULL; - } - } -#endif - - ret->flags = ret->meth->flags; - CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); - return (ret); -} - -static void * -ecdh_data_new(void) -{ - return (void *)ECDH_DATA_new_method(NULL); -} - -static void * -ecdh_data_dup(void *data) -{ - ECDH_DATA *r = (ECDH_DATA *)data; - - /* XXX: dummy operation */ - if (r == NULL) - return NULL; - - return (void *)ecdh_data_new(); -} - -void -ecdh_data_free(void *data) -{ - ECDH_DATA *r = (ECDH_DATA *)data; - -#ifndef OPENSSL_NO_ENGINE - ENGINE_finish(r->engine); -#endif - - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data); - - freezero(r, sizeof(ECDH_DATA)); -} - -ECDH_DATA * -ecdh_check(EC_KEY *key) -{ - ECDH_DATA *ecdh_data; - - void *data = EC_KEY_get_key_method_data(key, ecdh_data_dup, - ecdh_data_free, ecdh_data_free); - if (data == NULL) { - ecdh_data = (ECDH_DATA *)ecdh_data_new(); - if (ecdh_data == NULL) - return NULL; - data = EC_KEY_insert_key_method_data(key, (void *)ecdh_data, - ecdh_data_dup, ecdh_data_free, ecdh_data_free); - if (data != NULL) { - /* Another thread raced us to install the key_method - * data and won. */ - ecdh_data_free(ecdh_data); - ecdh_data = (ECDH_DATA *)data; - } - } else - ecdh_data = (ECDH_DATA *)data; - - return ecdh_data; -} - int ECDH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) diff --git a/lib/libcrypto/ecdh/ech_local.h b/lib/libcrypto/ecdh/ech_local.h index c8cb5182491..fefa817b1cb 100644 --- a/lib/libcrypto/ecdh/ech_local.h +++ b/lib/libcrypto/ecdh/ech_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ech_local.h,v 1.3 2023/06/25 08:12:23 tb Exp $ */ +/* $OpenBSD: ech_local.h,v 1.4 2023/06/25 18:45:56 tb Exp $ */ /* ==================================================================== * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. * @@ -68,18 +68,6 @@ struct ecdh_method { char *app_data; }; -typedef struct ecdh_data_st { - /* EC_KEY_METH_DATA part */ - int (*init)(EC_KEY *); - /* method specific part */ - ENGINE *engine; - int flags; - const ECDH_METHOD *meth; - CRYPTO_EX_DATA ex_data; -} ECDH_DATA; - -ECDH_DATA *ecdh_check(EC_KEY *); - /* * ECDH Key Derivation Function as defined in ANSI X9.63. */ diff --git a/lib/libcrypto/ecdsa/ecs_lib.c b/lib/libcrypto/ecdsa/ecs_lib.c index 9ba5db2fca8..11e707dd55b 100644 --- a/lib/libcrypto/ecdsa/ecs_lib.c +++ b/lib/libcrypto/ecdsa/ecs_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_lib.c,v 1.19 2023/06/25 18:27:38 tb Exp $ */ +/* $OpenBSD: ecs_lib.c,v 1.20 2023/06/25 18:45:56 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. * @@ -68,10 +68,6 @@ static const ECDSA_METHOD *default_ECDSA_method = NULL; -static void *ecdsa_data_new(void); -static void *ecdsa_data_dup(void *); -static void ecdsa_data_free(void *); - void ECDSA_set_default_method(const ECDSA_METHOD *meth) { @@ -93,96 +89,6 @@ ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth) return 0; } -static ECDSA_DATA * -ECDSA_DATA_new_method(ENGINE *engine) -{ - ECDSA_DATA *ret; - - ret = malloc(sizeof(ECDSA_DATA)); - if (ret == NULL) { - ECDSAerror(ERR_R_MALLOC_FAILURE); - return (NULL); - } - - ret->init = NULL; - - ret->meth = ECDSA_get_default_method(); - ret->engine = engine; -#ifndef OPENSSL_NO_ENGINE - if (!ret->engine) - ret->engine = ENGINE_get_default_ECDSA(); - if (ret->engine) { - ret->meth = ENGINE_get_ECDSA(ret->engine); - if (ret->meth == NULL) { - ECDSAerror(ERR_R_ENGINE_LIB); - ENGINE_finish(ret->engine); - free(ret); - return NULL; - } - } -#endif - - ret->flags = ret->meth->flags; - CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data); - return (ret); -} - -static void * -ecdsa_data_new(void) -{ - return (void *)ECDSA_DATA_new_method(NULL); -} - -static void * -ecdsa_data_dup(void *data) -{ - ECDSA_DATA *r = (ECDSA_DATA *)data; - - /* XXX: dummy operation */ - if (r == NULL) - return NULL; - - return ecdsa_data_new(); -} - -static void -ecdsa_data_free(void *data) -{ - ECDSA_DATA *r = (ECDSA_DATA *)data; - -#ifndef OPENSSL_NO_ENGINE - ENGINE_finish(r->engine); -#endif - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data); - - freezero(r, sizeof(ECDSA_DATA)); -} - -ECDSA_DATA * -ecdsa_check(EC_KEY *key) -{ - ECDSA_DATA *ecdsa_data; - - void *data = EC_KEY_get_key_method_data(key, ecdsa_data_dup, - ecdsa_data_free, ecdsa_data_free); - if (data == NULL) { - ecdsa_data = (ECDSA_DATA *)ecdsa_data_new(); - if (ecdsa_data == NULL) - return NULL; - data = EC_KEY_insert_key_method_data(key, (void *)ecdsa_data, - ecdsa_data_dup, ecdsa_data_free, ecdsa_data_free); - if (data != NULL) { - /* Another thread raced us to install the key_method - * data and won. */ - ecdsa_data_free(ecdsa_data); - ecdsa_data = (ECDSA_DATA *)data; - } - } else - ecdsa_data = (ECDSA_DATA *)data; - - return ecdsa_data; -} - int ECDSA_size(const EC_KEY *r) { diff --git a/lib/libcrypto/ecdsa/ecs_local.h b/lib/libcrypto/ecdsa/ecs_local.h index 5cdf2645571..20ad0c246e6 100644 --- a/lib/libcrypto/ecdsa/ecs_local.h +++ b/lib/libcrypto/ecdsa/ecs_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_local.h,v 1.2 2022/11/26 17:23:17 tb Exp $ */ +/* $OpenBSD: ecs_local.h,v 1.3 2023/06/25 18:45:56 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project */ @@ -63,29 +63,11 @@ __BEGIN_HIDDEN_DECLS -typedef struct ecdsa_data_st { - /* EC_KEY_METH_DATA part */ - int (*init)(EC_KEY *); - /* method (ECDSA) specific part */ - ENGINE *engine; - int flags; - const ECDSA_METHOD *meth; - CRYPTO_EX_DATA ex_data; -} ECDSA_DATA; - struct ECDSA_SIG_st { BIGNUM *r; BIGNUM *s; }; -/** ecdsa_check - * checks whether ECKEY->meth_data is a pointer to a ECDSA_DATA structure - * and if not it removes the old meth_data and creates a ECDSA_DATA structure. - * \param eckey pointer to a EC_KEY object - * \return pointer to a ECDSA_DATA structure - */ -ECDSA_DATA *ecdsa_check(EC_KEY *eckey); - int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, -- 2.20.1