1 /* crypto/pem/pem_all.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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)"
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
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.]
69 /* The X509 functions */
70 X509 *PEM_read_X509(fp,x,cb)
75 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
76 PEM_STRING_X509,fp,(char **)x,cb));
80 X509 *PEM_read_bio_X509(bp,x,cb)
85 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
86 PEM_STRING_X509,bp,(char **)x,cb));
90 int PEM_write_X509(fp,x)
94 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
95 (char *)x, NULL,NULL,0,NULL));
99 int PEM_write_bio_X509(bp,x)
103 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
104 (char *)x, NULL,NULL,0,NULL));
108 /* The X509_REQ functions */
109 X509_REQ *PEM_read_X509_REQ(fp,x,cb)
114 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
115 PEM_STRING_X509_REQ,fp,(char **)x,cb));
119 X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb)
124 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
125 PEM_STRING_X509_REQ,bp,(char **)x,cb));
129 int PEM_write_X509_REQ(fp,x)
133 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
134 (char *)x, NULL,NULL,0,NULL));
138 int PEM_write_bio_X509_REQ(bp,x)
142 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
143 bp,(char *)x, NULL,NULL,0,NULL));
147 /* The X509_CRL functions */
148 X509_CRL *PEM_read_X509_CRL(fp,x,cb)
153 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
154 PEM_STRING_X509_CRL,fp,(char **)x,cb));
158 X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
163 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
164 PEM_STRING_X509_CRL,bp,(char **)x,cb));
168 int PEM_write_X509_CRL(fp,x)
172 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
173 (char *)x, NULL,NULL,0,NULL));
177 int PEM_write_bio_X509_CRL(bp,x)
181 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
182 bp,(char *)x, NULL,NULL,0,NULL));
187 /* The RSAPrivateKey functions */
188 RSA *PEM_read_RSAPrivateKey(fp,x,cb)
193 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
194 PEM_STRING_RSA,fp,(char **)x,cb));
197 RSA *PEM_read_RSAPublicKey(fp,x,cb)
202 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
203 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
207 RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb)
212 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
213 PEM_STRING_RSA,bp,(char **)x,cb));
216 RSA *PEM_read_bio_RSAPublicKey(bp,x,cb)
221 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
222 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
226 int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
234 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
235 (char *)x,enc,kstr,klen,cb));
238 int PEM_write_RSAPublicKey(fp,x)
242 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
243 PEM_STRING_RSA_PUBLIC,fp,
244 (char *)x,NULL,NULL,0,NULL));
248 int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
256 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
257 bp,(char *)x,enc,kstr,klen,cb));
260 int PEM_write_bio_RSAPublicKey(bp,x)
264 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
265 PEM_STRING_RSA_PUBLIC,
266 bp,(char *)x,NULL,NULL,0,NULL));
272 /* The DSAPrivateKey functions */
273 DSA *PEM_read_DSAPrivateKey(fp,x,cb)
278 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
279 PEM_STRING_DSA,fp,(char **)x,cb));
283 DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
288 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
289 PEM_STRING_DSA,bp,(char **)x,cb));
293 int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
301 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
302 (char *)x,enc,kstr,klen,cb));
306 int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
314 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
315 bp,(char *)x,enc,kstr,klen,cb));
320 /* The PrivateKey functions */
321 EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
326 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
327 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
331 EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
336 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
337 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
341 int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
349 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
350 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
351 fp,(char *)x,enc,kstr,klen,cb));
355 int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb)
363 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
364 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
365 bp,(char *)x,enc,kstr,klen,cb));
369 /* The PKCS7 functions */
370 PKCS7 *PEM_read_PKCS7(fp,x,cb)
375 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
376 PEM_STRING_PKCS7,fp,(char **)x,cb));
380 PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
385 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
386 PEM_STRING_PKCS7,bp,(char **)x,cb));
390 int PEM_write_PKCS7(fp,x)
394 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
395 (char *)x, NULL,NULL,0,NULL));
399 int PEM_write_bio_PKCS7(bp,x)
403 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
404 (char *)x, NULL,NULL,0,NULL));
409 /* The DHparams functions */
410 DH *PEM_read_DHparams(fp,x,cb)
415 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
416 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
420 DH *PEM_read_bio_DHparams(bp,x,cb)
425 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
426 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
430 int PEM_write_DHparams(fp,x)
434 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
435 (char *)x, NULL,NULL,0,NULL));
439 int PEM_write_bio_DHparams(bp,x)
443 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
444 bp,(char *)x, NULL,NULL,0,NULL));
450 /* The DSAparams functions */
451 DSA *PEM_read_DSAparams(fp,x,cb)
456 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
457 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
461 DSA *PEM_read_bio_DSAparams(bp,x,cb)
466 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
467 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
471 int PEM_write_DSAparams(fp,x)
475 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
476 (char *)x, NULL,NULL,0,NULL));
480 int PEM_write_bio_DSAparams(bp,x)
484 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
485 bp,(char *)x, NULL,NULL,0,NULL));
489 /* The Netscape Certificate sequence functions */
492 NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb)
494 NETSCAPE_CERT_SEQUENCE **x;
497 return((NETSCAPE_CERT_SEQUENCE *)
498 PEM_ASN1_read((char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,
499 PEM_STRING_X509,fp,(char **)x,cb));
503 NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb)
505 NETSCAPE_CERT_SEQUENCE **x;
508 return((NETSCAPE_CERT_SEQUENCE *)
509 PEM_ASN1_read_bio((char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,
510 PEM_STRING_X509,bp,(char **)x,cb));
514 int PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x)
516 NETSCAPE_CERT_SEQUENCE *x;
518 return(PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE,
519 PEM_STRING_X509,fp, (char *)x, NULL,NULL,0,NULL));
523 int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x)
525 NETSCAPE_CERT_SEQUENCE *x;
527 return(PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE,
528 PEM_STRING_X509,bp, (char *)x, NULL,NULL,0,NULL));