]>
Commit | Line | Data |
---|---|---|
d02b48c6 | 1 | /* crypto/x509/x_all.c */ |
58964a49 | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
d02b48c6 RE |
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 | |
ec577822 | 61 | #include <openssl/stack.h> |
d02b48c6 | 62 | #include "cryptlib.h" |
ec577822 BM |
63 | #include <openssl/buffer.h> |
64 | #include <openssl/asn1.h> | |
65 | #include <openssl/evp.h> | |
66 | #include <openssl/x509.h> | |
d02b48c6 | 67 | |
6b691a5c | 68 | int X509_verify(X509 *a, EVP_PKEY *r) |
d02b48c6 | 69 | { |
bb5ea36b | 70 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg, |
4e1209eb | 71 | a->signature,a->cert_info,r)); |
d02b48c6 RE |
72 | } |
73 | ||
6b691a5c | 74 | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) |
d02b48c6 | 75 | { |
bb5ea36b | 76 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), |
4e1209eb | 77 | a->sig_alg,a->signature,a->req_info,r)); |
d02b48c6 RE |
78 | } |
79 | ||
6b691a5c | 80 | int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r) |
d02b48c6 | 81 | { |
bb5ea36b | 82 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), |
4e1209eb | 83 | a->sig_alg, a->signature,a->crl,r)); |
d02b48c6 RE |
84 | } |
85 | ||
6b691a5c | 86 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) |
d02b48c6 | 87 | { |
bb5ea36b | 88 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
4e1209eb | 89 | a->sig_algor,a->signature,a->spkac,r)); |
d02b48c6 RE |
90 | } |
91 | ||
6b691a5c | 92 | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) |
d02b48c6 | 93 | { |
bb5ea36b | 94 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature, |
4e1209eb | 95 | x->sig_alg, x->signature, x->cert_info,pkey,md)); |
d02b48c6 RE |
96 | } |
97 | ||
6b691a5c | 98 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) |
d02b48c6 | 99 | { |
bb5ea36b | 100 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL, |
4e1209eb | 101 | x->signature, x->req_info,pkey,md)); |
d02b48c6 RE |
102 | } |
103 | ||
6b691a5c | 104 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) |
d02b48c6 | 105 | { |
bb5ea36b | 106 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg, |
4e1209eb | 107 | x->sig_alg, x->signature, x->crl,pkey,md)); |
d02b48c6 RE |
108 | } |
109 | ||
6b691a5c | 110 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) |
d02b48c6 | 111 | { |
bb5ea36b | 112 | return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL, |
4e1209eb | 113 | x->signature, x->spkac,pkey,md)); |
d02b48c6 RE |
114 | } |
115 | ||
cf1b7d96 | 116 | #ifndef OPENSSL_NO_FP_API |
31a352d1 | 117 | X509 *d2i_X509_fp(FILE *fp, X509 **x509) |
d02b48c6 | 118 | { |
bb5ea36b | 119 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); |
d02b48c6 RE |
120 | } |
121 | ||
6b691a5c | 122 | int i2d_X509_fp(FILE *fp, X509 *x509) |
d02b48c6 | 123 | { |
bb5ea36b | 124 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); |
d02b48c6 RE |
125 | } |
126 | #endif | |
127 | ||
31a352d1 | 128 | X509 *d2i_X509_bio(BIO *bp, X509 **x509) |
d02b48c6 | 129 | { |
bb5ea36b | 130 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); |
d02b48c6 RE |
131 | } |
132 | ||
6b691a5c | 133 | int i2d_X509_bio(BIO *bp, X509 *x509) |
d02b48c6 | 134 | { |
bb5ea36b | 135 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); |
d02b48c6 RE |
136 | } |
137 | ||
cf1b7d96 | 138 | #ifndef OPENSSL_NO_FP_API |
31a352d1 | 139 | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) |
d02b48c6 | 140 | { |
bb5ea36b | 141 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
d02b48c6 RE |
142 | } |
143 | ||
6b691a5c | 144 | int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) |
d02b48c6 | 145 | { |
bb5ea36b | 146 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
d02b48c6 RE |
147 | } |
148 | #endif | |
149 | ||
31a352d1 | 150 | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) |
d02b48c6 | 151 | { |
bb5ea36b | 152 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
d02b48c6 RE |
153 | } |
154 | ||
6b691a5c | 155 | int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) |
d02b48c6 | 156 | { |
bb5ea36b | 157 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
d02b48c6 RE |
158 | } |
159 | ||
cf1b7d96 | 160 | #ifndef OPENSSL_NO_FP_API |
31a352d1 | 161 | PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) |
d02b48c6 | 162 | { |
bb5ea36b | 163 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
d02b48c6 RE |
164 | } |
165 | ||
6b691a5c | 166 | int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) |
d02b48c6 | 167 | { |
bb5ea36b | 168 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
d02b48c6 RE |
169 | } |
170 | #endif | |
171 | ||
31a352d1 | 172 | PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) |
d02b48c6 | 173 | { |
bb5ea36b | 174 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
d02b48c6 RE |
175 | } |
176 | ||
6b691a5c | 177 | int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) |
d02b48c6 | 178 | { |
bb5ea36b | 179 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
d02b48c6 RE |
180 | } |
181 | ||
cf1b7d96 | 182 | #ifndef OPENSSL_NO_FP_API |
31a352d1 | 183 | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) |
d02b48c6 | 184 | { |
bb5ea36b | 185 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
d02b48c6 RE |
186 | } |
187 | ||
6b691a5c | 188 | int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) |
d02b48c6 | 189 | { |
bb5ea36b | 190 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
d02b48c6 RE |
191 | } |
192 | #endif | |
193 | ||
31a352d1 | 194 | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) |
d02b48c6 | 195 | { |
bb5ea36b | 196 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
d02b48c6 RE |
197 | } |
198 | ||
6b691a5c | 199 | int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) |
d02b48c6 | 200 | { |
bb5ea36b | 201 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
d02b48c6 RE |
202 | } |
203 | ||
cf1b7d96 | 204 | #ifndef OPENSSL_NO_RSA |
d02b48c6 | 205 | |
cf1b7d96 | 206 | #ifndef OPENSSL_NO_FP_API |
31a352d1 | 207 | RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) |
d02b48c6 | 208 | { |
bb5ea36b | 209 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
d02b48c6 RE |
210 | } |
211 | ||
6b691a5c | 212 | int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) |
d02b48c6 | 213 | { |
bb5ea36b | 214 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
d02b48c6 RE |
215 | } |
216 | ||
31a352d1 | 217 | RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) |
d02b48c6 | 218 | { |
bb5ea36b | 219 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
d02b48c6 RE |
220 | } |
221 | ||
4e1209eb | 222 | |
52664f50 DSH |
223 | RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) |
224 | { | |
225 | return((RSA *)ASN1_d2i_fp((char *(*)()) | |
226 | RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp), | |
227 | (unsigned char **)(rsa))); | |
228 | } | |
229 | ||
6b691a5c | 230 | int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) |
d02b48c6 | 231 | { |
bb5ea36b | 232 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
d02b48c6 | 233 | } |
52664f50 DSH |
234 | |
235 | int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) | |
236 | { | |
237 | return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa)); | |
238 | } | |
d02b48c6 RE |
239 | #endif |
240 | ||
31a352d1 | 241 | RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) |
d02b48c6 | 242 | { |
bb5ea36b | 243 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
d02b48c6 RE |
244 | } |
245 | ||
6b691a5c | 246 | int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) |
d02b48c6 | 247 | { |
bb5ea36b | 248 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
d02b48c6 RE |
249 | } |
250 | ||
31a352d1 | 251 | RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) |
d02b48c6 | 252 | { |
bb5ea36b | 253 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
d02b48c6 RE |
254 | } |
255 | ||
4e1209eb | 256 | |
52664f50 DSH |
257 | RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) |
258 | { | |
259 | return((RSA *)ASN1_d2i_bio((char *(*)()) | |
260 | RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp), | |
261 | (unsigned char **)(rsa))); | |
262 | } | |
263 | ||
6b691a5c | 264 | int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) |
d02b48c6 | 265 | { |
bb5ea36b | 266 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
d02b48c6 | 267 | } |
52664f50 DSH |
268 | |
269 | int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) | |
270 | { | |
271 | return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa)); | |
272 | } | |
d02b48c6 RE |
273 | #endif |
274 | ||
cf1b7d96 RL |
275 | #ifndef OPENSSL_NO_DSA |
276 | #ifndef OPENSSL_NO_FP_API | |
31a352d1 | 277 | DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) |
d02b48c6 RE |
278 | { |
279 | return((DSA *)ASN1_d2i_fp((char *(*)()) | |
280 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), | |
281 | (unsigned char **)(dsa))); | |
282 | } | |
283 | ||
6b691a5c | 284 | int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) |
d02b48c6 RE |
285 | { |
286 | return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa)); | |
287 | } | |
3ea23631 | 288 | |
52664f50 | 289 | DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) |
3ea23631 DSH |
290 | { |
291 | return((DSA *)ASN1_d2i_fp((char *(*)()) | |
52664f50 | 292 | DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp), |
3ea23631 DSH |
293 | (unsigned char **)(dsa))); |
294 | } | |
295 | ||
52664f50 | 296 | int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) |
3ea23631 | 297 | { |
52664f50 | 298 | return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa)); |
3ea23631 | 299 | } |
d02b48c6 RE |
300 | #endif |
301 | ||
31a352d1 | 302 | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) |
d02b48c6 RE |
303 | { |
304 | return((DSA *)ASN1_d2i_bio((char *(*)()) | |
305 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), | |
306 | (unsigned char **)(dsa))); | |
307 | } | |
308 | ||
6b691a5c | 309 | int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) |
d02b48c6 RE |
310 | { |
311 | return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa)); | |
312 | } | |
3ea23631 | 313 | |
52664f50 | 314 | DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) |
3ea23631 DSH |
315 | { |
316 | return((DSA *)ASN1_d2i_bio((char *(*)()) | |
52664f50 | 317 | DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp), |
3ea23631 DSH |
318 | (unsigned char **)(dsa))); |
319 | } | |
320 | ||
52664f50 | 321 | int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) |
3ea23631 | 322 | { |
52664f50 | 323 | return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa)); |
3ea23631 DSH |
324 | } |
325 | ||
d02b48c6 RE |
326 | #endif |
327 | ||
4d94ae00 BM |
328 | #ifndef OPENSSL_NO_ECDSA |
329 | #ifndef OPENSSL_NO_FP_API | |
330 | ECDSA *d2i_ECDSAPrivateKey_fp(FILE *fp, ECDSA **ecdsa) | |
331 | { | |
332 | return((ECDSA *)ASN1_d2i_fp((char *(*)()) | |
333 | ECDSA_new,(char *(*)())d2i_ECDSAPrivateKey, (fp), | |
334 | (unsigned char **)(ecdsa))); | |
335 | } | |
336 | ||
337 | int i2d_ECDSAPrivateKey_fp(FILE *fp, ECDSA *ecdsa) | |
338 | { | |
339 | return(ASN1_i2d_fp(i2d_ECDSAPrivateKey,fp,(unsigned char *)ecdsa)); | |
340 | } | |
341 | ||
342 | ECDSA *d2i_ECDSA_PUBKEY_fp(FILE *fp, ECDSA **ecdsa) | |
343 | { | |
344 | return((ECDSA *)ASN1_d2i_fp((char *(*)()) | |
345 | ECDSA_new,(char *(*)())d2i_ECDSA_PUBKEY, (fp), | |
346 | (unsigned char **)(ecdsa))); | |
347 | } | |
348 | ||
349 | int i2d_ECDSA_PUBKEY_fp(FILE *fp, ECDSA *ecdsa) | |
350 | { | |
351 | return(ASN1_i2d_fp(i2d_ECDSA_PUBKEY,fp,(unsigned char *)ecdsa)); | |
352 | } | |
353 | #endif | |
354 | ||
355 | ECDSA *d2i_ECDSAPrivateKey_bio(BIO *bp, ECDSA **ecdsa) | |
356 | { | |
357 | return((ECDSA *)ASN1_d2i_bio((char *(*)()) | |
358 | ECDSA_new,(char *(*)())d2i_ECDSAPrivateKey, (bp), | |
359 | (unsigned char **)(ecdsa))); | |
360 | } | |
361 | ||
362 | int i2d_ECDSAPrivateKey_bio(BIO *bp, ECDSA *ecdsa) | |
363 | { | |
364 | return(ASN1_i2d_bio(i2d_ECDSAPrivateKey,bp,(unsigned char *)ecdsa)); | |
365 | } | |
366 | ||
367 | ECDSA *d2i_ECDSA_PUBKEY_bio(BIO *bp, ECDSA **ecdsa) | |
368 | { | |
369 | return((ECDSA *)ASN1_d2i_bio((char *(*)()) | |
370 | ECDSA_new,(char *(*)())d2i_ECDSA_PUBKEY, (bp), | |
371 | (unsigned char **)(ecdsa))); | |
372 | } | |
373 | ||
374 | int i2d_ECDSA_PUBKEY_bio(BIO *bp, ECDSA *ecdsa) | |
375 | { | |
376 | return(ASN1_i2d_bio(i2d_ECDSA_PUBKEY,bp,(unsigned char *)ecdsa)); | |
377 | } | |
378 | ||
379 | #endif | |
380 | ||
88ce56f8 DSH |
381 | int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
382 | unsigned int *len) | |
383 | { | |
384 | ASN1_BIT_STRING *key; | |
385 | key = X509_get0_pubkey_bitstr(data); | |
386 | if(!key) return 0; | |
20d2186c | 387 | return EVP_Digest(key->data, key->length, md, len, type, NULL); |
88ce56f8 DSH |
388 | } |
389 | ||
ccd86b68 | 390 | int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
6b691a5c | 391 | unsigned int *len) |
d02b48c6 | 392 | { |
bb5ea36b | 393 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len)); |
d02b48c6 RE |
394 | } |
395 | ||
ccd86b68 | 396 | int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, |
439df508 DSH |
397 | unsigned int *len) |
398 | { | |
bb5ea36b | 399 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len)); |
439df508 DSH |
400 | } |
401 | ||
ccd86b68 | 402 | int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, |
439df508 DSH |
403 | unsigned int *len) |
404 | { | |
bb5ea36b | 405 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len)); |
439df508 DSH |
406 | } |
407 | ||
ccd86b68 | 408 | int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, |
6b691a5c | 409 | unsigned int *len) |
d02b48c6 | 410 | { |
bb5ea36b | 411 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len)); |
d02b48c6 RE |
412 | } |
413 | ||
9868232a | 414 | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type, |
6b691a5c | 415 | unsigned char *md, unsigned int *len) |
d02b48c6 | 416 | { |
bb5ea36b | 417 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type, |
d02b48c6 RE |
418 | (char *)data,md,len)); |
419 | } | |
420 | ||
3cbb7937 | 421 | |
cf1b7d96 | 422 | #ifndef OPENSSL_NO_FP_API |
3cbb7937 DSH |
423 | X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) |
424 | { | |
425 | return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new, | |
426 | (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8))); | |
427 | } | |
428 | ||
429 | int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) | |
430 | { | |
431 | return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8)); | |
432 | } | |
433 | #endif | |
434 | ||
435 | X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) | |
436 | { | |
437 | return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new, | |
438 | (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8))); | |
439 | } | |
440 | ||
441 | int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) | |
442 | { | |
443 | return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8)); | |
444 | } | |
445 | ||
cf1b7d96 | 446 | #ifndef OPENSSL_NO_FP_API |
3cbb7937 DSH |
447 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, |
448 | PKCS8_PRIV_KEY_INFO **p8inf) | |
449 | { | |
450 | return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp( | |
451 | (char *(*)())PKCS8_PRIV_KEY_INFO_new, | |
452 | (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp), | |
453 | (unsigned char **)(p8inf))); | |
454 | } | |
455 | ||
456 | int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) | |
457 | { | |
458 | return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf)); | |
459 | } | |
36217a94 DSH |
460 | |
461 | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | |
462 | { | |
463 | PKCS8_PRIV_KEY_INFO *p8inf; | |
464 | int ret; | |
465 | p8inf = EVP_PKEY2PKCS8(key); | |
466 | if(!p8inf) return 0; | |
467 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); | |
468 | PKCS8_PRIV_KEY_INFO_free(p8inf); | |
469 | return ret; | |
470 | } | |
471 | ||
e6f3c585 DSH |
472 | int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) |
473 | { | |
474 | return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey)); | |
475 | } | |
476 | ||
20432eae | 477 | EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) |
e6f3c585 | 478 | { |
20432eae DSH |
479 | return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new, |
480 | (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a))); | |
e6f3c585 DSH |
481 | } |
482 | ||
bd08a2bd DSH |
483 | int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) |
484 | { | |
485 | return(ASN1_i2d_fp(i2d_PUBKEY,fp,(unsigned char *)pkey)); | |
486 | } | |
487 | ||
488 | EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | |
489 | { | |
490 | return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new, | |
491 | (char *(*)())d2i_PUBKEY, (fp),(unsigned char **)(a))); | |
492 | } | |
493 | ||
3cbb7937 DSH |
494 | #endif |
495 | ||
496 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, | |
497 | PKCS8_PRIV_KEY_INFO **p8inf) | |
498 | { | |
499 | return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio( | |
500 | (char *(*)())PKCS8_PRIV_KEY_INFO_new, | |
501 | (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp), | |
502 | (unsigned char **)(p8inf))); | |
503 | } | |
504 | ||
505 | int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) | |
506 | { | |
507 | return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf)); | |
508 | } | |
36217a94 DSH |
509 | |
510 | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | |
511 | { | |
512 | PKCS8_PRIV_KEY_INFO *p8inf; | |
513 | int ret; | |
514 | p8inf = EVP_PKEY2PKCS8(key); | |
515 | if(!p8inf) return 0; | |
516 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); | |
517 | PKCS8_PRIV_KEY_INFO_free(p8inf); | |
518 | return ret; | |
519 | } | |
e6f3c585 DSH |
520 | |
521 | int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) | |
522 | { | |
523 | return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey)); | |
524 | } | |
525 | ||
20432eae | 526 | EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) |
e6f3c585 | 527 | { |
20432eae DSH |
528 | return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new, |
529 | (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a))); | |
e6f3c585 | 530 | } |
bd08a2bd DSH |
531 | |
532 | int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) | |
533 | { | |
534 | return(ASN1_i2d_bio(i2d_PUBKEY,bp,(unsigned char *)pkey)); | |
535 | } | |
536 | ||
537 | EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | |
538 | { | |
539 | return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new, | |
540 | (char *(*)())d2i_PUBKEY, (bp),(unsigned char **)(a))); | |
541 | } |