summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c156
-rw-r--r--src/lib/libssl/src/crypto/asn1/ameth_lib.c156
2 files changed, 160 insertions, 152 deletions
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index bbaf6b4dfb..63ff18edae 100644
--- a/src/lib/libcrypto/asn1/ameth_lib.c
+++ b/src/lib/libcrypto/asn1/ameth_lib.c
@@ -9,7 +9,7 @@
9 * are met: 9 * are met:
10 * 10 *
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 13 *
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in 15 * notice, this list of conditions and the following disclaimer in
@@ -72,8 +72,7 @@ extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
72extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; 72extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
73 73
74/* Keep this sorted in type order !! */ 74/* Keep this sorted in type order !! */
75static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 75static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
76{
77#ifndef OPENSSL_NO_RSA 76#ifndef OPENSSL_NO_RSA
78 &rsa_asn1_meths[0], 77 &rsa_asn1_meths[0],
79 &rsa_asn1_meths[1], 78 &rsa_asn1_meths[1],
@@ -99,53 +98,55 @@ typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
99DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) 98DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
100static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; 99static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
101 100
102
103
104#ifdef TEST 101#ifdef TEST
105void main() 102void
103main()
106{ 104{
107 int i; 105 int i;
108 for (i = 0; 106 for (i = 0;
109 i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 107 i < sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); i++)
110 i++)
111 fprintf(stderr, "Number %d id=%d (%s)\n", i, 108 fprintf(stderr, "Number %d id=%d (%s)\n", i,
112 standard_methods[i]->pkey_id, 109 standard_methods[i]->pkey_id,
113 OBJ_nid2sn(standard_methods[i]->pkey_id)); 110 OBJ_nid2sn(standard_methods[i]->pkey_id));
114} 111}
115#endif 112#endif
116 113
117DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, 114DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
118 const EVP_PKEY_ASN1_METHOD *, ameth); 115 const EVP_PKEY_ASN1_METHOD *, ameth);
119 116
120static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, 117static int
121 const EVP_PKEY_ASN1_METHOD * const *b) 118ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
119 const EVP_PKEY_ASN1_METHOD * const *b)
122{ 120{
123 return ((*a)->pkey_id - (*b)->pkey_id); 121 return ((*a)->pkey_id - (*b)->pkey_id);
124} 122}
125 123
126IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, 124IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
127 const EVP_PKEY_ASN1_METHOD *, ameth); 125 const EVP_PKEY_ASN1_METHOD *, ameth);
128 126
129int EVP_PKEY_asn1_get_count(void) 127int
128EVP_PKEY_asn1_get_count(void)
130{ 129{
131 int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 130 int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
132 if (app_methods) 131 if (app_methods)
133 num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); 132 num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
134 return num; 133 return num;
135} 134}
136 135
137const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) 136const EVP_PKEY_ASN1_METHOD *
137EVP_PKEY_asn1_get0(int idx)
138{ 138{
139 int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 139 int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
140 if (idx < 0) 140 if (idx < 0)
141 return NULL; 141 return NULL;
142 if (idx < num) 142 if (idx < num)
143 return standard_methods[idx]; 143 return standard_methods[idx];
144 idx -= num; 144 idx -= num;
145 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); 145 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
146} 146}
147 147
148static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) 148static const EVP_PKEY_ASN1_METHOD *
149pkey_asn1_find(int type)
149{ 150{
150 EVP_PKEY_ASN1_METHOD tmp; 151 EVP_PKEY_ASN1_METHOD tmp;
151 const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; 152 const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
@@ -157,8 +158,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
157 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); 158 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
158 } 159 }
159 ret = OBJ_bsearch_ameth(&t, standard_methods, 160 ret = OBJ_bsearch_ameth(&t, standard_methods,
160 sizeof(standard_methods) 161 sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *));
161 /sizeof(EVP_PKEY_ASN1_METHOD *));
162 if (!ret || !*ret) 162 if (!ret || !*ret)
163 return NULL; 163 return NULL;
164 return *ret; 164 return *ret;
@@ -166,11 +166,12 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
166 166
167/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL 167/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL
168 * also search through engines and set *pe to a functional reference 168 * also search through engines and set *pe to a functional reference
169 * to the engine implementing 'type' or NULL if no engine implements 169 * to the engine implementing 'type' or NULL if no engine implements
170 * it. 170 * it.
171 */ 171 */
172 172
173const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) 173const EVP_PKEY_ASN1_METHOD *
174EVP_PKEY_asn1_find(ENGINE **pe, int type)
174{ 175{
175 const EVP_PKEY_ASN1_METHOD *t; 176 const EVP_PKEY_ASN1_METHOD *t;
176 177
@@ -195,8 +196,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
195 return t; 196 return t;
196} 197}
197 198
198const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, 199const EVP_PKEY_ASN1_METHOD *
199 const char *str, int len) 200EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
200{ 201{
201 int i; 202 int i;
202 const EVP_PKEY_ASN1_METHOD *ameth; 203 const EVP_PKEY_ASN1_METHOD *ameth;
@@ -223,14 +224,15 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
223 ameth = EVP_PKEY_asn1_get0(i); 224 ameth = EVP_PKEY_asn1_get0(i);
224 if (ameth->pkey_flags & ASN1_PKEY_ALIAS) 225 if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
225 continue; 226 continue;
226 if (((int)strlen(ameth->pem_str) == len) && 227 if (((int)strlen(ameth->pem_str) == len) &&
227 !strncasecmp(ameth->pem_str, str, len)) 228 !strncasecmp(ameth->pem_str, str, len))
228 return ameth; 229 return ameth;
229 } 230 }
230 return NULL; 231 return NULL;
231} 232}
232 233
233int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) 234int
235EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
234{ 236{
235 if (app_methods == NULL) { 237 if (app_methods == NULL) {
236 app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); 238 app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
@@ -243,7 +245,8 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
243 return 1; 245 return 1;
244} 246}
245 247
246int EVP_PKEY_asn1_add_alias(int to, int from) 248int
249EVP_PKEY_asn1_add_alias(int to, int from)
247{ 250{
248 EVP_PKEY_ASN1_METHOD *ameth; 251 EVP_PKEY_ASN1_METHOD *ameth;
249 ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); 252 ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
@@ -253,9 +256,10 @@ int EVP_PKEY_asn1_add_alias(int to, int from)
253 return EVP_PKEY_asn1_add0(ameth); 256 return EVP_PKEY_asn1_add0(ameth);
254} 257}
255 258
256int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, 259int
257 const char **pinfo, const char **ppem_str, 260EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
258 const EVP_PKEY_ASN1_METHOD *ameth) 261 const char **pinfo, const char **ppem_str,
262 const EVP_PKEY_ASN1_METHOD *ameth)
259{ 263{
260 if (!ameth) 264 if (!ameth)
261 return 0; 265 return 0;
@@ -272,15 +276,17 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
272 return 1; 276 return 1;
273} 277}
274 278
275const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) 279const EVP_PKEY_ASN1_METHOD*
280EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
276{ 281{
277 return pkey->ameth; 282 return pkey->ameth;
278} 283}
279 284
280EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, 285EVP_PKEY_ASN1_METHOD*
281 const char *pem_str, const char *info) 286EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
282{ 287{
283 EVP_PKEY_ASN1_METHOD *ameth; 288 EVP_PKEY_ASN1_METHOD *ameth;
289
284 ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); 290 ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD));
285 if (!ameth) 291 if (!ameth)
286 return NULL; 292 return NULL;
@@ -295,16 +301,14 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
295 ameth->info = BUF_strdup(info); 301 ameth->info = BUF_strdup(info);
296 if (!ameth->info) 302 if (!ameth->info)
297 goto err; 303 goto err;
298 } 304 } else
299 else
300 ameth->info = NULL; 305 ameth->info = NULL;
301 306
302 if (pem_str) { 307 if (pem_str) {
303 ameth->pem_str = BUF_strdup(pem_str); 308 ameth->pem_str = BUF_strdup(pem_str);
304 if (!ameth->pem_str) 309 if (!ameth->pem_str)
305 goto err; 310 goto err;
306 } 311 } else
307 else
308 ameth->pem_str = NULL; 312 ameth->pem_str = NULL;
309 313
310 ameth->pub_decode = 0; 314 ameth->pub_decode = 0;
@@ -337,17 +341,14 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
337 341
338 return ameth; 342 return ameth;
339 343
340 err: 344err:
341
342 EVP_PKEY_asn1_free(ameth); 345 EVP_PKEY_asn1_free(ameth);
343 return NULL; 346 return NULL;
344
345} 347}
346 348
347void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 349void
348 const EVP_PKEY_ASN1_METHOD *src) 350EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src)
349{ 351{
350
351 dst->pub_decode = src->pub_decode; 352 dst->pub_decode = src->pub_decode;
352 dst->pub_encode = src->pub_encode; 353 dst->pub_encode = src->pub_encode;
353 dst->pub_cmp = src->pub_cmp; 354 dst->pub_cmp = src->pub_cmp;
@@ -375,10 +376,10 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
375 376
376 dst->item_sign = src->item_sign; 377 dst->item_sign = src->item_sign;
377 dst->item_verify = src->item_verify; 378 dst->item_verify = src->item_verify;
378
379} 379}
380 380
381void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) 381void
382EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
382{ 383{
383 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) { 384 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
384 if (ameth->pem_str) 385 if (ameth->pem_str)
@@ -389,14 +390,15 @@ void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
389 } 390 }
390} 391}
391 392
392void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, 393void
393 int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), 394EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
394 int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk), 395 int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
395 int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), 396 int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
396 int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent, 397 int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
397 ASN1_PCTX *pctx), 398 int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
398 int (*pkey_size)(const EVP_PKEY *pk), 399 ASN1_PCTX *pctx),
399 int (*pkey_bits)(const EVP_PKEY *pk)) 400 int (*pkey_size)(const EVP_PKEY *pk),
401 int (*pkey_bits)(const EVP_PKEY *pk))
400{ 402{
401 ameth->pub_decode = pub_decode; 403 ameth->pub_decode = pub_decode;
402 ameth->pub_encode = pub_encode; 404 ameth->pub_encode = pub_encode;
@@ -406,26 +408,27 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
406 ameth->pkey_bits = pkey_bits; 408 ameth->pkey_bits = pkey_bits;
407} 409}
408 410
409void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, 411void
410 int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), 412EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
411 int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), 413 int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
412 int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, 414 int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
413 ASN1_PCTX *pctx)) 415 int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
416 ASN1_PCTX *pctx))
414{ 417{
415 ameth->priv_decode = priv_decode; 418 ameth->priv_decode = priv_decode;
416 ameth->priv_encode = priv_encode; 419 ameth->priv_encode = priv_encode;
417 ameth->priv_print = priv_print; 420 ameth->priv_print = priv_print;
418} 421}
419 422
420void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, 423void
421 int (*param_decode)(EVP_PKEY *pkey, 424EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
422 const unsigned char **pder, int derlen), 425 int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder, int derlen),
423 int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder), 426 int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
424 int (*param_missing)(const EVP_PKEY *pk), 427 int (*param_missing)(const EVP_PKEY *pk),
425 int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from), 428 int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
426 int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), 429 int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
427 int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, 430 int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
428 ASN1_PCTX *pctx)) 431 ASN1_PCTX *pctx))
429{ 432{
430 ameth->param_decode = param_decode; 433 ameth->param_decode = param_decode;
431 ameth->param_encode = param_encode; 434 ameth->param_encode = param_encode;
@@ -435,15 +438,16 @@ void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
435 ameth->param_print = param_print; 438 ameth->param_print = param_print;
436} 439}
437 440
438void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, 441void
439 void (*pkey_free)(EVP_PKEY *pkey)) 442EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
443 void (*pkey_free)(EVP_PKEY *pkey))
440{ 444{
441 ameth->pkey_free = pkey_free; 445 ameth->pkey_free = pkey_free;
442} 446}
443 447
444void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, 448void
445 int (*pkey_ctrl)(EVP_PKEY *pkey, int op, 449EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
446 long arg1, void *arg2)) 450 int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2))
447{ 451{
448 ameth->pkey_ctrl = pkey_ctrl; 452 ameth->pkey_ctrl = pkey_ctrl;
449} 453}
diff --git a/src/lib/libssl/src/crypto/asn1/ameth_lib.c b/src/lib/libssl/src/crypto/asn1/ameth_lib.c
index bbaf6b4dfb..63ff18edae 100644
--- a/src/lib/libssl/src/crypto/asn1/ameth_lib.c
+++ b/src/lib/libssl/src/crypto/asn1/ameth_lib.c
@@ -9,7 +9,7 @@
9 * are met: 9 * are met:
10 * 10 *
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 13 *
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in 15 * notice, this list of conditions and the following disclaimer in
@@ -72,8 +72,7 @@ extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
72extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth; 72extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
73 73
74/* Keep this sorted in type order !! */ 74/* Keep this sorted in type order !! */
75static const EVP_PKEY_ASN1_METHOD *standard_methods[] = 75static const EVP_PKEY_ASN1_METHOD *standard_methods[] = {
76{
77#ifndef OPENSSL_NO_RSA 76#ifndef OPENSSL_NO_RSA
78 &rsa_asn1_meths[0], 77 &rsa_asn1_meths[0],
79 &rsa_asn1_meths[1], 78 &rsa_asn1_meths[1],
@@ -99,53 +98,55 @@ typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
99DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD) 98DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
100static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; 99static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
101 100
102
103
104#ifdef TEST 101#ifdef TEST
105void main() 102void
103main()
106{ 104{
107 int i; 105 int i;
108 for (i = 0; 106 for (i = 0;
109 i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 107 i < sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); i++)
110 i++)
111 fprintf(stderr, "Number %d id=%d (%s)\n", i, 108 fprintf(stderr, "Number %d id=%d (%s)\n", i,
112 standard_methods[i]->pkey_id, 109 standard_methods[i]->pkey_id,
113 OBJ_nid2sn(standard_methods[i]->pkey_id)); 110 OBJ_nid2sn(standard_methods[i]->pkey_id));
114} 111}
115#endif 112#endif
116 113
117DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, 114DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
118 const EVP_PKEY_ASN1_METHOD *, ameth); 115 const EVP_PKEY_ASN1_METHOD *, ameth);
119 116
120static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, 117static int
121 const EVP_PKEY_ASN1_METHOD * const *b) 118ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
119 const EVP_PKEY_ASN1_METHOD * const *b)
122{ 120{
123 return ((*a)->pkey_id - (*b)->pkey_id); 121 return ((*a)->pkey_id - (*b)->pkey_id);
124} 122}
125 123
126IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, 124IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
127 const EVP_PKEY_ASN1_METHOD *, ameth); 125 const EVP_PKEY_ASN1_METHOD *, ameth);
128 126
129int EVP_PKEY_asn1_get_count(void) 127int
128EVP_PKEY_asn1_get_count(void)
130{ 129{
131 int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 130 int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
132 if (app_methods) 131 if (app_methods)
133 num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); 132 num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
134 return num; 133 return num;
135} 134}
136 135
137const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) 136const EVP_PKEY_ASN1_METHOD *
137EVP_PKEY_asn1_get0(int idx)
138{ 138{
139 int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); 139 int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
140 if (idx < 0) 140 if (idx < 0)
141 return NULL; 141 return NULL;
142 if (idx < num) 142 if (idx < num)
143 return standard_methods[idx]; 143 return standard_methods[idx];
144 idx -= num; 144 idx -= num;
145 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); 145 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
146} 146}
147 147
148static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) 148static const EVP_PKEY_ASN1_METHOD *
149pkey_asn1_find(int type)
149{ 150{
150 EVP_PKEY_ASN1_METHOD tmp; 151 EVP_PKEY_ASN1_METHOD tmp;
151 const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret; 152 const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
@@ -157,8 +158,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
157 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); 158 return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
158 } 159 }
159 ret = OBJ_bsearch_ameth(&t, standard_methods, 160 ret = OBJ_bsearch_ameth(&t, standard_methods,
160 sizeof(standard_methods) 161 sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *));
161 /sizeof(EVP_PKEY_ASN1_METHOD *));
162 if (!ret || !*ret) 162 if (!ret || !*ret)
163 return NULL; 163 return NULL;
164 return *ret; 164 return *ret;
@@ -166,11 +166,12 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
166 166
167/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL 167/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL
168 * also search through engines and set *pe to a functional reference 168 * also search through engines and set *pe to a functional reference
169 * to the engine implementing 'type' or NULL if no engine implements 169 * to the engine implementing 'type' or NULL if no engine implements
170 * it. 170 * it.
171 */ 171 */
172 172
173const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) 173const EVP_PKEY_ASN1_METHOD *
174EVP_PKEY_asn1_find(ENGINE **pe, int type)
174{ 175{
175 const EVP_PKEY_ASN1_METHOD *t; 176 const EVP_PKEY_ASN1_METHOD *t;
176 177
@@ -195,8 +196,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
195 return t; 196 return t;
196} 197}
197 198
198const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe, 199const EVP_PKEY_ASN1_METHOD *
199 const char *str, int len) 200EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
200{ 201{
201 int i; 202 int i;
202 const EVP_PKEY_ASN1_METHOD *ameth; 203 const EVP_PKEY_ASN1_METHOD *ameth;
@@ -223,14 +224,15 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
223 ameth = EVP_PKEY_asn1_get0(i); 224 ameth = EVP_PKEY_asn1_get0(i);
224 if (ameth->pkey_flags & ASN1_PKEY_ALIAS) 225 if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
225 continue; 226 continue;
226 if (((int)strlen(ameth->pem_str) == len) && 227 if (((int)strlen(ameth->pem_str) == len) &&
227 !strncasecmp(ameth->pem_str, str, len)) 228 !strncasecmp(ameth->pem_str, str, len))
228 return ameth; 229 return ameth;
229 } 230 }
230 return NULL; 231 return NULL;
231} 232}
232 233
233int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) 234int
235EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
234{ 236{
235 if (app_methods == NULL) { 237 if (app_methods == NULL) {
236 app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); 238 app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
@@ -243,7 +245,8 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
243 return 1; 245 return 1;
244} 246}
245 247
246int EVP_PKEY_asn1_add_alias(int to, int from) 248int
249EVP_PKEY_asn1_add_alias(int to, int from)
247{ 250{
248 EVP_PKEY_ASN1_METHOD *ameth; 251 EVP_PKEY_ASN1_METHOD *ameth;
249 ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); 252 ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
@@ -253,9 +256,10 @@ int EVP_PKEY_asn1_add_alias(int to, int from)
253 return EVP_PKEY_asn1_add0(ameth); 256 return EVP_PKEY_asn1_add0(ameth);
254} 257}
255 258
256int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags, 259int
257 const char **pinfo, const char **ppem_str, 260EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
258 const EVP_PKEY_ASN1_METHOD *ameth) 261 const char **pinfo, const char **ppem_str,
262 const EVP_PKEY_ASN1_METHOD *ameth)
259{ 263{
260 if (!ameth) 264 if (!ameth)
261 return 0; 265 return 0;
@@ -272,15 +276,17 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
272 return 1; 276 return 1;
273} 277}
274 278
275const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey) 279const EVP_PKEY_ASN1_METHOD*
280EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
276{ 281{
277 return pkey->ameth; 282 return pkey->ameth;
278} 283}
279 284
280EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags, 285EVP_PKEY_ASN1_METHOD*
281 const char *pem_str, const char *info) 286EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
282{ 287{
283 EVP_PKEY_ASN1_METHOD *ameth; 288 EVP_PKEY_ASN1_METHOD *ameth;
289
284 ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD)); 290 ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD));
285 if (!ameth) 291 if (!ameth)
286 return NULL; 292 return NULL;
@@ -295,16 +301,14 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
295 ameth->info = BUF_strdup(info); 301 ameth->info = BUF_strdup(info);
296 if (!ameth->info) 302 if (!ameth->info)
297 goto err; 303 goto err;
298 } 304 } else
299 else
300 ameth->info = NULL; 305 ameth->info = NULL;
301 306
302 if (pem_str) { 307 if (pem_str) {
303 ameth->pem_str = BUF_strdup(pem_str); 308 ameth->pem_str = BUF_strdup(pem_str);
304 if (!ameth->pem_str) 309 if (!ameth->pem_str)
305 goto err; 310 goto err;
306 } 311 } else
307 else
308 ameth->pem_str = NULL; 312 ameth->pem_str = NULL;
309 313
310 ameth->pub_decode = 0; 314 ameth->pub_decode = 0;
@@ -337,17 +341,14 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
337 341
338 return ameth; 342 return ameth;
339 343
340 err: 344err:
341
342 EVP_PKEY_asn1_free(ameth); 345 EVP_PKEY_asn1_free(ameth);
343 return NULL; 346 return NULL;
344
345} 347}
346 348
347void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, 349void
348 const EVP_PKEY_ASN1_METHOD *src) 350EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src)
349{ 351{
350
351 dst->pub_decode = src->pub_decode; 352 dst->pub_decode = src->pub_decode;
352 dst->pub_encode = src->pub_encode; 353 dst->pub_encode = src->pub_encode;
353 dst->pub_cmp = src->pub_cmp; 354 dst->pub_cmp = src->pub_cmp;
@@ -375,10 +376,10 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
375 376
376 dst->item_sign = src->item_sign; 377 dst->item_sign = src->item_sign;
377 dst->item_verify = src->item_verify; 378 dst->item_verify = src->item_verify;
378
379} 379}
380 380
381void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth) 381void
382EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
382{ 383{
383 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) { 384 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
384 if (ameth->pem_str) 385 if (ameth->pem_str)
@@ -389,14 +390,15 @@ void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
389 } 390 }
390} 391}
391 392
392void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, 393void
393 int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub), 394EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
394 int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk), 395 int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
395 int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), 396 int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
396 int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent, 397 int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
397 ASN1_PCTX *pctx), 398 int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
398 int (*pkey_size)(const EVP_PKEY *pk), 399 ASN1_PCTX *pctx),
399 int (*pkey_bits)(const EVP_PKEY *pk)) 400 int (*pkey_size)(const EVP_PKEY *pk),
401 int (*pkey_bits)(const EVP_PKEY *pk))
400{ 402{
401 ameth->pub_decode = pub_decode; 403 ameth->pub_decode = pub_decode;
402 ameth->pub_encode = pub_encode; 404 ameth->pub_encode = pub_encode;
@@ -406,26 +408,27 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
406 ameth->pkey_bits = pkey_bits; 408 ameth->pkey_bits = pkey_bits;
407} 409}
408 410
409void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, 411void
410 int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf), 412EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
411 int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), 413 int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
412 int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent, 414 int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
413 ASN1_PCTX *pctx)) 415 int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
416 ASN1_PCTX *pctx))
414{ 417{
415 ameth->priv_decode = priv_decode; 418 ameth->priv_decode = priv_decode;
416 ameth->priv_encode = priv_encode; 419 ameth->priv_encode = priv_encode;
417 ameth->priv_print = priv_print; 420 ameth->priv_print = priv_print;
418} 421}
419 422
420void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth, 423void
421 int (*param_decode)(EVP_PKEY *pkey, 424EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
422 const unsigned char **pder, int derlen), 425 int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder, int derlen),
423 int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder), 426 int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
424 int (*param_missing)(const EVP_PKEY *pk), 427 int (*param_missing)(const EVP_PKEY *pk),
425 int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from), 428 int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
426 int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b), 429 int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
427 int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent, 430 int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
428 ASN1_PCTX *pctx)) 431 ASN1_PCTX *pctx))
429{ 432{
430 ameth->param_decode = param_decode; 433 ameth->param_decode = param_decode;
431 ameth->param_encode = param_encode; 434 ameth->param_encode = param_encode;
@@ -435,15 +438,16 @@ void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
435 ameth->param_print = param_print; 438 ameth->param_print = param_print;
436} 439}
437 440
438void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth, 441void
439 void (*pkey_free)(EVP_PKEY *pkey)) 442EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
443 void (*pkey_free)(EVP_PKEY *pkey))
440{ 444{
441 ameth->pkey_free = pkey_free; 445 ameth->pkey_free = pkey_free;
442} 446}
443 447
444void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth, 448void
445 int (*pkey_ctrl)(EVP_PKEY *pkey, int op, 449EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
446 long arg1, void *arg2)) 450 int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2))
447{ 451{
448 ameth->pkey_ctrl = pkey_ctrl; 452 ameth->pkey_ctrl = pkey_ctrl;
449} 453}