1 /* crypto/pem/pem_all.c */
2 /* Copyright (C) 1995-1997 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.]
68 /* The X509 functions */
69 X509 *PEM_read_X509(fp,x,cb)
74 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
75 PEM_STRING_X509,fp,(char **)x,cb));
79 X509 *PEM_read_bio_X509(bp,x,cb)
84 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
85 PEM_STRING_X509,bp,(char **)x,cb));
89 int PEM_write_X509(fp,x)
93 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
94 (char *)x, NULL,NULL,0,NULL));
98 int PEM_write_bio_X509(bp,x)
102 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
103 (char *)x, NULL,NULL,0,NULL));
107 /* The X509_REQ functions */
108 X509_REQ *PEM_read_X509_REQ(fp,x,cb)
113 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
114 PEM_STRING_X509_REQ,fp,(char **)x,cb));
118 X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb)
123 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
124 PEM_STRING_X509_REQ,bp,(char **)x,cb));
128 int PEM_write_X509_REQ(fp,x)
132 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
133 (char *)x, NULL,NULL,0,NULL));
137 int PEM_write_bio_X509_REQ(bp,x)
141 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
142 bp,(char *)x, NULL,NULL,0,NULL));
146 /* The X509_CRL functions */
147 X509_CRL *PEM_read_X509_CRL(fp,x,cb)
152 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
153 PEM_STRING_X509_CRL,fp,(char **)x,cb));
157 X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
162 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
163 PEM_STRING_X509_CRL,bp,(char **)x,cb));
167 int PEM_write_X509_CRL(fp,x)
171 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
172 (char *)x, NULL,NULL,0,NULL));
176 int PEM_write_bio_X509_CRL(bp,x)
180 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
181 bp,(char *)x, NULL,NULL,0,NULL));
186 /* The RSAPrivateKey functions */
187 RSA *PEM_read_RSAPrivateKey(fp,x,cb)
192 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
193 PEM_STRING_RSA,fp,(char **)x,cb));
196 RSA *PEM_read_RSAPublicKey(fp,x,cb)
201 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
202 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
206 RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb)
211 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
212 PEM_STRING_RSA,bp,(char **)x,cb));
215 RSA *PEM_read_bio_RSAPublicKey(bp,x,cb)
220 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
221 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
225 int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
233 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
234 (char *)x,enc,kstr,klen,cb));
237 int PEM_write_RSAPublicKey(fp,x)
241 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
242 PEM_STRING_RSA_PUBLIC,fp,
243 (char *)x,NULL,NULL,0,NULL));
247 int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
255 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
256 bp,(char *)x,enc,kstr,klen,cb));
259 int PEM_write_bio_RSAPublicKey(bp,x)
263 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
264 PEM_STRING_RSA_PUBLIC,
265 bp,(char *)x,NULL,NULL,0,NULL));
271 /* The DSAPrivateKey functions */
272 DSA *PEM_read_DSAPrivateKey(fp,x,cb)
277 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
278 PEM_STRING_DSA,fp,(char **)x,cb));
282 DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
287 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
288 PEM_STRING_DSA,bp,(char **)x,cb));
292 int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
300 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
301 (char *)x,enc,kstr,klen,cb));
305 int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
313 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
314 bp,(char *)x,enc,kstr,klen,cb));
319 /* The PrivateKey functions */
320 EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
325 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
326 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
330 EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
335 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
336 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
340 int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
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));
354 int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb)
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));
368 /* The PKCS7 functions */
369 PKCS7 *PEM_read_PKCS7(fp,x,cb)
374 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
375 PEM_STRING_PKCS7,fp,(char **)x,cb));
379 PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
384 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
385 PEM_STRING_PKCS7,bp,(char **)x,cb));
389 int PEM_write_PKCS7(fp,x)
393 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
394 (char *)x, NULL,NULL,0,NULL));
398 int PEM_write_bio_PKCS7(bp,x)
402 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
403 (char *)x, NULL,NULL,0,NULL));
408 /* The DHparams functions */
409 DH *PEM_read_DHparams(fp,x,cb)
414 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
415 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
419 DH *PEM_read_bio_DHparams(bp,x,cb)
424 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
425 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
429 int PEM_write_DHparams(fp,x)
433 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
434 (char *)x, NULL,NULL,0,NULL));
438 int PEM_write_bio_DHparams(bp,x)
442 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
443 bp,(char *)x, NULL,NULL,0,NULL));
449 /* The DSAparams functions */
450 DSA *PEM_read_DSAparams(fp,x,cb)
455 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
456 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
460 DSA *PEM_read_bio_DSAparams(bp,x,cb)
465 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
466 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
470 int PEM_write_DSAparams(fp,x)
474 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
475 (char *)x, NULL,NULL,0,NULL));
479 int PEM_write_bio_DSAparams(bp,x)
483 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
484 bp,(char *)x, NULL,NULL,0,NULL));