• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young (eay@cryptsoft.com)"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #ifndef OPENSSL_HEADER_PEM_H
58 #define OPENSSL_HEADER_PEM_H
59 
60 #include <openssl/base64.h>
61 #include <openssl/bio.h>
62 #include <openssl/cipher.h>
63 #include <openssl/digest.h>
64 #include <openssl/evp.h>
65 #include <openssl/stack.h>
66 #include <openssl/x509.h>
67 
68 #ifdef  __cplusplus
69 extern "C" {
70 #endif
71 
72 
73 #define PEM_BUFSIZE		1024
74 
75 #define PEM_OBJ_UNDEF		0
76 #define PEM_OBJ_X509		1
77 #define PEM_OBJ_X509_REQ	2
78 #define PEM_OBJ_CRL		3
79 #define PEM_OBJ_SSL_SESSION	4
80 #define PEM_OBJ_PRIV_KEY	10
81 #define PEM_OBJ_PRIV_RSA	11
82 #define PEM_OBJ_PRIV_DSA	12
83 #define PEM_OBJ_PRIV_DH		13
84 #define PEM_OBJ_PUB_RSA		14
85 #define PEM_OBJ_PUB_DSA		15
86 #define PEM_OBJ_PUB_DH		16
87 #define PEM_OBJ_DHPARAMS	17
88 #define PEM_OBJ_DSAPARAMS	18
89 #define PEM_OBJ_PRIV_RSA_PUBLIC	19
90 #define PEM_OBJ_PRIV_ECDSA	20
91 #define PEM_OBJ_PUB_ECDSA	21
92 #define PEM_OBJ_ECPARAMETERS	22
93 
94 #define PEM_ERROR		30
95 #define PEM_DEK_DES_CBC         40
96 #define PEM_DEK_IDEA_CBC        45
97 #define PEM_DEK_DES_EDE         50
98 #define PEM_DEK_DES_ECB         60
99 #define PEM_DEK_RSA             70
100 #define PEM_DEK_RSA_MD2         80
101 #define PEM_DEK_RSA_MD5         90
102 
103 #define PEM_MD_MD2		NID_md2
104 #define PEM_MD_MD5		NID_md5
105 #define PEM_MD_SHA		NID_sha
106 #define PEM_MD_MD2_RSA		NID_md2WithRSAEncryption
107 #define PEM_MD_MD5_RSA		NID_md5WithRSAEncryption
108 #define PEM_MD_SHA_RSA		NID_sha1WithRSAEncryption
109 
110 #define PEM_STRING_X509_OLD	"X509 CERTIFICATE"
111 #define PEM_STRING_X509		"CERTIFICATE"
112 #define PEM_STRING_X509_PAIR	"CERTIFICATE PAIR"
113 #define PEM_STRING_X509_TRUSTED	"TRUSTED CERTIFICATE"
114 #define PEM_STRING_X509_REQ_OLD	"NEW CERTIFICATE REQUEST"
115 #define PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
116 #define PEM_STRING_X509_CRL	"X509 CRL"
117 #define PEM_STRING_EVP_PKEY	"ANY PRIVATE KEY"
118 #define PEM_STRING_PUBLIC	"PUBLIC KEY"
119 #define PEM_STRING_RSA		"RSA PRIVATE KEY"
120 #define PEM_STRING_RSA_PUBLIC	"RSA PUBLIC KEY"
121 #define PEM_STRING_DSA		"DSA PRIVATE KEY"
122 #define PEM_STRING_DSA_PUBLIC	"DSA PUBLIC KEY"
123 #define PEM_STRING_PKCS7	"PKCS7"
124 #define PEM_STRING_PKCS7_SIGNED	"PKCS #7 SIGNED DATA"
125 #define PEM_STRING_PKCS8	"ENCRYPTED PRIVATE KEY"
126 #define PEM_STRING_PKCS8INF	"PRIVATE KEY"
127 #define PEM_STRING_DHPARAMS	"DH PARAMETERS"
128 #define PEM_STRING_SSL_SESSION	"SSL SESSION PARAMETERS"
129 #define PEM_STRING_DSAPARAMS	"DSA PARAMETERS"
130 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
131 #define PEM_STRING_ECPRIVATEKEY	"EC PRIVATE KEY"
132 #define PEM_STRING_PARAMETERS	"PARAMETERS"
133 #define PEM_STRING_CMS		"CMS"
134 
135   /* Note that this structure is initialised by PEM_SealInit and cleaned up
136      by PEM_SealFinal (at least for now) */
137 typedef struct PEM_Encode_Seal_st
138 	{
139 	EVP_ENCODE_CTX encode;
140 	EVP_MD_CTX md;
141 	EVP_CIPHER_CTX cipher;
142 	} PEM_ENCODE_SEAL_CTX;
143 
144 /* enc_type is one off */
145 #define PEM_TYPE_ENCRYPTED      10
146 #define PEM_TYPE_MIC_ONLY       20
147 #define PEM_TYPE_MIC_CLEAR      30
148 #define PEM_TYPE_CLEAR		40
149 
150 typedef struct pem_recip_st
151 	{
152 	char *name;
153 	X509_NAME *dn;
154 
155 	int cipher;
156 	int key_enc;
157 	/*	char iv[8]; unused and wrong size */
158 	} PEM_USER;
159 
160 typedef struct pem_ctx_st
161 	{
162 	int type;		/* what type of object */
163 
164 	struct	{
165 		int version;
166 		int mode;
167 		} proc_type;
168 
169 	char *domain;
170 
171 	struct	{
172 		int cipher;
173 	/* unused, and wrong size
174 	   unsigned char iv[8]; */
175 		} DEK_info;
176 
177 	PEM_USER *originator;
178 
179 	int num_recipient;
180 	PEM_USER **recipient;
181 
182 	EVP_MD *md;		/* signature type */
183 
184 	int md_enc;		/* is the md encrypted or not? */
185 	int md_len;		/* length of md_data */
186 	char *md_data;		/* message digest, could be pkey encrypted */
187 
188 	EVP_CIPHER *dec;	/* date encryption cipher */
189 	int key_len;		/* key length */
190 	unsigned char *key;	/* key */
191 	/* unused, and wrong size
192 	   unsigned char iv[8]; */
193 
194 
195 	int  data_enc;		/* is the data encrypted */
196 	int data_len;
197 	unsigned char *data;
198 	} PEM_CTX;
199 
200 /* These macros make the PEM_read/PEM_write functions easier to maintain and
201  * write. Now they are all implemented with either:
202  * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
203  */
204 
205 #ifdef OPENSSL_NO_FP_API
206 
207 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
208 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
209 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
210 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
211 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
212 
213 #else
214 
215 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
216 OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
217 { \
218 return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
219 }
220 
221 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
222 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \
223 { \
224 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
225 }
226 
227 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
228 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \
229 { \
230 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
231 }
232 
233 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
234 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
235 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
236 		  void *u) \
237 	{ \
238 	return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
239 	}
240 
241 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
242 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
243 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
244 		  void *u) \
245 	{ \
246 	return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
247 	}
248 
249 #endif
250 
251 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
252 OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
253 { \
254 return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
255 }
256 
257 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
258 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \
259 { \
260 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
261 }
262 
263 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
264 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \
265 { \
266 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
267 }
268 
269 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
270 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
271 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
272 	{ \
273 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
274 	}
275 
276 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
277 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
278 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
279 	{ \
280 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
281 	}
282 
283 #define IMPLEMENT_PEM_write(name, type, str, asn1) \
284 	IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
285 	IMPLEMENT_PEM_write_fp(name, type, str, asn1)
286 
287 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
288 	IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
289 	IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
290 
291 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
292 	IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
293 	IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
294 
295 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
296 	IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
297 	IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
298 
299 #define IMPLEMENT_PEM_read(name, type, str, asn1) \
300 	IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
301 	IMPLEMENT_PEM_read_fp(name, type, str, asn1)
302 
303 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
304 	IMPLEMENT_PEM_read(name, type, str, asn1) \
305 	IMPLEMENT_PEM_write(name, type, str, asn1)
306 
307 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
308 	IMPLEMENT_PEM_read(name, type, str, asn1) \
309 	IMPLEMENT_PEM_write_const(name, type, str, asn1)
310 
311 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
312 	IMPLEMENT_PEM_read(name, type, str, asn1) \
313 	IMPLEMENT_PEM_write_cb(name, type, str, asn1)
314 
315 /* These are the same except they are for the declarations */
316 
317 #if defined(OPENSSL_NO_FP_API)
318 
319 #define DECLARE_PEM_read_fp(name, type) /**/
320 #define DECLARE_PEM_write_fp(name, type) /**/
321 #define DECLARE_PEM_write_cb_fp(name, type) /**/
322 
323 #else
324 
325 #define DECLARE_PEM_read_fp(name, type) \
326 	OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
327 
328 #define DECLARE_PEM_write_fp(name, type) \
329 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
330 
331 #define DECLARE_PEM_write_fp_const(name, type) \
332 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
333 
334 #define DECLARE_PEM_write_cb_fp(name, type) \
335 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
336 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
337 
338 #endif
339 
340 #define DECLARE_PEM_read_bio(name, type) \
341 	OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
342 
343 #define DECLARE_PEM_write_bio(name, type) \
344 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
345 
346 #define DECLARE_PEM_write_bio_const(name, type) \
347 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
348 
349 #define DECLARE_PEM_write_cb_bio(name, type) \
350 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
351 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
352 
353 
354 #define DECLARE_PEM_write(name, type) \
355 	DECLARE_PEM_write_bio(name, type) \
356 	DECLARE_PEM_write_fp(name, type)
357 
358 #define DECLARE_PEM_write_const(name, type) \
359 	DECLARE_PEM_write_bio_const(name, type) \
360 	DECLARE_PEM_write_fp_const(name, type)
361 
362 #define DECLARE_PEM_write_cb(name, type) \
363 	DECLARE_PEM_write_cb_bio(name, type) \
364 	DECLARE_PEM_write_cb_fp(name, type)
365 
366 #define DECLARE_PEM_read(name, type) \
367 	DECLARE_PEM_read_bio(name, type) \
368 	DECLARE_PEM_read_fp(name, type)
369 
370 #define DECLARE_PEM_rw(name, type) \
371 	DECLARE_PEM_read(name, type) \
372 	DECLARE_PEM_write(name, type)
373 
374 #define DECLARE_PEM_rw_const(name, type) \
375 	DECLARE_PEM_read(name, type) \
376 	DECLARE_PEM_write_const(name, type)
377 
378 #define DECLARE_PEM_rw_cb(name, type) \
379 	DECLARE_PEM_read(name, type) \
380 	DECLARE_PEM_write_cb(name, type)
381 
382 /* "userdata": new with OpenSSL 0.9.4 */
383 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
384 
385 OPENSSL_EXPORT int	PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
386 OPENSSL_EXPORT int	PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u);
387 
388 OPENSSL_EXPORT int	PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len);
389 OPENSSL_EXPORT int	PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
390 OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, pem_password_cb *cb, void *u);
391 OPENSSL_EXPORT void *	PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u);
392 OPENSSL_EXPORT int	PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, const EVP_CIPHER *enc,unsigned char *kstr,int klen, pem_password_cb *cb, void *u);
393 
394 OPENSSL_EXPORT STACK_OF(X509_INFO) *	PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
395 OPENSSL_EXPORT int	PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
396 
397 OPENSSL_EXPORT int	PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len);
398 OPENSSL_EXPORT int	PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len);
399 OPENSSL_EXPORT void *  PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u);
400 OPENSSL_EXPORT int	PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, void *x,const EVP_CIPHER *enc,unsigned char *kstr, int klen,pem_password_cb *callback, void *u);
401 OPENSSL_EXPORT STACK_OF(X509_INFO) *	PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
402 
403 OPENSSL_EXPORT int	PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
404 OPENSSL_EXPORT void	PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl);
405 OPENSSL_EXPORT int	PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv);
406 
407 OPENSSL_EXPORT void    PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
408 OPENSSL_EXPORT void    PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
409 OPENSSL_EXPORT int	PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey);
410 
411 /* PEM_def_callback treats |userdata| as a string and copies it into |buf|,
412  * assuming its |size| is sufficient. Returns the length of the string, or 0
413  * if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
414  * returned. Note that this is different from OpenSSL, which prompts for a
415  * password. */
416 OPENSSL_EXPORT int	PEM_def_callback(char *buf, int size, int rwflag, void *userdata);
417 OPENSSL_EXPORT void	PEM_proc_type(char *buf, int type);
418 OPENSSL_EXPORT void	PEM_dek_info(char *buf, const char *type, int len, char *str);
419 
420 
421 DECLARE_PEM_rw(X509, X509)
422 
423 DECLARE_PEM_rw(X509_AUX, X509)
424 
425 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
426 
427 DECLARE_PEM_rw(X509_REQ, X509_REQ)
428 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
429 
430 DECLARE_PEM_rw(X509_CRL, X509_CRL)
431 
432 /* DECLARE_PEM_rw(PKCS7, PKCS7) */
433 
434 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
435 
436 DECLARE_PEM_rw(PKCS8, X509_SIG)
437 
438 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
439 
440 DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
441 
442 DECLARE_PEM_rw_const(RSAPublicKey, RSA)
443 DECLARE_PEM_rw(RSA_PUBKEY, RSA)
444 
445 #ifndef OPENSSL_NO_DSA
446 
447 DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
448 
449 DECLARE_PEM_rw(DSA_PUBKEY, DSA)
450 
451 DECLARE_PEM_rw_const(DSAparams, DSA)
452 
453 #endif
454 
455 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
456 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
457 
458 
459 DECLARE_PEM_rw_const(DHparams, DH)
460 
461 
462 DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
463 
464 DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
465 
466 OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
467 OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *);
468 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
469 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
470 OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
471 
472 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
473 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
474 OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
475 
476 OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
477 
478 OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, char *kstr,int klen, pem_password_cb *cd, void *u);
479 
480 OPENSSL_EXPORT EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
481 OPENSSL_EXPORT int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x);
482 
483 
484 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
485 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
486 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
487 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in);
488 OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
489 OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
490 OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
491 OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u);
492 
493 
494 void ERR_load_PEM_strings(void);
495 
496 
497 #ifdef  __cplusplus
498 }
499 #endif
500 
501 #define PEM_R_BAD_BASE64_DECODE 100
502 #define PEM_R_BAD_DECRYPT 101
503 #define PEM_R_BAD_END_LINE 102
504 #define PEM_R_BAD_IV_CHARS 103
505 #define PEM_R_BAD_PASSWORD_READ 104
506 #define PEM_R_CIPHER_IS_NULL 105
507 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106
508 #define PEM_R_NOT_DEK_INFO 107
509 #define PEM_R_NOT_ENCRYPTED 108
510 #define PEM_R_NOT_PROC_TYPE 109
511 #define PEM_R_NO_START_LINE 110
512 #define PEM_R_READ_KEY 111
513 #define PEM_R_SHORT_HEADER 112
514 #define PEM_R_UNSUPPORTED_CIPHER 113
515 #define PEM_R_UNSUPPORTED_ENCRYPTION 114
516 
517 #endif  /* OPENSSL_HEADER_PEM_H */
518