1221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * project 2006.
3221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom */
4221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/* ====================================================================
5221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
6221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
7221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Redistribution and use in source and binary forms, with or without
8221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * modification, are permitted provided that the following conditions
9221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * are met:
10221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
11221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 1. Redistributions of source code must retain the above copyright
12221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    notice, this list of conditions and the following disclaimer.
13221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
14221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 2. Redistributions in binary form must reproduce the above copyright
15221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    notice, this list of conditions and the following disclaimer in
16221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    the documentation and/or other materials provided with the
17221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    distribution.
18221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
19221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 3. All advertising materials mentioning features or use of this
20221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    software must display the following acknowledgment:
21221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    "This product includes software developed by the OpenSSL Project
22221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
24221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    endorse or promote products derived from this software without
26221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    prior written permission. For written permission, please contact
27221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    licensing@OpenSSL.org.
28221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
29221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 5. Products derived from this software may not be called "OpenSSL"
30221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    nor may "OpenSSL" appear in their names without prior written
31221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    permission of the OpenSSL Project.
32221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
33221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * 6. Redistributions of any form whatsoever must retain the following
34221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    acknowledgment:
35221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    "This product includes software developed by the OpenSSL Project
36221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
38221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * OF THE POSSIBILITY OF SUCH DAMAGE.
50221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * ====================================================================
51221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
52221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * This product includes cryptographic software written by Eric Young
53221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * (eay@cryptsoft.com).  This product includes software written by Tim
54221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Hudson (tjh@cryptsoft.com).
55221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *
56221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom */
57221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
58221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include <stdio.h>
59221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include "cryptlib.h"
60221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include <openssl/asn1t.h>
61221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include <openssl/x509.h>
62221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_ENGINE
63221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include <openssl/engine.h>
64221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
65221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#include "asn1_locl.h"
66221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
67221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromextern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[];
68221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromextern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[];
69221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromextern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
70221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromextern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
71221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromextern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
72392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstromextern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
73221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
74221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/* Keep this sorted in type order !! */
75221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromstatic const EVP_PKEY_ASN1_METHOD *standard_methods[] =
76221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
77221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_RSA
78221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&rsa_asn1_meths[0],
79221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&rsa_asn1_meths[1],
80221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
81221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_DH
82221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dh_asn1_meth,
83221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
84221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_DSA
85221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dsa_asn1_meths[0],
86221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dsa_asn1_meths[1],
87221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dsa_asn1_meths[2],
88221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dsa_asn1_meths[3],
89221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&dsa_asn1_meths[4],
90221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
91221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_EC
92221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	&eckey_asn1_meth,
93221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
94392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	&hmac_asn1_meth,
95392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	&cmac_asn1_meth
96221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	};
97221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
98221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromtypedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
99221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromDECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD)
100221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromstatic STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL;
101221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
102221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
103221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
104221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifdef TEST
105221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid main()
106221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
107221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	int i;
108221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	for (i = 0;
109221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		i < sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
110221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		i++)
111221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		fprintf(stderr, "Number %d id=%d (%s)\n", i,
112221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			standard_methods[i]->pkey_id,
113221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			OBJ_nid2sn(standard_methods[i]->pkey_id));
114221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
115221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
116221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
117221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromDECLARE_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
118221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			   const EVP_PKEY_ASN1_METHOD *, ameth);
119221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
120221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromstatic int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
121221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		     const EVP_PKEY_ASN1_METHOD * const *b)
122221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
123221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom        return ((*a)->pkey_id - (*b)->pkey_id);
124221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
125221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
126221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromIMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *,
127221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			     const EVP_PKEY_ASN1_METHOD *, ameth);
128221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
129221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromint EVP_PKEY_asn1_get_count(void)
130221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
131221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
132221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (app_methods)
133221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
134221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return num;
135221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
136221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
137221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromconst EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx)
138221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
139221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *);
140221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (idx < 0)
141221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return NULL;
142221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (idx < num)
143221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return standard_methods[idx];
144221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	idx -= num;
145221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
146221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
147221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
148221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromstatic const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
149221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
150221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	EVP_PKEY_ASN1_METHOD tmp;
151221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	const EVP_PKEY_ASN1_METHOD *t = &tmp, **ret;
152221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	tmp.pkey_id = type;
153221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (app_methods)
154221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
155221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int idx;
156221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp);
157221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (idx >= 0)
158221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
159221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
160221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ret = OBJ_bsearch_ameth(&t, standard_methods,
161221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			  sizeof(standard_methods)
162221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			  /sizeof(EVP_PKEY_ASN1_METHOD *));
163221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (!ret || !*ret)
164221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return NULL;
165221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return *ret;
166221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
167221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
168221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/* Find an implementation of an ASN1 algorithm. If 'pe' is not NULL
169221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * also search through engines and set *pe to a functional reference
170221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * to the engine implementing 'type' or NULL if no engine implements
171221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * it.
172221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom */
173221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
174221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromconst EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
175221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
176221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	const EVP_PKEY_ASN1_METHOD *t;
177221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
178221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	for (;;)
179221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
180221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		t = pkey_asn1_find(type);
181221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (!t || !(t->pkey_flags & ASN1_PKEY_ALIAS))
182221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			break;
183221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		type = t->pkey_base_id;
184221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
185221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (pe)
186221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
187221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_ENGINE
18881c4de7869b646592127e952cda763abf8305069Brian Carlstrom		ENGINE *e;
189221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		/* type will contain the final unaliased type */
190221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		e = ENGINE_get_pkey_asn1_meth_engine(type);
191221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (e)
192221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			{
193221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			*pe = e;
194221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			return ENGINE_get_pkey_asn1_meth(e, type);
195221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			}
196221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
197221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*pe = NULL;
198221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
199221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return t;
200221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
201221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
202221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromconst EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
203221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom					const char *str, int len)
204221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
205221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	int i;
206221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	const EVP_PKEY_ASN1_METHOD *ameth;
207221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (len == -1)
208221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		len = strlen(str);
209221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (pe)
210221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
211221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#ifndef OPENSSL_NO_ENGINE
212221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ENGINE *e;
213221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
214221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (ameth)
215221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			{
216221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			/* Convert structural into
217221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			 * functional reference
218221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			 */
219221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			if (!ENGINE_init(e))
220221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom				ameth = NULL;
221221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			ENGINE_free(e);
222221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			*pe = e;
223221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			return ameth;
224221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			}
225221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom#endif
226221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*pe = NULL;
227221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
228221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	for (i = 0; i < EVP_PKEY_asn1_get_count(); i++)
229221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
230221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth = EVP_PKEY_asn1_get0(i);
231221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
232221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			continue;
233221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (((int)strlen(ameth->pem_str) == len) &&
234221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			!strncasecmp(ameth->pem_str, str, len))
235221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			return ameth;
236221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
237221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return NULL;
238221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
239221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
240221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromint EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
241221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
242221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (app_methods == NULL)
243221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
244221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
245221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (!app_methods)
246221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			return 0;
247221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
248221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth))
249221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return 0;
250221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	sk_EVP_PKEY_ASN1_METHOD_sort(app_methods);
251221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return 1;
252221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
253221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
254221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromint EVP_PKEY_asn1_add_alias(int to, int from)
255221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
256221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	EVP_PKEY_ASN1_METHOD *ameth;
257221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
258221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (!ameth)
259221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return 0;
260221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_base_id = to;
261c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root	if (!EVP_PKEY_asn1_add0(ameth))
262c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root		{
263c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root		EVP_PKEY_asn1_free(ameth);
264c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root		return 0;
265c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root		}
266c64f6fe2be99cb3fa8e491b5bede9a217de87a4cKenny Root	return 1;
267221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
268221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
269221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromint EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
270221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom				const char **pinfo, const char **ppem_str,
271221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom					const EVP_PKEY_ASN1_METHOD *ameth)
272221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
273221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (!ameth)
274221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return 0;
275221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (ppkey_id)
276221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*ppkey_id = ameth->pkey_id;
277221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (ppkey_base_id)
278221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*ppkey_base_id = ameth->pkey_base_id;
279221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (ppkey_flags)
280221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*ppkey_flags = ameth->pkey_flags;
281221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (pinfo)
282221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*pinfo = ameth->info;
283221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (ppem_str)
284221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		*ppem_str = ameth->pem_str;
285221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return 1;
286221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
287221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
288221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromconst EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
289221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
290221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return pkey->ameth;
291221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
292221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
293221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromEVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
294221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom					const char *pem_str, const char *info)
295221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
296221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	EVP_PKEY_ASN1_METHOD *ameth;
297221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD));
298221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (!ameth)
299221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		return NULL;
300221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
301392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	memset(ameth, 0, sizeof(EVP_PKEY_ASN1_METHOD));
302392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom
303221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_id = id;
304221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_base_id = id;
305221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
306221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
307221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (info)
308221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
309221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth->info = BUF_strdup(info);
310221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (!ameth->info)
311221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			goto err;
312221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
313221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	else
314221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth->info = NULL;
315221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
316221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (pem_str)
317221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
318221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth->pem_str = BUF_strdup(pem_str);
319221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (!ameth->pem_str)
320221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			goto err;
321221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
322221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	else
323221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		ameth->pem_str = NULL;
324221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
325221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_decode = 0;
326221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_encode = 0;
327221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_cmp = 0;
328221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_print = 0;
329221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
330221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_decode = 0;
331221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_encode = 0;
332221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_print = 0;
333221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
334221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->old_priv_encode = 0;
335221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->old_priv_decode = 0;
336221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
337392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ameth->item_verify = 0;
338392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	ameth->item_sign = 0;
339392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom
340221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_size = 0;
341221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_bits = 0;
342221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
343221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_decode = 0;
344221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_encode = 0;
345221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_missing = 0;
346221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_copy = 0;
347221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_cmp = 0;
348221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_print = 0;
349221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
350221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_free = 0;
351221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_ctrl = 0;
352221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
353221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return ameth;
354221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
355221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	err:
356221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
357221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	EVP_PKEY_asn1_free(ameth);
358221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	return NULL;
359221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
360221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
361221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
362221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
363221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			const EVP_PKEY_ASN1_METHOD *src)
364221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
365221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
366221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pub_decode = src->pub_decode;
367221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pub_encode = src->pub_encode;
368221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pub_cmp = src->pub_cmp;
369221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pub_print = src->pub_print;
370221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
371221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->priv_decode = src->priv_decode;
372221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->priv_encode = src->priv_encode;
373221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->priv_print = src->priv_print;
374221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
375221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->old_priv_encode = src->old_priv_encode;
376221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->old_priv_decode = src->old_priv_decode;
377221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
378221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pkey_size = src->pkey_size;
379221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pkey_bits = src->pkey_bits;
380221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
381221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_decode = src->param_decode;
382221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_encode = src->param_encode;
383221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_missing = src->param_missing;
384221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_copy = src->param_copy;
385221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_cmp = src->param_cmp;
386221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->param_print = src->param_print;
387221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
388221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pkey_free = src->pkey_free;
389221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	dst->pkey_ctrl = src->pkey_ctrl;
390221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
391392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	dst->item_sign = src->item_sign;
392392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom	dst->item_verify = src->item_verify;
393392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom
394221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
395221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
396221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
397221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
398221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
399221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		{
400221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (ameth->pem_str)
401221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			OPENSSL_free(ameth->pem_str);
402221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		if (ameth->info)
403221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom			OPENSSL_free(ameth->info);
404221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		OPENSSL_free(ameth);
405221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		}
406221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
407221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
408221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
409221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
410221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
411221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
412221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
413221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom							ASN1_PCTX *pctx),
414221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pkey_size)(const EVP_PKEY *pk),
415221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pkey_bits)(const EVP_PKEY *pk))
416221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
417221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_decode = pub_decode;
418221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_encode = pub_encode;
419221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_cmp = pub_cmp;
420221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pub_print = pub_print;
421221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_size = pkey_size;
422221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_bits = pkey_bits;
423221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
424221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
425221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
426221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
427221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
428221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
429221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom							ASN1_PCTX *pctx))
430221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
431221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_decode = priv_decode;
432221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_encode = priv_encode;
433221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->priv_print = priv_print;
434221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
435221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
436221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
437221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_decode)(EVP_PKEY *pkey,
438221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom				const unsigned char **pder, int derlen),
439221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_encode)(const EVP_PKEY *pkey, unsigned char **pder),
440221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_missing)(const EVP_PKEY *pk),
441221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
442221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
443221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
444221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom							ASN1_PCTX *pctx))
445221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
446221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_decode = param_decode;
447221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_encode = param_encode;
448221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_missing = param_missing;
449221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_copy = param_copy;
450221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_cmp = param_cmp;
451221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->param_print = param_print;
452221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
453221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
454221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
455221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		void (*pkey_free)(EVP_PKEY *pkey))
456221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
457221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_free = pkey_free;
458221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
459221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom
460221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
461221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom		int (*pkey_ctrl)(EVP_PKEY *pkey, int op,
462221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom							long arg1, void *arg2))
463221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	{
464221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	ameth->pkey_ctrl = pkey_ctrl;
465221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom	}
466