From 7f25767d815c78384174f883d4be409806f5f41d Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 16 Dec 2023 14:09:33 +0000 Subject: [PATCH] Move EVP_PBE_find() next to the tables There is no point in having EVP_PBE_CipherInit() between the table and the lookup functions (which it notably uses). No code change. --- lib/libcrypto/evp/evp_pbe.c | 92 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/libcrypto/evp/evp_pbe.c b/lib/libcrypto/evp/evp_pbe.c index 0fe82953e3f..94658f87974 100644 --- a/lib/libcrypto/evp/evp_pbe.c +++ b/lib/libcrypto/evp/evp_pbe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_pbe.c,v 1.32 2023/12/16 14:04:59 tb Exp $ */ +/* $OpenBSD: evp_pbe.c,v 1.33 2023/12/16 14:09:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -220,6 +220,51 @@ static const struct pbe_config pbe_prf[] = { #define N_PBE_PRF (sizeof(pbe_prf) / sizeof(pbe_prf[0])) +int +EVP_PBE_find(int type, int pbe_nid, int *out_cipher_nid, int *out_md_nid, + EVP_PBE_KEYGEN **out_keygen) +{ + const struct pbe_config *pbe = NULL; + size_t i; + + if (out_cipher_nid != NULL) + *out_cipher_nid = NID_undef; + if (out_md_nid != NULL) + *out_md_nid = NID_undef; + if (out_keygen != NULL) + *out_keygen = NULL; + + if (pbe_nid == NID_undef) + return 0; + + if (type == EVP_PBE_TYPE_OUTER) { + for (i = 0; i < N_PBE_OUTER; i++) { + if (pbe_nid == pbe_outer[i].pbe_nid) { + pbe = &pbe_outer[i]; + break; + } + } + } else if (type == EVP_PBE_TYPE_PRF) { + for (i = 0; i < N_PBE_PRF; i++) { + if (pbe_nid == pbe_prf[i].pbe_nid) { + pbe = &pbe_prf[i]; + break; + } + } + } + if (pbe == NULL) + return 0; + + if (out_cipher_nid != NULL) + *out_cipher_nid = pbe->cipher_nid; + if (out_md_nid != NULL) + *out_md_nid = pbe->md_nid; + if (out_keygen != NULL) + *out_keygen = pbe->keygen; + + return 1; +} + int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) @@ -273,51 +318,6 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, return 1; } -int -EVP_PBE_find(int type, int pbe_nid, int *out_cipher_nid, int *out_md_nid, - EVP_PBE_KEYGEN **out_keygen) -{ - const struct pbe_config *pbe = NULL; - size_t i; - - if (out_cipher_nid != NULL) - *out_cipher_nid = NID_undef; - if (out_md_nid != NULL) - *out_md_nid = NID_undef; - if (out_keygen != NULL) - *out_keygen = NULL; - - if (pbe_nid == NID_undef) - return 0; - - if (type == EVP_PBE_TYPE_OUTER) { - for (i = 0; i < N_PBE_OUTER; i++) { - if (pbe_nid == pbe_outer[i].pbe_nid) { - pbe = &pbe_outer[i]; - break; - } - } - } else if (type == EVP_PBE_TYPE_PRF) { - for (i = 0; i < N_PBE_PRF; i++) { - if (pbe_nid == pbe_prf[i].pbe_nid) { - pbe = &pbe_prf[i]; - break; - } - } - } - if (pbe == NULL) - return 0; - - if (out_cipher_nid != NULL) - *out_cipher_nid = pbe->cipher_nid; - if (out_md_nid != NULL) - *out_md_nid = pbe->md_nid; - if (out_keygen != NULL) - *out_keygen = pbe->keygen; - - return 1; -} - int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid, EVP_PBE_KEYGEN *keygen) -- 2.20.1