From 9a2a8e9b90c2d1ffca1b8f1c94f304e57db01f2c Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 20 Dec 2023 10:14:14 +0000 Subject: [PATCH] Remove preprocessor mess in EVP_PKEY_{de,en}crypt_old() This was done the worst possible way. It would be much simpler to invert the logic and use a single #ifdef. jsing prefers keeping the current logic and suggested we ditch the preprocessor mess altogether. ok jsing, claudio agreed with the initial diff --- lib/libcrypto/evp/p_dec.c | 23 +++-------------------- lib/libcrypto/evp/p_enc.c | 24 +++++------------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/lib/libcrypto/evp/p_dec.c b/lib/libcrypto/evp/p_dec.c index d55b48b771c..2c63fe054e7 100644 --- a/lib/libcrypto/evp/p_dec.c +++ b/lib/libcrypto/evp/p_dec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: p_dec.c,v 1.15 2023/07/07 19:37:54 beck Exp $ */ +/* $OpenBSD: p_dec.c,v 1.16 2023/12/20 10:14:14 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,18 +56,10 @@ * [including the GNU Public Licence.] */ -#include - -#include - #include #include -#include -#include -#ifndef OPENSSL_NO_RSA #include -#endif #include "evp_local.h" @@ -75,20 +67,11 @@ int EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl, EVP_PKEY *priv) { - int ret = -1; - -#ifndef OPENSSL_NO_RSA if (priv->type != EVP_PKEY_RSA) { -#endif EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA); -#ifndef OPENSSL_NO_RSA - goto err; + return -1; } - ret = RSA_private_decrypt(ekl, ek, key, priv->pkey.rsa, + return RSA_private_decrypt(ekl, ek, key, priv->pkey.rsa, RSA_PKCS1_PADDING); - -err: -#endif - return (ret); } diff --git a/lib/libcrypto/evp/p_enc.c b/lib/libcrypto/evp/p_enc.c index 1abaf0b2685..b6346260e57 100644 --- a/lib/libcrypto/evp/p_enc.c +++ b/lib/libcrypto/evp/p_enc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: p_enc.c,v 1.15 2023/07/07 19:37:54 beck Exp $ */ +/* $OpenBSD: p_enc.c,v 1.16 2023/12/20 10:14:14 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,18 +56,10 @@ * [including the GNU Public Licence.] */ -#include - -#include - #include #include -#include -#include -#ifndef OPENSSL_NO_RSA #include -#endif #include "evp_local.h" @@ -75,17 +67,11 @@ int EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key, int key_len, EVP_PKEY *pubk) { - int ret = 0; - -#ifndef OPENSSL_NO_RSA if (pubk->type != EVP_PKEY_RSA) { -#endif EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA); -#ifndef OPENSSL_NO_RSA - goto err; + return 0; } - ret = RSA_public_encrypt(key_len, key, ek, pubk->pkey.rsa, RSA_PKCS1_PADDING); -err: -#endif - return (ret); + + return RSA_public_encrypt(key_len, key, ek, pubk->pkey.rsa, + RSA_PKCS1_PADDING); } -- 2.20.1