1 /* crypto/x509/x_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.]
72 return(ASN1_verify((int (*)())i2d_X509_CINF
,a
->sig_alg
,
73 a
->signature
,(char *)a
->cert_info
,r
));
76 int X509_REQ_verify(a
,r
)
80 return( ASN1_verify((int (*)())i2d_X509_REQ_INFO
,
81 a
->sig_alg
,a
->signature
,(char *)a
->req_info
,r
));
84 int X509_CRL_verify(a
,r
)
88 return(ASN1_verify((int (*)())i2d_X509_CRL_INFO
,
89 a
->sig_alg
, a
->signature
,(char *)a
->crl
,r
));
92 int NETSCAPE_SPKI_verify(a
,r
)
96 return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC
,
97 a
->sig_algor
,a
->signature
, (char *)a
->spkac
,r
));
100 int X509_sign(x
,pkey
,md
)
105 return(ASN1_sign((int (*)())i2d_X509_CINF
, x
->cert_info
->signature
,
106 x
->sig_alg
, x
->signature
, (char *)x
->cert_info
,pkey
,md
));
109 int X509_REQ_sign(x
,pkey
,md
)
114 return(ASN1_sign((int (*)())i2d_X509_REQ_INFO
,x
->sig_alg
, NULL
,
115 x
->signature
, (char *)x
->req_info
,pkey
,md
));
118 int X509_CRL_sign(x
,pkey
,md
)
123 return(ASN1_sign((int (*)())i2d_X509_CRL_INFO
,x
->crl
->sig_alg
,
124 x
->sig_alg
, x
->signature
, (char *)x
->crl
,pkey
,md
));
127 int NETSCAPE_SPKI_sign(x
,pkey
,md
)
132 return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC
, x
->sig_algor
,NULL
,
133 x
->signature
, (char *)x
->spkac
,pkey
,md
));
139 return((X509
*)ASN1_dup((int (*)())i2d_X509
,
140 (char *(*)())d2i_X509
,(char *)x509
));
143 X509_EXTENSION
*X509_EXTENSION_dup(ex
)
146 return((X509_EXTENSION
*)ASN1_dup(
147 (int (*)())i2d_X509_EXTENSION
,
148 (char *(*)())d2i_X509_EXTENSION
,(char *)ex
));
152 X509
*d2i_X509_fp(fp
,x509
)
156 return((X509
*)ASN1_d2i_fp((char *(*)())X509_new
,
157 (char *(*)())d2i_X509
, (fp
),(unsigned char **)(x509
)));
160 int i2d_X509_fp(fp
,x509
)
164 return(ASN1_i2d_fp(i2d_X509
,fp
,(unsigned char *)x509
));
168 X509
*d2i_X509_bio(bp
,x509
)
172 return((X509
*)ASN1_d2i_bio((char *(*)())X509_new
,
173 (char *(*)())d2i_X509
, (bp
),(unsigned char **)(x509
)));
176 int i2d_X509_bio(bp
,x509
)
180 return(ASN1_i2d_bio(i2d_X509
,bp
,(unsigned char *)x509
));
183 X509_CRL
*X509_CRL_dup(crl
)
186 return((X509_CRL
*)ASN1_dup((int (*)())i2d_X509_CRL
,
187 (char *(*)())d2i_X509_CRL
,(char *)crl
));
191 X509_CRL
*d2i_X509_CRL_fp(fp
,crl
)
195 return((X509_CRL
*)ASN1_d2i_fp((char *(*)())
196 X509_CRL_new
,(char *(*)())d2i_X509_CRL
, (fp
),
197 (unsigned char **)(crl
)));
200 int i2d_X509_CRL_fp(fp
,crl
)
204 return(ASN1_i2d_fp(i2d_X509_CRL
,fp
,(unsigned char *)crl
));
208 X509_CRL
*d2i_X509_CRL_bio(bp
,crl
)
212 return((X509_CRL
*)ASN1_d2i_bio((char *(*)())
213 X509_CRL_new
,(char *(*)())d2i_X509_CRL
, (bp
),
214 (unsigned char **)(crl
)));
217 int i2d_X509_CRL_bio(bp
,crl
)
221 return(ASN1_i2d_bio(i2d_X509_CRL
,bp
,(unsigned char *)crl
));
227 return((PKCS7
*)ASN1_dup((int (*)())i2d_PKCS7
,
228 (char *(*)())d2i_PKCS7
,(char *)p7
));
232 PKCS7
*d2i_PKCS7_fp(fp
,p7
)
236 return((PKCS7
*)ASN1_d2i_fp((char *(*)())
237 PKCS7_new
,(char *(*)())d2i_PKCS7
, (fp
),
238 (unsigned char **)(p7
)));
241 int i2d_PKCS7_fp(fp
,p7
)
245 return(ASN1_i2d_fp(i2d_PKCS7
,fp
,(unsigned char *)p7
));
249 PKCS7
*d2i_PKCS7_bio(bp
,p7
)
253 return((PKCS7
*)ASN1_d2i_bio((char *(*)())
254 PKCS7_new
,(char *(*)())d2i_PKCS7
, (bp
),
255 (unsigned char **)(p7
)));
258 int i2d_PKCS7_bio(bp
,p7
)
262 return(ASN1_i2d_bio(i2d_PKCS7
,bp
,(unsigned char *)p7
));
265 X509_REQ
*X509_REQ_dup(req
)
268 return((X509_REQ
*)ASN1_dup((int (*)())i2d_X509_REQ
,
269 (char *(*)())d2i_X509_REQ
,(char *)req
));
273 X509_REQ
*d2i_X509_REQ_fp(fp
,req
)
277 return((X509_REQ
*)ASN1_d2i_fp((char *(*)())
278 X509_REQ_new
, (char *(*)())d2i_X509_REQ
, (fp
),
279 (unsigned char **)(req
)));
282 int i2d_X509_REQ_fp(fp
,req
)
286 return(ASN1_i2d_fp(i2d_X509_REQ
,fp
,(unsigned char *)req
));
290 X509_REQ
*d2i_X509_REQ_bio(bp
,req
)
294 return((X509_REQ
*)ASN1_d2i_bio((char *(*)())
295 X509_REQ_new
, (char *(*)())d2i_X509_REQ
, (bp
),
296 (unsigned char **)(req
)));
299 int i2d_X509_REQ_bio(bp
,req
)
303 return(ASN1_i2d_bio(i2d_X509_REQ
,bp
,(unsigned char *)req
));
307 RSA
*RSAPublicKey_dup(rsa
)
310 return((RSA
*)ASN1_dup((int (*)())i2d_RSAPublicKey
,
311 (char *(*)())d2i_RSAPublicKey
,(char *)rsa
));
314 RSA
*RSAPrivateKey_dup(rsa
)
317 return((RSA
*)ASN1_dup((int (*)())i2d_RSAPrivateKey
,
318 (char *(*)())d2i_RSAPrivateKey
,(char *)rsa
));
322 RSA
*d2i_RSAPrivateKey_fp(fp
,rsa
)
326 return((RSA
*)ASN1_d2i_fp((char *(*)())
327 RSA_new
,(char *(*)())d2i_RSAPrivateKey
, (fp
),
328 (unsigned char **)(rsa
)));
331 int i2d_RSAPrivateKey_fp(fp
,rsa
)
335 return(ASN1_i2d_fp(i2d_RSAPrivateKey
,fp
,(unsigned char *)rsa
));
338 RSA
*d2i_RSAPublicKey_fp(fp
,rsa
)
342 return((RSA
*)ASN1_d2i_fp((char *(*)())
343 RSA_new
,(char *(*)())d2i_RSAPublicKey
, (fp
),
344 (unsigned char **)(rsa
)));
347 int i2d_RSAPublicKey_fp(fp
,rsa
)
351 return(ASN1_i2d_fp(i2d_RSAPublicKey
,fp
,(unsigned char *)rsa
));
355 RSA
*d2i_RSAPrivateKey_bio(bp
,rsa
)
359 return((RSA
*)ASN1_d2i_bio((char *(*)())
360 RSA_new
,(char *(*)())d2i_RSAPrivateKey
, (bp
),
361 (unsigned char **)(rsa
)));
364 int i2d_RSAPrivateKey_bio(bp
,rsa
)
368 return(ASN1_i2d_bio(i2d_RSAPrivateKey
,bp
,(unsigned char *)rsa
));
371 RSA
*d2i_RSAPublicKey_bio(bp
,rsa
)
375 return((RSA
*)ASN1_d2i_bio((char *(*)())
376 RSA_new
,(char *(*)())d2i_RSAPublicKey
, (bp
),
377 (unsigned char **)(rsa
)));
380 int i2d_RSAPublicKey_bio(bp
,rsa
)
384 return(ASN1_i2d_bio(i2d_RSAPublicKey
,bp
,(unsigned char *)rsa
));
390 DSA
*d2i_DSAPrivateKey_fp(fp
,dsa
)
394 return((DSA
*)ASN1_d2i_fp((char *(*)())
395 DSA_new
,(char *(*)())d2i_DSAPrivateKey
, (fp
),
396 (unsigned char **)(dsa
)));
399 int i2d_DSAPrivateKey_fp(fp
,dsa
)
403 return(ASN1_i2d_fp(i2d_DSAPrivateKey
,fp
,(unsigned char *)dsa
));
407 DSA
*d2i_DSAPrivateKey_bio(bp
,dsa
)
411 return((DSA
*)ASN1_d2i_bio((char *(*)())
412 DSA_new
,(char *(*)())d2i_DSAPrivateKey
, (bp
),
413 (unsigned char **)(dsa
)));
416 int i2d_DSAPrivateKey_bio(bp
,dsa
)
420 return(ASN1_i2d_bio(i2d_DSAPrivateKey
,bp
,(unsigned char *)dsa
));
424 X509_NAME
*X509_NAME_dup(xn
)
427 return((X509_NAME
*)ASN1_dup((int (*)())i2d_X509_NAME
,
428 (char *(*)())d2i_X509_NAME
,(char *)xn
));
431 X509_NAME_ENTRY
*X509_NAME_ENTRY_dup(ne
)
434 return((X509_NAME_ENTRY
*)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY
,
435 (char *(*)())d2i_X509_NAME_ENTRY
,(char *)ne
));
438 int X509_digest(data
,type
,md
,len
)
444 return(ASN1_digest((int (*)())i2d_X509
,type
,(char *)data
,md
,len
));
447 int X509_NAME_digest(data
,type
,md
,len
)
453 return(ASN1_digest((int (*)())i2d_X509_NAME
,type
,(char *)data
,md
,len
));
456 int PKCS7_ISSUER_AND_SERIAL_digest(data
,type
,md
,len
)
457 PKCS7_ISSUER_AND_SERIAL
*data
;
462 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL
,type
,
463 (char *)data
,md
,len
));