This commit was generated by cvs2svn to track changes on a CVS vendor
[openssl.git] / crypto / pem / pem_all.c
1 /* crypto/pem/pem_all.c */
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.
8  * 
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).
15  * 
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.
22  * 
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 :-).
37  * 4. If you include any Windows specific code (or a derivative thereof) from 
38  *    the apps directory (application code) you must include an acknowledgement:
39  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40  * 
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.
52  * 
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
59 #include <stdio.h>
60 #undef SSLEAY_MACROS
61 #include "bio.h"
62 #include "evp.h"
63 #include "x509.h"
64 #include "pkcs7.h"
65 #include "pem.h"
66
67 #ifndef WIN16
68 /* The X509 functions */
69 X509 *PEM_read_X509(fp,x,cb)
70 FILE *fp;
71 X509 **x;
72 int (*cb)();
73         {
74         return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
75                 PEM_STRING_X509,fp,(char **)x,cb));
76         }
77 #endif
78
79 X509 *PEM_read_bio_X509(bp,x,cb)
80 BIO *bp;
81 X509 **x;
82 int (*cb)();
83         {
84         return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
85                 PEM_STRING_X509,bp,(char **)x,cb));
86         }
87
88 #ifndef WIN16
89 int PEM_write_X509(fp,x)
90 FILE *fp;
91 X509 *x;
92         {
93         return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
94                 (char *)x, NULL,NULL,0,NULL));
95         }
96 #endif
97
98 int PEM_write_bio_X509(bp,x)
99 BIO *bp;
100 X509 *x;
101         {
102         return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
103                 (char *)x, NULL,NULL,0,NULL));
104         }
105
106 #ifndef WIN16
107 /* The X509_REQ functions */
108 X509_REQ *PEM_read_X509_REQ(fp,x,cb)
109 FILE *fp;
110 X509_REQ **x;
111 int (*cb)();
112         {
113         return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
114                 PEM_STRING_X509_REQ,fp,(char **)x,cb));
115         }
116 #endif
117
118 X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb)
119 BIO *bp;
120 X509_REQ **x;
121 int (*cb)();
122         {
123         return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
124                 PEM_STRING_X509_REQ,bp,(char **)x,cb));
125         }
126
127 #ifndef WIN16
128 int PEM_write_X509_REQ(fp,x)
129 FILE *fp;
130 X509_REQ *x;
131         {
132         return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
133                 (char *)x, NULL,NULL,0,NULL));
134         }
135 #endif
136
137 int PEM_write_bio_X509_REQ(bp,x)
138 BIO *bp;
139 X509_REQ *x;
140         {
141         return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
142                 bp,(char *)x, NULL,NULL,0,NULL));
143         }
144
145 #ifndef WIN16
146 /* The X509_CRL functions */
147 X509_CRL *PEM_read_X509_CRL(fp,x,cb)
148 FILE *fp;
149 X509_CRL **x;
150 int (*cb)();
151         {
152         return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
153                 PEM_STRING_X509_CRL,fp,(char **)x,cb));
154         }
155 #endif
156
157 X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
158 BIO *bp;
159 X509_CRL **x;
160 int (*cb)();
161         {
162         return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
163                 PEM_STRING_X509_CRL,bp,(char **)x,cb));
164         }
165
166 #ifndef WIN16
167 int PEM_write_X509_CRL(fp,x)
168 FILE *fp;
169 X509_CRL *x;
170         {
171         return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
172                 (char *)x, NULL,NULL,0,NULL));
173         }
174 #endif
175
176 int PEM_write_bio_X509_CRL(bp,x)
177 BIO *bp;
178 X509_CRL *x;
179         {
180         return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
181                 bp,(char *)x, NULL,NULL,0,NULL));
182         }
183
184 #ifndef NO_RSA
185 #ifndef WIN16
186 /* The RSAPrivateKey functions */
187 RSA *PEM_read_RSAPrivateKey(fp,x,cb)
188 FILE *fp;
189 RSA **x;
190 int (*cb)();
191         {
192         return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
193                 PEM_STRING_RSA,fp,(char **)x,cb));
194         }
195
196 RSA *PEM_read_RSAPublicKey(fp,x,cb)
197 FILE *fp;
198 RSA **x;
199 int (*cb)();
200         {
201         return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
202                 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
203         }
204 #endif
205
206 RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb)
207 BIO *bp;
208 RSA **x;
209 int (*cb)();
210         {
211         return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
212                 PEM_STRING_RSA,bp,(char **)x,cb));
213         }
214
215 RSA *PEM_read_bio_RSAPublicKey(bp,x,cb)
216 BIO *bp;
217 RSA **x;
218 int (*cb)();
219         {
220         return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
221                 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
222         }
223
224 #ifndef WIN16
225 int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
226 FILE *fp;
227 RSA *x;
228 EVP_CIPHER *enc;
229 unsigned char *kstr;
230 int klen;
231 int (*cb)();
232         {
233         return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
234                 (char *)x,enc,kstr,klen,cb));
235         }
236
237 int PEM_write_RSAPublicKey(fp,x)
238 FILE *fp;
239 RSA *x;
240         {
241         return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
242                 PEM_STRING_RSA_PUBLIC,fp,
243                 (char *)x,NULL,NULL,0,NULL));
244         }
245 #endif
246
247 int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
248 BIO *bp;
249 RSA *x;
250 EVP_CIPHER *enc;
251 unsigned char *kstr;
252 int klen;
253 int (*cb)();
254         {
255         return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
256                 bp,(char *)x,enc,kstr,klen,cb));
257         }
258
259 int PEM_write_bio_RSAPublicKey(bp,x)
260 BIO *bp;
261 RSA *x;
262         {
263         return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
264                 PEM_STRING_RSA_PUBLIC,
265                 bp,(char *)x,NULL,NULL,0,NULL));
266         }
267 #endif /* !NO_RSA */
268
269 #ifndef NO_DSA
270 #ifndef WIN16
271 /* The DSAPrivateKey functions */
272 DSA *PEM_read_DSAPrivateKey(fp,x,cb)
273 FILE *fp;
274 DSA **x;
275 int (*cb)();
276         {
277         return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
278                 PEM_STRING_DSA,fp,(char **)x,cb));
279         }
280 #endif
281
282 DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
283 BIO *bp;
284 DSA **x;
285 int (*cb)();
286         {
287         return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
288                 PEM_STRING_DSA,bp,(char **)x,cb));
289         }
290
291 #ifndef WIN16
292 int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
293 FILE *fp;
294 DSA *x;
295 EVP_CIPHER *enc;
296 unsigned char *kstr;
297 int klen;
298 int (*cb)();
299         {
300         return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
301                 (char *)x,enc,kstr,klen,cb));
302         }
303 #endif
304
305 int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
306 BIO *bp;
307 DSA *x;
308 EVP_CIPHER *enc;
309 unsigned char *kstr;
310 int klen;
311 int (*cb)();
312         {
313         return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
314                 bp,(char *)x,enc,kstr,klen,cb));
315         }
316 #endif
317
318 #ifndef WIN16
319 /* The PrivateKey functions */
320 EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
321 FILE *fp;
322 EVP_PKEY **x;
323 int (*cb)();
324         {
325         return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
326                 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
327         }
328 #endif
329
330 EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
331 BIO *bp;
332 EVP_PKEY **x;
333 int (*cb)();
334         {
335         return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
336                 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
337         }
338
339 #ifndef WIN16
340 int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
341 FILE *fp;
342 EVP_PKEY *x;
343 EVP_CIPHER *enc;
344 unsigned char *kstr;
345 int klen;
346 int (*cb)();
347         {
348         return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
349                 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
350                 fp,(char *)x,enc,kstr,klen,cb));
351         }
352 #endif
353
354 int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb)
355 BIO *bp;
356 EVP_PKEY *x;
357 EVP_CIPHER *enc;
358 unsigned char *kstr;
359 int klen;
360 int (*cb)();
361         {
362         return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
363                 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
364                 bp,(char *)x,enc,kstr,klen,cb));
365         }
366
367 #ifndef WIN16
368 /* The PKCS7 functions */
369 PKCS7 *PEM_read_PKCS7(fp,x,cb)
370 FILE *fp;
371 PKCS7 **x;
372 int (*cb)();
373         {
374         return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
375                 PEM_STRING_PKCS7,fp,(char **)x,cb));
376         }
377 #endif
378
379 PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
380 BIO *bp;
381 PKCS7 **x;
382 int (*cb)();
383         {
384         return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
385                 PEM_STRING_PKCS7,bp,(char **)x,cb));
386         }
387
388 #ifndef WIN16
389 int PEM_write_PKCS7(fp,x)
390 FILE *fp;
391 PKCS7 *x;
392         {
393         return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
394                 (char *)x, NULL,NULL,0,NULL));
395         }
396 #endif
397
398 int PEM_write_bio_PKCS7(bp,x)
399 BIO *bp;
400 PKCS7 *x;
401         {
402         return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
403                 (char *)x, NULL,NULL,0,NULL));
404         }
405
406 #ifndef NO_DH
407 #ifndef WIN16
408 /* The DHparams functions */
409 DH *PEM_read_DHparams(fp,x,cb)
410 FILE *fp;
411 DH **x;
412 int (*cb)();
413         {
414         return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
415                 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
416         }
417 #endif
418
419 DH *PEM_read_bio_DHparams(bp,x,cb)
420 BIO *bp;
421 DH **x;
422 int (*cb)();
423         {
424         return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
425                 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
426         }
427
428 #ifndef WIN16
429 int PEM_write_DHparams(fp,x)
430 FILE *fp;
431 DH *x;
432         {
433         return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
434                 (char *)x, NULL,NULL,0,NULL));
435         }
436 #endif
437
438 int PEM_write_bio_DHparams(bp,x)
439 BIO *bp;
440 DH *x;
441         {
442         return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
443                 bp,(char *)x, NULL,NULL,0,NULL));
444         }
445 #endif
446
447 #ifndef NO_DSA
448 #ifndef WIN16
449 /* The DSAparams functions */
450 DSA *PEM_read_DSAparams(fp,x,cb)
451 FILE *fp;
452 DSA **x;
453 int (*cb)();
454         {
455         return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
456                 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
457         }
458 #endif
459
460 DSA *PEM_read_bio_DSAparams(bp,x,cb)
461 BIO *bp;
462 DSA **x;
463 int (*cb)();
464         {
465         return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
466                 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
467         }
468
469 #ifndef WIN16
470 int PEM_write_DSAparams(fp,x)
471 FILE *fp;
472 DSA *x;
473         {
474         return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
475                 (char *)x, NULL,NULL,0,NULL));
476         }
477 #endif
478
479 int PEM_write_bio_DSAparams(bp,x)
480 BIO *bp;
481 DSA *x;
482         {
483         return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
484                 bp,(char *)x, NULL,NULL,0,NULL));
485         }
486 #endif
487