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