xref: /dragonfly/crypto/libressl/crypto/pem/pem_pk8.c (revision 72c33676)
172c33676SMaxim Ag /* $OpenBSD: pem_pk8.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2f5b1c8a1SJohn Marino /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3f5b1c8a1SJohn Marino  * All rights reserved.
4f5b1c8a1SJohn Marino  *
5f5b1c8a1SJohn Marino  * This package is an SSL implementation written
6f5b1c8a1SJohn Marino  * by Eric Young (eay@cryptsoft.com).
7f5b1c8a1SJohn Marino  * The implementation was written so as to conform with Netscapes SSL.
8f5b1c8a1SJohn Marino  *
9f5b1c8a1SJohn Marino  * This library is free for commercial and non-commercial use as long as
10f5b1c8a1SJohn Marino  * the following conditions are aheared to.  The following conditions
11f5b1c8a1SJohn Marino  * apply to all code found in this distribution, be it the RC4, RSA,
12f5b1c8a1SJohn Marino  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13f5b1c8a1SJohn Marino  * included with this distribution is covered by the same copyright terms
14f5b1c8a1SJohn Marino  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15f5b1c8a1SJohn Marino  *
16f5b1c8a1SJohn Marino  * Copyright remains Eric Young's, and as such any Copyright notices in
17f5b1c8a1SJohn Marino  * the code are not to be removed.
18f5b1c8a1SJohn Marino  * If this package is used in a product, Eric Young should be given attribution
19f5b1c8a1SJohn Marino  * as the author of the parts of the library used.
20f5b1c8a1SJohn Marino  * This can be in the form of a textual message at program startup or
21f5b1c8a1SJohn Marino  * in documentation (online or textual) provided with the package.
22f5b1c8a1SJohn Marino  *
23f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
24f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
25f5b1c8a1SJohn Marino  * are met:
26f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the copyright
27f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
28f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
29f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
30f5b1c8a1SJohn Marino  *    documentation and/or other materials provided with the distribution.
31f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this software
32f5b1c8a1SJohn Marino  *    must display the following acknowledgement:
33f5b1c8a1SJohn Marino  *    "This product includes cryptographic software written by
34f5b1c8a1SJohn Marino  *     Eric Young (eay@cryptsoft.com)"
35f5b1c8a1SJohn Marino  *    The word 'cryptographic' can be left out if the rouines from the library
36f5b1c8a1SJohn Marino  *    being used are not cryptographic related :-).
37f5b1c8a1SJohn Marino  * 4. If you include any Windows specific code (or a derivative thereof) from
38f5b1c8a1SJohn Marino  *    the apps directory (application code) you must include an acknowledgement:
39f5b1c8a1SJohn Marino  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40f5b1c8a1SJohn Marino  *
41f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42f5b1c8a1SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44f5b1c8a1SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45f5b1c8a1SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46f5b1c8a1SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47f5b1c8a1SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49f5b1c8a1SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50f5b1c8a1SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51f5b1c8a1SJohn Marino  * SUCH DAMAGE.
52f5b1c8a1SJohn Marino  *
53f5b1c8a1SJohn Marino  * The licence and distribution terms for any publically available version or
54f5b1c8a1SJohn Marino  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55f5b1c8a1SJohn Marino  * copied and put under another distribution licence
56f5b1c8a1SJohn Marino  * [including the GNU Public Licence.]
57f5b1c8a1SJohn Marino  */
58f5b1c8a1SJohn Marino 
59f5b1c8a1SJohn Marino #include <stdio.h>
60f5b1c8a1SJohn Marino #include <string.h>
61f5b1c8a1SJohn Marino 
62f5b1c8a1SJohn Marino #include <openssl/buffer.h>
63f5b1c8a1SJohn Marino #include <openssl/err.h>
64f5b1c8a1SJohn Marino #include <openssl/evp.h>
65f5b1c8a1SJohn Marino #include <openssl/objects.h>
66f5b1c8a1SJohn Marino #include <openssl/pem.h>
67f5b1c8a1SJohn Marino #include <openssl/pkcs12.h>
68f5b1c8a1SJohn Marino #include <openssl/x509.h>
69f5b1c8a1SJohn Marino 
70f5b1c8a1SJohn Marino static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid,
71f5b1c8a1SJohn Marino     const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
72f5b1c8a1SJohn Marino static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder, int nid,
73f5b1c8a1SJohn Marino     const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
74f5b1c8a1SJohn Marino 
75f5b1c8a1SJohn Marino /* These functions write a private key in PKCS#8 format: it is a "drop in"
76f5b1c8a1SJohn Marino  * replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
77f5b1c8a1SJohn Marino  * is NULL then it uses the unencrypted private key form. The 'nid' versions
78f5b1c8a1SJohn Marino  * uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
79f5b1c8a1SJohn Marino  */
80f5b1c8a1SJohn Marino 
81f5b1c8a1SJohn Marino int
PEM_write_bio_PKCS8PrivateKey_nid(BIO * bp,EVP_PKEY * x,int nid,char * kstr,int klen,pem_password_cb * cb,void * u)82f5b1c8a1SJohn Marino PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr,
83f5b1c8a1SJohn Marino     int klen, pem_password_cb *cb, void *u)
84f5b1c8a1SJohn Marino {
85f5b1c8a1SJohn Marino 	return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
86f5b1c8a1SJohn Marino }
87f5b1c8a1SJohn Marino 
88f5b1c8a1SJohn Marino int
PEM_write_bio_PKCS8PrivateKey(BIO * bp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)89f5b1c8a1SJohn Marino PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
90f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
91f5b1c8a1SJohn Marino {
92f5b1c8a1SJohn Marino 	return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
93f5b1c8a1SJohn Marino }
94f5b1c8a1SJohn Marino 
95f5b1c8a1SJohn Marino int
i2d_PKCS8PrivateKey_bio(BIO * bp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)96f5b1c8a1SJohn Marino i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
97f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
98f5b1c8a1SJohn Marino {
99f5b1c8a1SJohn Marino 	return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
100f5b1c8a1SJohn Marino }
101f5b1c8a1SJohn Marino 
102f5b1c8a1SJohn Marino int
i2d_PKCS8PrivateKey_nid_bio(BIO * bp,EVP_PKEY * x,int nid,char * kstr,int klen,pem_password_cb * cb,void * u)103f5b1c8a1SJohn Marino i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
104f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
105f5b1c8a1SJohn Marino {
106f5b1c8a1SJohn Marino 	return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
107f5b1c8a1SJohn Marino }
108f5b1c8a1SJohn Marino 
109f5b1c8a1SJohn Marino static int
do_pk8pkey(BIO * bp,EVP_PKEY * x,int isder,int nid,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)110f5b1c8a1SJohn Marino do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
111f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
112f5b1c8a1SJohn Marino {
113f5b1c8a1SJohn Marino 	X509_SIG *p8;
114f5b1c8a1SJohn Marino 	PKCS8_PRIV_KEY_INFO *p8inf;
115f5b1c8a1SJohn Marino 	char buf[PEM_BUFSIZE];
116f5b1c8a1SJohn Marino 	int ret;
117f5b1c8a1SJohn Marino 
118f5b1c8a1SJohn Marino 	if (!(p8inf = EVP_PKEY2PKCS8(x))) {
11972c33676SMaxim Ag 		PEMerror(PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
120f5b1c8a1SJohn Marino 		return 0;
121f5b1c8a1SJohn Marino 	}
122f5b1c8a1SJohn Marino 	if (enc || (nid != -1)) {
123f5b1c8a1SJohn Marino 		if (!kstr) {
124f5b1c8a1SJohn Marino 			if (!cb)
125f5b1c8a1SJohn Marino 				klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
126f5b1c8a1SJohn Marino 			else
127f5b1c8a1SJohn Marino 				klen = cb(buf, PEM_BUFSIZE, 1, u);
128f5b1c8a1SJohn Marino 			if (klen <= 0) {
12972c33676SMaxim Ag 				PEMerror(PEM_R_READ_KEY);
130f5b1c8a1SJohn Marino 				PKCS8_PRIV_KEY_INFO_free(p8inf);
131f5b1c8a1SJohn Marino 				return 0;
132f5b1c8a1SJohn Marino 			}
133f5b1c8a1SJohn Marino 
134f5b1c8a1SJohn Marino 			kstr = buf;
135f5b1c8a1SJohn Marino 		}
136f5b1c8a1SJohn Marino 		p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
137f5b1c8a1SJohn Marino 		if (kstr == buf)
138f5b1c8a1SJohn Marino 			explicit_bzero(buf, klen);
139f5b1c8a1SJohn Marino 		PKCS8_PRIV_KEY_INFO_free(p8inf);
140f5b1c8a1SJohn Marino 		if (isder)
141f5b1c8a1SJohn Marino 			ret = i2d_PKCS8_bio(bp, p8);
142f5b1c8a1SJohn Marino 		else
143f5b1c8a1SJohn Marino 			ret = PEM_write_bio_PKCS8(bp, p8);
144f5b1c8a1SJohn Marino 		X509_SIG_free(p8);
145f5b1c8a1SJohn Marino 		return ret;
146f5b1c8a1SJohn Marino 	} else {
147f5b1c8a1SJohn Marino 		if (isder)
148f5b1c8a1SJohn Marino 			ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
149f5b1c8a1SJohn Marino 		else
150f5b1c8a1SJohn Marino 			ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
151f5b1c8a1SJohn Marino 		PKCS8_PRIV_KEY_INFO_free(p8inf);
152f5b1c8a1SJohn Marino 		return ret;
153f5b1c8a1SJohn Marino 	}
154f5b1c8a1SJohn Marino }
155f5b1c8a1SJohn Marino 
156f5b1c8a1SJohn Marino EVP_PKEY *
d2i_PKCS8PrivateKey_bio(BIO * bp,EVP_PKEY ** x,pem_password_cb * cb,void * u)157f5b1c8a1SJohn Marino d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
158f5b1c8a1SJohn Marino {
159f5b1c8a1SJohn Marino 	PKCS8_PRIV_KEY_INFO *p8inf = NULL;
160f5b1c8a1SJohn Marino 	X509_SIG *p8 = NULL;
161f5b1c8a1SJohn Marino 	int klen;
162f5b1c8a1SJohn Marino 	EVP_PKEY *ret;
163f5b1c8a1SJohn Marino 	char psbuf[PEM_BUFSIZE];
164f5b1c8a1SJohn Marino 
165f5b1c8a1SJohn Marino 	p8 = d2i_PKCS8_bio(bp, NULL);
166f5b1c8a1SJohn Marino 	if (!p8)
167f5b1c8a1SJohn Marino 		return NULL;
168f5b1c8a1SJohn Marino 	if (cb)
169f5b1c8a1SJohn Marino 		klen = cb(psbuf, PEM_BUFSIZE, 0, u);
170f5b1c8a1SJohn Marino 	else
171f5b1c8a1SJohn Marino 		klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
172f5b1c8a1SJohn Marino 	if (klen <= 0) {
17372c33676SMaxim Ag 		PEMerror(PEM_R_BAD_PASSWORD_READ);
174f5b1c8a1SJohn Marino 		X509_SIG_free(p8);
175f5b1c8a1SJohn Marino 		return NULL;
176f5b1c8a1SJohn Marino 	}
177f5b1c8a1SJohn Marino 	p8inf = PKCS8_decrypt(p8, psbuf, klen);
178f5b1c8a1SJohn Marino 	X509_SIG_free(p8);
179f5b1c8a1SJohn Marino 	if (!p8inf)
180f5b1c8a1SJohn Marino 		return NULL;
181f5b1c8a1SJohn Marino 	ret = EVP_PKCS82PKEY(p8inf);
182f5b1c8a1SJohn Marino 	PKCS8_PRIV_KEY_INFO_free(p8inf);
183f5b1c8a1SJohn Marino 	if (!ret)
184f5b1c8a1SJohn Marino 		return NULL;
185f5b1c8a1SJohn Marino 	if (x) {
186f5b1c8a1SJohn Marino 		EVP_PKEY_free(*x);
187f5b1c8a1SJohn Marino 		*x = ret;
188f5b1c8a1SJohn Marino 	}
189f5b1c8a1SJohn Marino 	return ret;
190f5b1c8a1SJohn Marino }
191f5b1c8a1SJohn Marino 
192f5b1c8a1SJohn Marino 
193f5b1c8a1SJohn Marino int
i2d_PKCS8PrivateKey_fp(FILE * fp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)194f5b1c8a1SJohn Marino i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
195f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
196f5b1c8a1SJohn Marino {
197f5b1c8a1SJohn Marino 	return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
198f5b1c8a1SJohn Marino }
199f5b1c8a1SJohn Marino 
200f5b1c8a1SJohn Marino int
i2d_PKCS8PrivateKey_nid_fp(FILE * fp,EVP_PKEY * x,int nid,char * kstr,int klen,pem_password_cb * cb,void * u)201f5b1c8a1SJohn Marino i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr,
202f5b1c8a1SJohn Marino     int klen, pem_password_cb *cb, void *u)
203f5b1c8a1SJohn Marino {
204f5b1c8a1SJohn Marino 	return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
205f5b1c8a1SJohn Marino }
206f5b1c8a1SJohn Marino 
207f5b1c8a1SJohn Marino int
PEM_write_PKCS8PrivateKey_nid(FILE * fp,EVP_PKEY * x,int nid,char * kstr,int klen,pem_password_cb * cb,void * u)208f5b1c8a1SJohn Marino PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr,
209f5b1c8a1SJohn Marino     int klen, pem_password_cb *cb, void *u)
210f5b1c8a1SJohn Marino {
211f5b1c8a1SJohn Marino 	return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
212f5b1c8a1SJohn Marino }
213f5b1c8a1SJohn Marino 
214f5b1c8a1SJohn Marino int
PEM_write_PKCS8PrivateKey(FILE * fp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)215f5b1c8a1SJohn Marino PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
216f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
217f5b1c8a1SJohn Marino {
218f5b1c8a1SJohn Marino 	return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
219f5b1c8a1SJohn Marino }
220f5b1c8a1SJohn Marino 
221f5b1c8a1SJohn Marino static int
do_pk8pkey_fp(FILE * fp,EVP_PKEY * x,int isder,int nid,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)222f5b1c8a1SJohn Marino do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
223f5b1c8a1SJohn Marino     char *kstr, int klen, pem_password_cb *cb, void *u)
224f5b1c8a1SJohn Marino {
225f5b1c8a1SJohn Marino 	BIO *bp;
226f5b1c8a1SJohn Marino 	int ret;
227f5b1c8a1SJohn Marino 
228f5b1c8a1SJohn Marino 	if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
22972c33676SMaxim Ag 		PEMerror(ERR_R_BUF_LIB);
230f5b1c8a1SJohn Marino 		return (0);
231f5b1c8a1SJohn Marino 	}
232f5b1c8a1SJohn Marino 	ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
233f5b1c8a1SJohn Marino 	BIO_free(bp);
234f5b1c8a1SJohn Marino 	return ret;
235f5b1c8a1SJohn Marino }
236f5b1c8a1SJohn Marino 
237f5b1c8a1SJohn Marino EVP_PKEY *
d2i_PKCS8PrivateKey_fp(FILE * fp,EVP_PKEY ** x,pem_password_cb * cb,void * u)238f5b1c8a1SJohn Marino d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
239f5b1c8a1SJohn Marino {
240f5b1c8a1SJohn Marino 	BIO *bp;
241f5b1c8a1SJohn Marino 	EVP_PKEY *ret;
242f5b1c8a1SJohn Marino 
243f5b1c8a1SJohn Marino 	if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
24472c33676SMaxim Ag 		PEMerror(ERR_R_BUF_LIB);
245f5b1c8a1SJohn Marino 		return NULL;
246f5b1c8a1SJohn Marino 	}
247f5b1c8a1SJohn Marino 	ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
248f5b1c8a1SJohn Marino 	BIO_free(bp);
249f5b1c8a1SJohn Marino 	return ret;
250f5b1c8a1SJohn Marino }
251f5b1c8a1SJohn Marino 
25272c33676SMaxim Ag X509_SIG *
PEM_read_PKCS8(FILE * fp,X509_SIG ** x,pem_password_cb * cb,void * u)25372c33676SMaxim Ag PEM_read_PKCS8(FILE *fp, X509_SIG **x, pem_password_cb *cb, void *u)
25472c33676SMaxim Ag {
25572c33676SMaxim Ag 	return PEM_ASN1_read((d2i_of_void *)d2i_X509_SIG, PEM_STRING_PKCS8, fp,
25672c33676SMaxim Ag 	    (void **)x, cb, u);
25772c33676SMaxim Ag }
258f5b1c8a1SJohn Marino 
25972c33676SMaxim Ag int
PEM_write_PKCS8(FILE * fp,X509_SIG * x)26072c33676SMaxim Ag PEM_write_PKCS8(FILE *fp, X509_SIG *x)
26172c33676SMaxim Ag {
26272c33676SMaxim Ag 	return PEM_ASN1_write((i2d_of_void *)i2d_X509_SIG, PEM_STRING_PKCS8, fp,
26372c33676SMaxim Ag 	    x, NULL, NULL, 0, NULL, NULL);
26472c33676SMaxim Ag }
26572c33676SMaxim Ag 
26672c33676SMaxim Ag X509_SIG *
PEM_read_bio_PKCS8(BIO * bp,X509_SIG ** x,pem_password_cb * cb,void * u)26772c33676SMaxim Ag PEM_read_bio_PKCS8(BIO *bp, X509_SIG **x, pem_password_cb *cb, void *u)
26872c33676SMaxim Ag {
26972c33676SMaxim Ag 	return PEM_ASN1_read_bio((d2i_of_void *)d2i_X509_SIG, PEM_STRING_PKCS8, bp,
27072c33676SMaxim Ag 	    (void **)x, cb, u);
27172c33676SMaxim Ag }
27272c33676SMaxim Ag 
27372c33676SMaxim Ag int
PEM_write_bio_PKCS8(BIO * bp,X509_SIG * x)27472c33676SMaxim Ag PEM_write_bio_PKCS8(BIO *bp, X509_SIG *x)
27572c33676SMaxim Ag {
27672c33676SMaxim Ag 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_X509_SIG, PEM_STRING_PKCS8, bp,
27772c33676SMaxim Ag 	    x, NULL, NULL, 0, NULL, NULL);
27872c33676SMaxim Ag }
27972c33676SMaxim Ag 
28072c33676SMaxim Ag PKCS8_PRIV_KEY_INFO *
PEM_read_PKCS8_PRIV_KEY_INFO(FILE * fp,PKCS8_PRIV_KEY_INFO ** x,pem_password_cb * cb,void * u)28172c33676SMaxim Ag PEM_read_PKCS8_PRIV_KEY_INFO(FILE *fp, PKCS8_PRIV_KEY_INFO **x, pem_password_cb *cb, void *u)
28272c33676SMaxim Ag {
28372c33676SMaxim Ag 	return PEM_ASN1_read((d2i_of_void *)d2i_PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, fp,
28472c33676SMaxim Ag 	    (void **)x, cb, u);
28572c33676SMaxim Ag }
28672c33676SMaxim Ag 
28772c33676SMaxim Ag int
PEM_write_PKCS8_PRIV_KEY_INFO(FILE * fp,PKCS8_PRIV_KEY_INFO * x)28872c33676SMaxim Ag PEM_write_PKCS8_PRIV_KEY_INFO(FILE *fp, PKCS8_PRIV_KEY_INFO *x)
28972c33676SMaxim Ag {
29072c33676SMaxim Ag 	return PEM_ASN1_write((i2d_of_void *)i2d_PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, fp,
29172c33676SMaxim Ag 	    x, NULL, NULL, 0, NULL, NULL);
29272c33676SMaxim Ag }
29372c33676SMaxim Ag 
29472c33676SMaxim Ag PKCS8_PRIV_KEY_INFO *
PEM_read_bio_PKCS8_PRIV_KEY_INFO(BIO * bp,PKCS8_PRIV_KEY_INFO ** x,pem_password_cb * cb,void * u)29572c33676SMaxim Ag PEM_read_bio_PKCS8_PRIV_KEY_INFO(BIO *bp, PKCS8_PRIV_KEY_INFO **x, pem_password_cb *cb, void *u)
29672c33676SMaxim Ag {
29772c33676SMaxim Ag 	return PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, bp,
29872c33676SMaxim Ag 	    (void **)x, cb, u);
29972c33676SMaxim Ag }
30072c33676SMaxim Ag 
30172c33676SMaxim Ag int
PEM_write_bio_PKCS8_PRIV_KEY_INFO(BIO * bp,PKCS8_PRIV_KEY_INFO * x)30272c33676SMaxim Ag PEM_write_bio_PKCS8_PRIV_KEY_INFO(BIO *bp, PKCS8_PRIV_KEY_INFO *x)
30372c33676SMaxim Ag {
30472c33676SMaxim Ag 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, bp,
30572c33676SMaxim Ag 	    x, NULL, NULL, 0, NULL, NULL);
30672c33676SMaxim Ag }
307