diff options
| author | tb <> | 2024-01-04 17:08:57 +0000 |
|---|---|---|
| committer | tb <> | 2024-01-04 17:08:57 +0000 |
| commit | f532675414edae4b4b8205239d63889a7b9b63eb (patch) | |
| tree | a0f102a32e600023cb2524ee331f4273178138b4 /src | |
| parent | 9f1cd2582409ac5778c5a0e28dfb77f18d122c98 (diff) | |
| download | openbsd-f532675414edae4b4b8205239d63889a7b9b63eb.tar.gz openbsd-f532675414edae4b4b8205239d63889a7b9b63eb.tar.bz2 openbsd-f532675414edae4b4b8205239d63889a7b9b63eb.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.c | 42 |
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 | ||
| 191 | static const EVP_PKEY_ASN1_METHOD * | ||
| 192 | pkey_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 | */ | ||
| 212 | const EVP_PKEY_ASN1_METHOD * | 191 | const EVP_PKEY_ASN1_METHOD * |
| 213 | EVP_PKEY_asn1_find(ENGINE **pe, int type) | 192 | EVP_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 | ||
| 231 | const EVP_PKEY_ASN1_METHOD * | 207 | const EVP_PKEY_ASN1_METHOD * |
