]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/pem.h
Fix no-stdio build
[thirdparty/openssl.git] / include / openssl / pem.h
CommitLineData
169cc7a1 1/* crypto/pem/pem.h */
d02b48c6
RE
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
0f113f3e 8 *
d02b48c6
RE
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
0f113f3e 15 *
d02b48c6
RE
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
0f113f3e 22 *
d02b48c6
RE
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
0f113f3e 37 * 4. If you include any Windows specific code (or a derivative thereof) from
d02b48c6
RE
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
0f113f3e 40 *
d02b48c6
RE
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
0f113f3e 52 *
d02b48c6
RE
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
d02b48c6 59#ifndef HEADER_PEM_H
0f113f3e
MC
60# define HEADER_PEM_H
61
62# include <openssl/e_os2.h>
a00ae6c4
RS
63# include <openssl/bio.h>
64# include <openssl/stack.h>
0f113f3e
MC
65# include <openssl/evp.h>
66# include <openssl/x509.h>
67# include <openssl/pem2.h>
d02b48c6 68
82271cee
RL
69#ifdef __cplusplus
70extern "C" {
71#endif
72
0f113f3e
MC
73# define PEM_BUFSIZE 1024
74
0f113f3e
MC
75# define PEM_STRING_X509_OLD "X509 CERTIFICATE"
76# define PEM_STRING_X509 "CERTIFICATE"
0f113f3e
MC
77# define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
78# define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
79# define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
80# define PEM_STRING_X509_CRL "X509 CRL"
81# define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
82# define PEM_STRING_PUBLIC "PUBLIC KEY"
83# define PEM_STRING_RSA "RSA PRIVATE KEY"
84# define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
85# define PEM_STRING_DSA "DSA PRIVATE KEY"
86# define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
87# define PEM_STRING_PKCS7 "PKCS7"
88# define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
89# define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
90# define PEM_STRING_PKCS8INF "PRIVATE KEY"
91# define PEM_STRING_DHPARAMS "DH PARAMETERS"
92# define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS"
93# define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
94# define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
95# define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
96# define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
97# define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
98# define PEM_STRING_PARAMETERS "PARAMETERS"
99# define PEM_STRING_CMS "CMS"
100
101 /*
102 * Note that this structure is initialised by PEM_SealInit and cleaned up
103 * by PEM_SealFinal (at least for now)
104 */
105typedef struct PEM_Encode_Seal_st {
106 EVP_ENCODE_CTX encode;
107 EVP_MD_CTX md;
108 EVP_CIPHER_CTX cipher;
109} PEM_ENCODE_SEAL_CTX;
d02b48c6 110
0f113f3e
MC
111# define PEM_TYPE_ENCRYPTED 10
112# define PEM_TYPE_MIC_ONLY 20
113# define PEM_TYPE_MIC_CLEAR 30
114# define PEM_TYPE_CLEAR 40
115
116typedef struct pem_recip_st {
117 char *name;
118 X509_NAME *dn;
119 int cipher;
120 int key_enc;
121 /* char iv[8]; unused and wrong size */
122} PEM_USER;
123
124typedef struct pem_ctx_st {
125 int type; /* what type of object */
126 struct {
127 int version;
128 int mode;
129 } proc_type;
130
131 char *domain;
132
133 struct {
134 int cipher;
135 /*-
35a1cc90
MC
136 unused, and wrong size
137 unsigned char iv[8]; */
0f113f3e
MC
138 } DEK_info;
139
140 PEM_USER *originator;
141
142 int num_recipient;
143 PEM_USER **recipient;
144
50e735f9
MC
145/*-
146 XXX(ben): don#t think this is used!
147 STACK *x509_chain; / * certificate chain */
0f113f3e
MC
148 EVP_MD *md; /* signature type */
149
150 int md_enc; /* is the md encrypted or not? */
151 int md_len; /* length of md_data */
152 char *md_data; /* message digest, could be pkey encrypted */
153
154 EVP_CIPHER *dec; /* date encryption cipher */
155 int key_len; /* key length */
156 unsigned char *key; /* key */
35a1cc90
MC
157 /*-
158 unused, and wrong size
159 unsigned char iv[8]; */
0f113f3e
MC
160
161 int data_enc; /* is the data encrypted */
162 int data_len;
163 unsigned char *data;
164} PEM_CTX;
165
166/*
167 * These macros make the PEM_read/PEM_write functions easier to maintain and
168 * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or
169 * IMPLEMENT_PEM_rw_cb(...)
f62676b9
DSH
170 */
171
0f113f3e 172# ifdef OPENSSL_NO_STDIO
f62676b9 173
0f113f3e
MC
174# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
175# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
176# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
177# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
178# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
179# else
f62676b9 180
0f113f3e 181# define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
74678cc2 182type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
f62676b9 183{ \
297e6f19 184return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
0f113f3e 185}
f62676b9 186
0f113f3e 187# define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
f62676b9
DSH
188int PEM_write_##name(FILE *fp, type *x) \
189{ \
297e6f19 190return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
41a15c4f
BL
191}
192
0f113f3e 193# define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
67ffa18c 194int PEM_write_##name(FILE *fp, const type *x) \
41a15c4f 195{ \
297e6f19 196return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
a2400fca 197}
f62676b9 198
0f113f3e 199# define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
f62676b9 200int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
0f113f3e
MC
201 unsigned char *kstr, int klen, pem_password_cb *cb, \
202 void *u) \
203 { \
204 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
205 }
41a15c4f 206
0f113f3e 207# define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
41a15c4f 208int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
0f113f3e
MC
209 unsigned char *kstr, int klen, pem_password_cb *cb, \
210 void *u) \
211 { \
212 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
213 }
f62676b9 214
0f113f3e 215# endif
f62676b9 216
0f113f3e 217# define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
74678cc2 218type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
f62676b9 219{ \
297e6f19 220return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
f62676b9
DSH
221}
222
0f113f3e 223# define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
f62676b9
DSH
224int PEM_write_bio_##name(BIO *bp, type *x) \
225{ \
297e6f19 226return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
41a15c4f
BL
227}
228
0f113f3e 229# define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
67ffa18c 230int PEM_write_bio_##name(BIO *bp, const type *x) \
41a15c4f 231{ \
297e6f19 232return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
f62676b9
DSH
233}
234
0f113f3e 235# define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
f62676b9 236int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
0f113f3e
MC
237 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
238 { \
239 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
240 }
41a15c4f 241
0f113f3e 242# define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
41a15c4f 243int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
0f113f3e
MC
244 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
245 { \
246 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
247 }
f62676b9 248
0f113f3e
MC
249# define IMPLEMENT_PEM_write(name, type, str, asn1) \
250 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
251 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
f62676b9 252
0f113f3e
MC
253# define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
254 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
255 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
41a15c4f 256
0f113f3e
MC
257# define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
258 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
259 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
f62676b9 260
0f113f3e
MC
261# define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
262 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
263 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
41a15c4f 264
0f113f3e
MC
265# define IMPLEMENT_PEM_read(name, type, str, asn1) \
266 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
267 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
f62676b9 268
0f113f3e
MC
269# define IMPLEMENT_PEM_rw(name, type, str, asn1) \
270 IMPLEMENT_PEM_read(name, type, str, asn1) \
271 IMPLEMENT_PEM_write(name, type, str, asn1)
f62676b9 272
0f113f3e
MC
273# define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
274 IMPLEMENT_PEM_read(name, type, str, asn1) \
275 IMPLEMENT_PEM_write_const(name, type, str, asn1)
41a15c4f 276
0f113f3e
MC
277# define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
278 IMPLEMENT_PEM_read(name, type, str, asn1) \
279 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
f62676b9 280
dbd665c2
DSH
281/* These are the same except they are for the declarations */
282
0f113f3e
MC
283# if defined(OPENSSL_NO_STDIO)
284
285# define DECLARE_PEM_read_fp(name, type) /**/
286# define DECLARE_PEM_write_fp(name, type) /**/
984d6c60 287# define DECLARE_PEM_write_fp_const(name, type) /**/
0f113f3e
MC
288# define DECLARE_PEM_write_cb_fp(name, type) /**/
289# else
290
291# define DECLARE_PEM_read_fp(name, type) \
292 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
293
294# define DECLARE_PEM_write_fp(name, type) \
295 int PEM_write_##name(FILE *fp, type *x);
296
297# define DECLARE_PEM_write_fp_const(name, type) \
298 int PEM_write_##name(FILE *fp, const type *x);
299
300# define DECLARE_PEM_write_cb_fp(name, type) \
301 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
302 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
303
304# endif
305
0f113f3e
MC
306# define DECLARE_PEM_read_bio(name, type) \
307 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
308
309# define DECLARE_PEM_write_bio(name, type) \
310 int PEM_write_bio_##name(BIO *bp, type *x);
311
312# define DECLARE_PEM_write_bio_const(name, type) \
313 int PEM_write_bio_##name(BIO *bp, const type *x);
314
315# define DECLARE_PEM_write_cb_bio(name, type) \
316 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
317 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
318
0f113f3e
MC
319# define DECLARE_PEM_write(name, type) \
320 DECLARE_PEM_write_bio(name, type) \
321 DECLARE_PEM_write_fp(name, type)
322# define DECLARE_PEM_write_const(name, type) \
323 DECLARE_PEM_write_bio_const(name, type) \
324 DECLARE_PEM_write_fp_const(name, type)
325# define DECLARE_PEM_write_cb(name, type) \
326 DECLARE_PEM_write_cb_bio(name, type) \
327 DECLARE_PEM_write_cb_fp(name, type)
328# define DECLARE_PEM_read(name, type) \
329 DECLARE_PEM_read_bio(name, type) \
330 DECLARE_PEM_read_fp(name, type)
331# define DECLARE_PEM_rw(name, type) \
332 DECLARE_PEM_read(name, type) \
333 DECLARE_PEM_write(name, type)
334# define DECLARE_PEM_rw_const(name, type) \
335 DECLARE_PEM_read(name, type) \
336 DECLARE_PEM_write_const(name, type)
337# define DECLARE_PEM_rw_cb(name, type) \
338 DECLARE_PEM_read(name, type) \
339 DECLARE_PEM_write_cb(name, type)
0f113f3e 340typedef int pem_password_cb (char *buf, int size, int rwflag, void *userdata);
0f113f3e
MC
341
342int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
343int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len,
344 pem_password_cb *callback, void *u);
345
0f113f3e
MC
346int PEM_read_bio(BIO *bp, char **name, char **header,
347 unsigned char **data, long *len);
348int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
349 const unsigned char *data, long len);
350int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
351 const char *name, BIO *bp, pem_password_cb *cb,
352 void *u);
353void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
354 pem_password_cb *cb, void *u);
355int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
356 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
357 pem_password_cb *cb, void *u);
358
359STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
360 pem_password_cb *cb, void *u);
361int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
362 unsigned char *kstr, int klen,
363 pem_password_cb *cd, void *u);
0f113f3e 364
984d6c60 365#ifndef OPENSSL_NO_STDIO
0f113f3e
MC
366int PEM_read(FILE *fp, char **name, char **header,
367 unsigned char **data, long *len);
368int PEM_write(FILE *fp, const char *name, const char *hdr,
369 const unsigned char *data, long len);
370void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
371 pem_password_cb *cb, void *u);
372int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
373 void *x, const EVP_CIPHER *enc, unsigned char *kstr,
374 int klen, pem_password_cb *callback, void *u);
375STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
376 pem_password_cb *cb, void *u);
984d6c60 377#endif
0f113f3e
MC
378
379int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
380 EVP_MD *md_type, unsigned char **ek, int *ekl,
381 unsigned char *iv, EVP_PKEY **pubk, int npubk);
382int PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
383 unsigned char *in, int inl);
384int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
385 unsigned char *out, int *outl, EVP_PKEY *priv);
386
387int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
388int PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt);
389int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
390 unsigned int *siglen, EVP_PKEY *pkey);
391
392int PEM_def_callback(char *buf, int num, int w, void *key);
393void PEM_proc_type(char *buf, int type);
394void PEM_dek_info(char *buf, const char *type, int len, char *str);
395
396# include <openssl/symhacks.h>
8c197cc5 397
dbd665c2 398DECLARE_PEM_rw(X509, X509)
ce1b4fe1 399DECLARE_PEM_rw(X509_AUX, X509)
a8fe430a
MC
400DECLARE_PEM_rw(X509_REQ, X509_REQ)
401DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
dbd665c2 402DECLARE_PEM_rw(X509_CRL, X509_CRL)
dbd665c2 403DECLARE_PEM_rw(PKCS7, PKCS7)
dbd665c2 404DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
dbd665c2 405DECLARE_PEM_rw(PKCS8, X509_SIG)
dbd665c2 406DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
0f113f3e 407# ifndef OPENSSL_NO_RSA
dbd665c2 408DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
a8fe430a
MC
409DECLARE_PEM_rw_const(RSAPublicKey, RSA)
410DECLARE_PEM_rw(RSA_PUBKEY, RSA)
0f113f3e
MC
411# endif
412# ifndef OPENSSL_NO_DSA
dbd665c2 413DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
a8fe430a
MC
414DECLARE_PEM_rw(DSA_PUBKEY, DSA)
415DECLARE_PEM_rw_const(DSAparams, DSA)
0f113f3e
MC
416# endif
417# ifndef OPENSSL_NO_EC
67ffa18c 418DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)
a8fe430a
MC
419DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
420DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
0f113f3e
MC
421# endif
422# ifndef OPENSSL_NO_DH
a8fe430a
MC
423DECLARE_PEM_rw_const(DHparams, DH)
424DECLARE_PEM_write_const(DHxparams, DH)
0f113f3e 425# endif
a8fe430a
MC
426DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
427DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
52664f50 428
525f51f6 429int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
0f113f3e
MC
430 char *kstr, int klen,
431 pem_password_cb *cb, void *u);
1d5edd08
RE
432int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
433 char *, int, pem_password_cb *, void *);
525f51f6 434int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
0f113f3e
MC
435 char *kstr, int klen,
436 pem_password_cb *cb, void *u);
525f51f6 437int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
0f113f3e
MC
438 char *kstr, int klen,
439 pem_password_cb *cb, void *u);
440EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
441 void *u);
525f51f6 442
984d6c60 443#ifndef OPENSSL_NO_STDIO
525f51f6 444int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
0f113f3e
MC
445 char *kstr, int klen,
446 pem_password_cb *cb, void *u);
525f51f6 447int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
0f113f3e
MC
448 char *kstr, int klen,
449 pem_password_cb *cb, void *u);
525f51f6 450int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
0f113f3e
MC
451 char *kstr, int klen,
452 pem_password_cb *cb, void *u);
525f51f6 453
0f113f3e
MC
454EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
455 void *u);
525f51f6 456
0f113f3e
MC
457int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
458 char *kstr, int klen, pem_password_cb *cd,
459 void *u);
984d6c60 460#endif
3e4585c8
DSH
461EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
462int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x);
463
a0156a92
DSH
464EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
465EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
466EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
467EVP_PKEY *b2i_PublicKey_bio(BIO *in);
468int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
469int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
0f113f3e 470# ifndef OPENSSL_NO_RC4
a0156a92
DSH
471EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
472int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
0f113f3e
MC
473 pem_password_cb *cb, void *u);
474# endif
a0156a92 475
d02b48c6 476/* BEGIN ERROR CODES */
0f113f3e
MC
477/*
478 * The following lines are auto generated by the script mkerr.pl. Any changes
6d311938
DSH
479 * made after this point may be overwritten when the script is next run.
480 */
b476df64 481void ERR_load_PEM_strings(void);
6d311938 482
d02b48c6
RE
483/* Error codes for the PEM functions. */
484
485/* Function codes. */
0f113f3e
MC
486# define PEM_F_B2I_DSS 127
487# define PEM_F_B2I_PVK_BIO 128
488# define PEM_F_B2I_RSA 129
489# define PEM_F_CHECK_BITLEN_DSA 130
490# define PEM_F_CHECK_BITLEN_RSA 131
491# define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
492# define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
493# define PEM_F_DO_B2I 132
494# define PEM_F_DO_B2I_BIO 133
495# define PEM_F_DO_BLOB_HEADER 134
496# define PEM_F_DO_PK8PKEY 126
497# define PEM_F_DO_PK8PKEY_FP 125
498# define PEM_F_DO_PVK_BODY 135
499# define PEM_F_DO_PVK_HEADER 136
500# define PEM_F_I2B_PVK 137
501# define PEM_F_I2B_PVK_BIO 138
502# define PEM_F_LOAD_IV 101
503# define PEM_F_PEM_ASN1_READ 102
504# define PEM_F_PEM_ASN1_READ_BIO 103
505# define PEM_F_PEM_ASN1_WRITE 104
506# define PEM_F_PEM_ASN1_WRITE_BIO 105
507# define PEM_F_PEM_DEF_CALLBACK 100
508# define PEM_F_PEM_DO_HEADER 106
509# define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
510# define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
511# define PEM_F_PEM_PK8PKEY 119
512# define PEM_F_PEM_READ 108
513# define PEM_F_PEM_READ_BIO 109
514# define PEM_F_PEM_READ_BIO_DHPARAMS 141
515# define PEM_F_PEM_READ_BIO_PARAMETERS 140
516# define PEM_F_PEM_READ_BIO_PRIVATEKEY 123
517# define PEM_F_PEM_READ_DHPARAMS 142
518# define PEM_F_PEM_READ_PRIVATEKEY 124
519# define PEM_F_PEM_SEALFINAL 110
520# define PEM_F_PEM_SEALINIT 111
521# define PEM_F_PEM_SIGNFINAL 112
522# define PEM_F_PEM_WRITE 113
523# define PEM_F_PEM_WRITE_BIO 114
524# define PEM_F_PEM_WRITE_PRIVATEKEY 139
525# define PEM_F_PEM_X509_INFO_READ 115
526# define PEM_F_PEM_X509_INFO_READ_BIO 116
527# define PEM_F_PEM_X509_INFO_WRITE_BIO 117
d02b48c6
RE
528
529/* Reason codes. */
0f113f3e
MC
530# define PEM_R_BAD_BASE64_DECODE 100
531# define PEM_R_BAD_DECRYPT 101
532# define PEM_R_BAD_END_LINE 102
533# define PEM_R_BAD_IV_CHARS 103
534# define PEM_R_BAD_MAGIC_NUMBER 116
535# define PEM_R_BAD_PASSWORD_READ 104
536# define PEM_R_BAD_VERSION_NUMBER 117
537# define PEM_R_BIO_WRITE_FAILURE 118
538# define PEM_R_CIPHER_IS_NULL 127
539# define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
540# define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119
541# define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120
542# define PEM_R_INCONSISTENT_HEADER 121
543# define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122
544# define PEM_R_KEYBLOB_TOO_SHORT 123
545# define PEM_R_NOT_DEK_INFO 105
546# define PEM_R_NOT_ENCRYPTED 106
547# define PEM_R_NOT_PROC_TYPE 107
548# define PEM_R_NO_START_LINE 108
549# define PEM_R_PROBLEMS_GETTING_PASSWORD 109
550# define PEM_R_PUBLIC_KEY_NO_RSA 110
551# define PEM_R_PVK_DATA_TOO_SHORT 124
552# define PEM_R_PVK_TOO_SHORT 125
553# define PEM_R_READ_KEY 111
554# define PEM_R_SHORT_HEADER 112
555# define PEM_R_UNSUPPORTED_CIPHER 113
556# define PEM_R_UNSUPPORTED_ENCRYPTION 114
557# define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126
6d311938 558
d02b48c6
RE
559#ifdef __cplusplus
560}
561#endif
562#endif