diff options
author | tb <> | 2023-12-15 08:16:54 +0000 |
---|---|---|
committer | tb <> | 2023-12-15 08:16:54 +0000 |
commit | c40d126d3db6ce3ded4af595d4f8cb09c69354f8 (patch) | |
tree | 4a3cbab2ce008847420e33da55a4277676be0945 /src | |
parent | 884ca327ec84fbad9a6f32474fd2089181a29138 (diff) | |
download | openbsd-c40d126d3db6ce3ded4af595d4f8cb09c69354f8.tar.gz openbsd-c40d126d3db6ce3ded4af595d4f8cb09c69354f8.tar.bz2 openbsd-c40d126d3db6ce3ded4af595d4f8cb09c69354f8.zip |
Neuter EVP_PKEY_asn1_add{0,_alias}()
Nothing uses these, so they will be removed in the next bump. For now
make them always fail and remove the unprotected global state backing
them. This makes EVP_PKEY_asn1_get{0,_count}() completely trivial and
will allow some further cleanup in later steps.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/ameth_lib.c | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c index aa4bb87667..9b4796a161 100644 --- a/src/lib/libcrypto/asn1/ameth_lib.c +++ b/src/lib/libcrypto/asn1/ameth_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ameth_lib.c,v 1.34 2023/11/29 21:35:57 tb Exp $ */ | 1 | /* $OpenBSD: ameth_lib.c,v 1.35 2023/12/15 08:16:54 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -62,6 +62,7 @@ | |||
62 | #include <openssl/opensslconf.h> | 62 | #include <openssl/opensslconf.h> |
63 | 63 | ||
64 | #include <openssl/asn1t.h> | 64 | #include <openssl/asn1t.h> |
65 | #include <openssl/err.h> | ||
65 | #include <openssl/x509.h> | 66 | #include <openssl/x509.h> |
66 | 67 | ||
67 | #include "asn1_local.h" | 68 | #include "asn1_local.h" |
@@ -100,36 +101,21 @@ static const EVP_PKEY_ASN1_METHOD *asn1_methods[] = { | |||
100 | &x25519_asn1_meth, | 101 | &x25519_asn1_meth, |
101 | }; | 102 | }; |
102 | 103 | ||
103 | static const size_t asn1_methods_count = | 104 | #define N_ASN1_METHODS (sizeof(asn1_methods) / sizeof(asn1_methods[0])) |
104 | sizeof(asn1_methods) / sizeof(asn1_methods[0]); | ||
105 | |||
106 | DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) | ||
107 | static STACK_OF(EVP_PKEY_ASN1_METHOD) *asn1_app_methods = NULL; | ||
108 | 105 | ||
109 | int | 106 | int |
110 | EVP_PKEY_asn1_get_count(void) | 107 | EVP_PKEY_asn1_get_count(void) |
111 | { | 108 | { |
112 | int num = asn1_methods_count; | 109 | return N_ASN1_METHODS; |
113 | |||
114 | if (asn1_app_methods != NULL) | ||
115 | num += sk_EVP_PKEY_ASN1_METHOD_num(asn1_app_methods); | ||
116 | |||
117 | return num; | ||
118 | } | 110 | } |
119 | 111 | ||
120 | const EVP_PKEY_ASN1_METHOD * | 112 | const EVP_PKEY_ASN1_METHOD * |
121 | EVP_PKEY_asn1_get0(int idx) | 113 | EVP_PKEY_asn1_get0(int idx) |
122 | { | 114 | { |
123 | int num = asn1_methods_count; | 115 | if (idx < 0 || idx >= N_ASN1_METHODS) |
124 | |||
125 | if (idx < 0) | ||
126 | return NULL; | 116 | return NULL; |
127 | if (idx < num) | ||
128 | return asn1_methods[idx]; | ||
129 | |||
130 | idx -= num; | ||
131 | 117 | ||
132 | return sk_EVP_PKEY_ASN1_METHOD_value(asn1_app_methods, idx); | 118 | return asn1_methods[idx]; |
133 | } | 119 | } |
134 | 120 | ||
135 | static const EVP_PKEY_ASN1_METHOD * | 121 | static const EVP_PKEY_ASN1_METHOD * |
@@ -196,33 +182,15 @@ EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len) | |||
196 | int | 182 | int |
197 | EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) | 183 | EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) |
198 | { | 184 | { |
199 | if (asn1_app_methods == NULL) { | 185 | EVPerror(ERR_R_DISABLED); |
200 | asn1_app_methods = sk_EVP_PKEY_ASN1_METHOD_new(NULL); | 186 | return 0; |
201 | if (asn1_app_methods == NULL) | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | if (!sk_EVP_PKEY_ASN1_METHOD_push(asn1_app_methods, ameth)) | ||
206 | return 0; | ||
207 | |||
208 | return 1; | ||
209 | } | 187 | } |
210 | 188 | ||
211 | int | 189 | int |
212 | EVP_PKEY_asn1_add_alias(int to, int from) | 190 | EVP_PKEY_asn1_add_alias(int to, int from) |
213 | { | 191 | { |
214 | EVP_PKEY_ASN1_METHOD *ameth; | 192 | EVPerror(ERR_R_DISABLED); |
215 | 193 | return 0; | |
216 | ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); | ||
217 | if (ameth == NULL) | ||
218 | return 0; | ||
219 | |||
220 | ameth->pkey_base_id = to; | ||
221 | if (!EVP_PKEY_asn1_add0(ameth)) { | ||
222 | EVP_PKEY_asn1_free(ameth); | ||
223 | return 0; | ||
224 | } | ||
225 | return 1; | ||
226 | } | 194 | } |
227 | 195 | ||
228 | int | 196 | int |