summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/ameth_lib.c
diff options
context:
space:
mode:
authortb <>2023-12-29 10:59:00 +0000
committertb <>2023-12-29 10:59:00 +0000
commit74f37a921dec4d88238715b69fdd65f00d225fda (patch)
tree75f4dda3052f834420459527c235e1bb9b3f059c /src/lib/libcrypto/asn1/ameth_lib.c
parentc84e468c4aa089677e98a7754e5fc8cb0cd62e54 (diff)
downloadopenbsd-74f37a921dec4d88238715b69fdd65f00d225fda.tar.gz
openbsd-74f37a921dec4d88238715b69fdd65f00d225fda.tar.bz2
openbsd-74f37a921dec4d88238715b69fdd65f00d225fda.zip
Move the EVP_PKEY_asn1_* API that will stay to evp/p_lib.c
Most of these functions are only called from this file internally apart from the pem_str lookups from pem/. In the next major bump we can then remove asn/ameth_lib.c. Also move EVP_PKEY_ASN1_METHOD to evp_local.h. While this is used to dispatch to various ASN.1 decoding routines, it doesn't fit into asn1/ at all.
Diffstat (limited to 'src/lib/libcrypto/asn1/ameth_lib.c')
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c140
1 files changed, 1 insertions, 139 deletions
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index 2165bf06b5..cf3a965a64 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.39 2023/12/29 10:17:26 tb Exp $ */ 1/* $OpenBSD: ameth_lib.c,v 1.40 2023/12/29 10:59:00 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,146 +62,8 @@
62#include <openssl/err.h> 62#include <openssl/err.h>
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64 64
65#include "asn1_local.h"
66#include "evp_local.h" 65#include "evp_local.h"
67 66
68extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
69extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
70extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
71extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
72extern const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth;
73extern const EVP_PKEY_ASN1_METHOD gostimit_asn1_meth;
74extern const EVP_PKEY_ASN1_METHOD gostr01_asn1_meths[];
75extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
76extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
77extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth;
78extern const EVP_PKEY_ASN1_METHOD x25519_asn1_meth;
79
80static const EVP_PKEY_ASN1_METHOD *asn1_methods[] = {
81 &cmac_asn1_meth,
82 &dh_asn1_meth,
83 &dsa_asn1_meths[0],
84 &dsa_asn1_meths[1],
85 &dsa_asn1_meths[2],
86 &dsa_asn1_meths[3],
87 &dsa_asn1_meths[4],
88 &eckey_asn1_meth,
89 &ed25519_asn1_meth,
90 &gostimit_asn1_meth,
91 &gostr01_asn1_meths[0],
92 &gostr01_asn1_meths[1],
93 &gostr01_asn1_meths[2],
94 &hmac_asn1_meth,
95 &rsa_asn1_meths[0],
96 &rsa_asn1_meths[1],
97 &rsa_pss_asn1_meth,
98 &x25519_asn1_meth,
99};
100
101#define N_ASN1_METHODS (sizeof(asn1_methods) / sizeof(asn1_methods[0]))
102
103int
104EVP_PKEY_asn1_get_count(void)
105{
106 return N_ASN1_METHODS;
107}
108
109const EVP_PKEY_ASN1_METHOD *
110EVP_PKEY_asn1_get0(int idx)
111{
112 if (idx < 0 || idx >= N_ASN1_METHODS)
113 return NULL;
114
115 return asn1_methods[idx];
116}
117
118static const EVP_PKEY_ASN1_METHOD *
119pkey_asn1_find(int pkey_id)
120{
121 const EVP_PKEY_ASN1_METHOD *ameth;
122 int i;
123
124 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) {
125 ameth = EVP_PKEY_asn1_get0(i);
126 if (ameth->pkey_id == pkey_id)
127 return ameth;
128 }
129
130 return NULL;
131}
132
133/*
134 * XXX - fix this. In what looks like an infinite loop, this API only makes two
135 * calls to pkey_asn1_find(): If the type resolves to an aliased ASN.1 method,
136 * the second call will find the method it aliases. Codify this in regress and
137 * make this explicit in code.
138 */
139const EVP_PKEY_ASN1_METHOD *
140EVP_PKEY_asn1_find(ENGINE **pe, int type)
141{
142 const EVP_PKEY_ASN1_METHOD *mp;
143
144 if (pe != NULL)
145 *pe = NULL;
146
147 for (;;) {
148 if ((mp = pkey_asn1_find(type)) == NULL)
149 break;
150 if ((mp->pkey_flags & ASN1_PKEY_ALIAS) == 0)
151 break;
152 type = mp->pkey_base_id;
153 }
154
155 return mp;
156}
157
158const EVP_PKEY_ASN1_METHOD *
159EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
160{
161 const EVP_PKEY_ASN1_METHOD *ameth;
162 int i;
163
164 if (len == -1)
165 len = strlen(str);
166 if (pe != NULL)
167 *pe = NULL;
168 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) {
169 ameth = EVP_PKEY_asn1_get0(i);
170 if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
171 continue;
172 if (((int)strlen(ameth->pem_str) == len) &&
173 !strncasecmp(ameth->pem_str, str, len))
174 return ameth;
175 }
176 return NULL;
177}
178
179int
180EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
181 const char **pinfo, const char **ppem_str,
182 const EVP_PKEY_ASN1_METHOD *ameth)
183{
184 if (!ameth)
185 return 0;
186 if (ppkey_id)
187 *ppkey_id = ameth->pkey_id;
188 if (ppkey_base_id)
189 *ppkey_base_id = ameth->pkey_base_id;
190 if (ppkey_flags)
191 *ppkey_flags = ameth->pkey_flags;
192 if (pinfo)
193 *pinfo = ameth->info;
194 if (ppem_str)
195 *ppem_str = ameth->pem_str;
196 return 1;
197}
198
199const EVP_PKEY_ASN1_METHOD*
200EVP_PKEY_get0_asn1(const EVP_PKEY *pkey)
201{
202 return pkey->ameth;
203}
204
205/* 67/*
206 * XXX - remove all the API below here in the next major bump. 68 * XXX - remove all the API below here in the next major bump.
207 */ 69 */