summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-01-04 17:08:57 +0000
committertb <>2024-01-04 17:08:57 +0000
commit00a41f70d8c4e3330ec5ea9a908795fa95756a7f (patch)
treea0f102a32e600023cb2524ee331f4273178138b4 /src
parent28fd80a9189b82d0223c35153f8ed6f9cfb59161 (diff)
downloadopenbsd-00a41f70d8c4e3330ec5ea9a908795fa95756a7f.tar.gz
openbsd-00a41f70d8c4e3330ec5ea9a908795fa95756a7f.tar.bz2
openbsd-00a41f70d8c4e3330ec5ea9a908795fa95756a7f.zip
Simplify EVP_PKEY_asn1_find()
EVP_PKEY_asn1_find() finds the EVP_PKEY_ASN1_METHOD underlying the method or alias with nid (or, rather, pkey_id) passed in. Now that we have the base method stored in a pointer, we can return that method after a simple lookup of said nid (or, rather, pkey_id). ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index b43a0fcd5d..d9cb66336c 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_lib.c,v 1.54 2024/01/04 17:01:26 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.55 2024/01/04 17:08:57 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -188,44 +188,20 @@ EVP_PKEY_asn1_get0(int idx)
188 return asn1_methods[idx]; 188 return asn1_methods[idx];
189} 189}
190 190
191static const EVP_PKEY_ASN1_METHOD *
192pkey_asn1_find(int pkey_id)
193{
194 const EVP_PKEY_ASN1_METHOD *ameth;
195 int i;
196
197 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) {
198 ameth = EVP_PKEY_asn1_get0(i);
199 if (ameth->pkey_id == pkey_id)
200 return ameth;
201 }
202
203 return NULL;
204}
205
206/*
207 * XXX - fix this. In what looks like an infinite loop, this API only makes two
208 * calls to pkey_asn1_find(): If the type resolves to an aliased ASN.1 method,
209 * the second call will find the method it aliases. Codify this in regress and
210 * make this explicit in code.
211 */
212const EVP_PKEY_ASN1_METHOD * 191const EVP_PKEY_ASN1_METHOD *
213EVP_PKEY_asn1_find(ENGINE **pe, int type) 192EVP_PKEY_asn1_find(ENGINE **engine, int pkey_id)
214{ 193{
215 const EVP_PKEY_ASN1_METHOD *mp; 194 size_t i;
216 195
217 if (pe != NULL) 196 if (engine != NULL)
218 *pe = NULL; 197 *engine = NULL;
219 198
220 for (;;) { 199 for (i = 0; i < N_ASN1_METHODS; i++) {
221 if ((mp = pkey_asn1_find(type)) == NULL) 200 if (asn1_methods[i]->pkey_id == pkey_id)
222 break; 201 return asn1_methods[i]->base_method;
223 if ((mp->pkey_flags & ASN1_PKEY_ALIAS) == 0)
224 break;
225 type = mp->base_method->pkey_id;
226 } 202 }
227 203
228 return mp; 204 return NULL;
229} 205}
230 206
231const EVP_PKEY_ASN1_METHOD * 207const EVP_PKEY_ASN1_METHOD *