From 474ea8ba179719239431070606a28b55464f844c Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 12 Apr 2024 09:41:39 +0000 Subject: [PATCH] Garbage collect various *_init() pmeths It's unclear whether the functions these support were ever really used for anything else than kicking off an overenginerred state machine. ok jsing --- lib/libcrypto/evp/evp_local.h | 7 +----- lib/libcrypto/evp/pmeth_fn.c | 42 ++++++++++++----------------------- lib/libcrypto/evp/pmeth_gn.c | 28 ++++++++--------------- 3 files changed, 24 insertions(+), 53 deletions(-) diff --git a/lib/libcrypto/evp/evp_local.h b/lib/libcrypto/evp/evp_local.h index b1c0c9b14ee..9631992a28f 100644 --- a/lib/libcrypto/evp/evp_local.h +++ b/lib/libcrypto/evp/evp_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_local.h,v 1.21 2024/03/26 01:41:06 tb Exp $ */ +/* $OpenBSD: evp_local.h,v 1.22 2024/04/12 09:41:39 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -283,10 +283,8 @@ struct evp_pkey_method_st { int (*copy)(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src); void (*cleanup)(EVP_PKEY_CTX *ctx); - int (*paramgen_init)(EVP_PKEY_CTX *ctx); int (*paramgen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); - int (*keygen_init)(EVP_PKEY_CTX *ctx); int (*keygen)(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); int (*sign_init)(EVP_PKEY_CTX *ctx); @@ -298,7 +296,6 @@ struct evp_pkey_method_st { const unsigned char *sig, size_t siglen, const unsigned char *tbs, size_t tbslen); - int (*verify_recover_init)(EVP_PKEY_CTX *ctx); int (*verify_recover)(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, const unsigned char *sig, size_t siglen); @@ -307,11 +304,9 @@ struct evp_pkey_method_st { int (*signctx)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, EVP_MD_CTX *mctx); - int (*encrypt_init)(EVP_PKEY_CTX *ctx); int (*encrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen); - int (*decrypt_init)(EVP_PKEY_CTX *ctx); int (*decrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen, const unsigned char *in, size_t inlen); diff --git a/lib/libcrypto/evp/pmeth_fn.c b/lib/libcrypto/evp/pmeth_fn.c index f8ed555fda0..308c434f0d8 100644 --- a/lib/libcrypto/evp/pmeth_fn.c +++ b/lib/libcrypto/evp/pmeth_fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmeth_fn.c,v 1.10 2024/04/09 13:52:41 beck Exp $ */ +/* $OpenBSD: pmeth_fn.c,v 1.11 2024/04/12 09:41:39 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -155,19 +155,15 @@ LCRYPTO_ALIAS(EVP_PKEY_verify); int EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx) { - int ret; - - if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { + if (ctx == NULL || ctx->pmeth == NULL || + ctx->pmeth->verify_recover == NULL) { EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } + ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; - if (!ctx->pmeth->verify_recover_init) - return 1; - ret = ctx->pmeth->verify_recover_init(ctx); - if (ret <= 0) - ctx->operation = EVP_PKEY_OP_UNDEFINED; - return ret; + + return 1; } LCRYPTO_ALIAS(EVP_PKEY_verify_recover_init); @@ -191,19 +187,14 @@ LCRYPTO_ALIAS(EVP_PKEY_verify_recover); int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx) { - int ret; - - if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { + if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->encrypt == NULL) { EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } + ctx->operation = EVP_PKEY_OP_ENCRYPT; - if (!ctx->pmeth->encrypt_init) - return 1; - ret = ctx->pmeth->encrypt_init(ctx); - if (ret <= 0) - ctx->operation = EVP_PKEY_OP_UNDEFINED; - return ret; + + return 1; } LCRYPTO_ALIAS(EVP_PKEY_encrypt_init); @@ -227,19 +218,14 @@ LCRYPTO_ALIAS(EVP_PKEY_encrypt); int EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx) { - int ret; - - if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { + if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->decrypt == NULL) { EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } + ctx->operation = EVP_PKEY_OP_DECRYPT; - if (!ctx->pmeth->decrypt_init) - return 1; - ret = ctx->pmeth->decrypt_init(ctx); - if (ret <= 0) - ctx->operation = EVP_PKEY_OP_UNDEFINED; - return ret; + + return 1; } LCRYPTO_ALIAS(EVP_PKEY_decrypt_init); diff --git a/lib/libcrypto/evp/pmeth_gn.c b/lib/libcrypto/evp/pmeth_gn.c index b86ecc68113..b8b51ced3d8 100644 --- a/lib/libcrypto/evp/pmeth_gn.c +++ b/lib/libcrypto/evp/pmeth_gn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmeth_gn.c,v 1.17 2024/04/12 02:56:15 tb Exp $ */ +/* $OpenBSD: pmeth_gn.c,v 1.18 2024/04/12 09:41:39 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -71,19 +71,14 @@ int EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx) { - int ret; - - if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) { + if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->paramgen == NULL) { EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } + ctx->operation = EVP_PKEY_OP_PARAMGEN; - if (!ctx->pmeth->paramgen_init) - return 1; - ret = ctx->pmeth->paramgen_init(ctx); - if (ret <= 0) - ctx->operation = EVP_PKEY_OP_UNDEFINED; - return ret; + + return 1; } LCRYPTO_ALIAS(EVP_PKEY_paramgen_init); @@ -120,19 +115,14 @@ LCRYPTO_ALIAS(EVP_PKEY_paramgen); int EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx) { - int ret; - - if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) { + if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->keygen == NULL) { EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return -2; } + ctx->operation = EVP_PKEY_OP_KEYGEN; - if (!ctx->pmeth->keygen_init) - return 1; - ret = ctx->pmeth->keygen_init(ctx); - if (ret <= 0) - ctx->operation = EVP_PKEY_OP_UNDEFINED; - return ret; + + return 1; } LCRYPTO_ALIAS(EVP_PKEY_keygen_init); -- 2.20.1