blob: a37d7bdee6863834a3f10d0b5b2e81154267bc05 [file] [log] [blame]
Adam Langleyd9e397b2015-01-22 14:27:53 -08001/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2 * All rights reserved.
3 *
4 * This package is an SSL implementation written
5 * by Eric Young (eay@cryptsoft.com).
6 * The implementation was written so as to conform with Netscapes SSL.
7 *
8 * This library is free for commercial and non-commercial use as long as
9 * the following conditions are aheared to. The following conditions
10 * apply to all code found in this distribution, be it the RC4, RSA,
11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12 * included with this distribution is covered by the same copyright terms
13 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14 *
15 * Copyright remains Eric Young's, and as such any Copyright notices in
16 * the code are not to be removed.
17 * If this package is used in a product, Eric Young should be given attribution
18 * as the author of the parts of the library used.
19 * This can be in the form of a textual message at program startup or
20 * in documentation (online or textual) provided with the package.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * "This product includes cryptographic software written by
33 * Eric Young (eay@cryptsoft.com)"
34 * The word 'cryptographic' can be left out if the rouines from the library
35 * being used are not cryptographic related :-).
36 * 4. If you include any Windows specific code (or a derivative thereof) from
37 * the apps directory (application code) you must include an acknowledgement:
38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply be
54 * copied and put under another distribution licence
55 * [including the GNU Public Licence.] */
56
Robert Sloanf068def2018-10-10 18:45:40 -070057#include <openssl/x509.h>
58
59#include <limits.h>
60
Adam Langleyd9e397b2015-01-22 14:27:53 -080061#include <openssl/asn1.h>
62#include <openssl/buf.h>
63#include <openssl/digest.h>
64#include <openssl/dsa.h>
65#include <openssl/evp.h>
Robert Sloanf068def2018-10-10 18:45:40 -070066#include <openssl/mem.h>
Adam Langleyd9e397b2015-01-22 14:27:53 -080067#include <openssl/rsa.h>
68#include <openssl/stack.h>
Adam Langleyd9e397b2015-01-22 14:27:53 -080069
Adam Langleyd9e397b2015-01-22 14:27:53 -080070int X509_verify(X509 *a, EVP_PKEY *r)
David Benjamin4969cc92016-04-22 15:02:23 -040071{
Robert Sloan036981b2018-09-24 10:20:02 -070072 if (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature)) {
73 OPENSSL_PUT_ERROR(X509, X509_R_SIGNATURE_ALGORITHM_MISMATCH);
David Benjamin4969cc92016-04-22 15:02:23 -040074 return 0;
Robert Sloan036981b2018-09-24 10:20:02 -070075 }
David Benjamin4969cc92016-04-22 15:02:23 -040076 return (ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), a->sig_alg,
77 a->signature, a->cert_info, r));
78}
Adam Langleyd9e397b2015-01-22 14:27:53 -080079
80int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
David Benjamin4969cc92016-04-22 15:02:23 -040081{
82 return (ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
83 a->sig_alg, a->signature, a->req_info, r));
84}
Adam Langleyd9e397b2015-01-22 14:27:53 -080085
86int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
David Benjamin4969cc92016-04-22 15:02:23 -040087{
88 x->cert_info->enc.modified = 1;
89 return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature,
90 x->sig_alg, x->signature, x->cert_info, pkey, md));
91}
Adam Langleyd9e397b2015-01-22 14:27:53 -080092
93int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx)
David Benjamin4969cc92016-04-22 15:02:23 -040094{
95 x->cert_info->enc.modified = 1;
96 return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF),
97 x->cert_info->signature,
98 x->sig_alg, x->signature, x->cert_info, ctx);
99}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800100
Adam Langleyd9e397b2015-01-22 14:27:53 -0800101int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
David Benjamin4969cc92016-04-22 15:02:23 -0400102{
103 return (ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO), x->sig_alg, NULL,
104 x->signature, x->req_info, pkey, md));
105}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800106
107int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx)
David Benjamin4969cc92016-04-22 15:02:23 -0400108{
109 return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO),
110 x->sig_alg, NULL, x->signature, x->req_info,
111 ctx);
112}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800113
114int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
David Benjamin4969cc92016-04-22 15:02:23 -0400115{
116 x->crl->enc.modified = 1;
117 return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg,
118 x->sig_alg, x->signature, x->crl, pkey, md));
119}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800120
121int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx)
David Benjamin4969cc92016-04-22 15:02:23 -0400122{
123 x->crl->enc.modified = 1;
124 return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO),
125 x->crl->sig_alg, x->sig_alg, x->signature,
126 x->crl, ctx);
127}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800128
Adam Langleyd9e397b2015-01-22 14:27:53 -0800129int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
David Benjamin4969cc92016-04-22 15:02:23 -0400130{
131 return (ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor, NULL,
132 x->signature, x->spkac, pkey, md));
133}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800134
Kenny Rootb8494592015-09-25 02:29:14 +0000135int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *x, EVP_PKEY *pkey)
David Benjamin4969cc92016-04-22 15:02:23 -0400136{
137 return (ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,
138 x->signature, x->spkac, pkey));
139}
Kenny Rootb8494592015-09-25 02:29:14 +0000140
Adam Langleyd9e397b2015-01-22 14:27:53 -0800141#ifndef OPENSSL_NO_FP_API
142X509 *d2i_X509_fp(FILE *fp, X509 **x509)
David Benjamin4969cc92016-04-22 15:02:23 -0400143{
144 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509);
145}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800146
147int i2d_X509_fp(FILE *fp, X509 *x509)
David Benjamin4969cc92016-04-22 15:02:23 -0400148{
149 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509);
150}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800151#endif
152
153X509 *d2i_X509_bio(BIO *bp, X509 **x509)
David Benjamin4969cc92016-04-22 15:02:23 -0400154{
155 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509);
156}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800157
158int i2d_X509_bio(BIO *bp, X509 *x509)
David Benjamin4969cc92016-04-22 15:02:23 -0400159{
160 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509);
161}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800162
163#ifndef OPENSSL_NO_FP_API
164X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
David Benjamin4969cc92016-04-22 15:02:23 -0400165{
166 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
167}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800168
169int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
David Benjamin4969cc92016-04-22 15:02:23 -0400170{
171 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
172}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800173#endif
174
175X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
David Benjamin4969cc92016-04-22 15:02:23 -0400176{
177 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
178}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800179
180int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
David Benjamin4969cc92016-04-22 15:02:23 -0400181{
182 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
183}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800184
Adam Langleyd9e397b2015-01-22 14:27:53 -0800185#ifndef OPENSSL_NO_FP_API
186X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
David Benjamin4969cc92016-04-22 15:02:23 -0400187{
188 return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
189}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800190
191int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
David Benjamin4969cc92016-04-22 15:02:23 -0400192{
193 return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
194}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800195#endif
196
197X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
David Benjamin4969cc92016-04-22 15:02:23 -0400198{
199 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
200}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800201
202int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
David Benjamin4969cc92016-04-22 15:02:23 -0400203{
204 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
205}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800206
207#ifndef OPENSSL_NO_FP_API
Adam Langleyd9e397b2015-01-22 14:27:53 -0800208
Robert Sloanf068def2018-10-10 18:45:40 -0700209#define IMPLEMENT_D2I_FP(type, name, bio_func) \
210 type *name(FILE *fp, type **obj) { \
211 BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); \
212 if (bio == NULL) { \
213 return NULL; \
214 } \
215 type *ret = bio_func(bio, obj); \
216 BIO_free(bio); \
217 return ret; \
218 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800219
Robert Sloanf068def2018-10-10 18:45:40 -0700220#define IMPLEMENT_I2D_FP(type, name, bio_func) \
221 int name(FILE *fp, type *obj) { \
222 BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); \
223 if (bio == NULL) { \
224 return 0; \
225 } \
226 int ret = bio_func(bio, obj); \
227 BIO_free(bio); \
228 return ret; \
229 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800230
Robert Sloanf068def2018-10-10 18:45:40 -0700231IMPLEMENT_D2I_FP(RSA, d2i_RSAPrivateKey_fp, d2i_RSAPrivateKey_bio)
232IMPLEMENT_I2D_FP(RSA, i2d_RSAPrivateKey_fp, i2d_RSAPrivateKey_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800233
Robert Sloanf068def2018-10-10 18:45:40 -0700234IMPLEMENT_D2I_FP(RSA, d2i_RSAPublicKey_fp, d2i_RSAPublicKey_bio)
235IMPLEMENT_I2D_FP(RSA, i2d_RSAPublicKey_fp, i2d_RSAPublicKey_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800236
Robert Sloanf068def2018-10-10 18:45:40 -0700237IMPLEMENT_D2I_FP(RSA, d2i_RSA_PUBKEY_fp, d2i_RSA_PUBKEY_bio)
238IMPLEMENT_I2D_FP(RSA, i2d_RSA_PUBKEY_fp, i2d_RSA_PUBKEY_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800239#endif
240
Robert Sloanf068def2018-10-10 18:45:40 -0700241#define IMPLEMENT_D2I_BIO(type, name, d2i_func) \
242 type *name(BIO *bio, type **obj) { \
243 uint8_t *data; \
244 size_t len; \
245 if (!BIO_read_asn1(bio, &data, &len, 100 * 1024)) { \
246 return NULL; \
247 } \
248 const uint8_t *ptr = data; \
249 type *ret = d2i_func(obj, &ptr, (long)len); \
250 OPENSSL_free(data); \
251 return ret; \
252 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800253
Robert Sloanf068def2018-10-10 18:45:40 -0700254#define IMPLEMENT_I2D_BIO(type, name, i2d_func) \
255 int name(BIO *bio, type *obj) { \
256 uint8_t *data = NULL; \
257 int len = i2d_func(obj, &data); \
258 if (len < 0) { \
259 return 0; \
260 } \
261 int ret = BIO_write_all(bio, data, len); \
262 OPENSSL_free(data); \
263 return ret; \
264 }
Adam Langleyd9e397b2015-01-22 14:27:53 -0800265
Robert Sloanf068def2018-10-10 18:45:40 -0700266IMPLEMENT_D2I_BIO(RSA, d2i_RSAPrivateKey_bio, d2i_RSAPrivateKey)
267IMPLEMENT_I2D_BIO(RSA, i2d_RSAPrivateKey_bio, i2d_RSAPrivateKey)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800268
Robert Sloanf068def2018-10-10 18:45:40 -0700269IMPLEMENT_D2I_BIO(RSA, d2i_RSAPublicKey_bio, d2i_RSAPublicKey)
270IMPLEMENT_I2D_BIO(RSA, i2d_RSAPublicKey_bio, i2d_RSAPublicKey)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800271
Robert Sloanf068def2018-10-10 18:45:40 -0700272IMPLEMENT_D2I_BIO(RSA, d2i_RSA_PUBKEY_bio, d2i_RSA_PUBKEY)
273IMPLEMENT_I2D_BIO(RSA, i2d_RSA_PUBKEY_bio, i2d_RSA_PUBKEY)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800274
275#ifndef OPENSSL_NO_DSA
David Benjamin4969cc92016-04-22 15:02:23 -0400276# ifndef OPENSSL_NO_FP_API
Robert Sloanf068def2018-10-10 18:45:40 -0700277IMPLEMENT_D2I_FP(DSA, d2i_DSAPrivateKey_fp, d2i_DSAPrivateKey_bio)
278IMPLEMENT_I2D_FP(DSA, i2d_DSAPrivateKey_fp, i2d_DSAPrivateKey_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800279
Robert Sloanf068def2018-10-10 18:45:40 -0700280IMPLEMENT_D2I_FP(DSA, d2i_DSA_PUBKEY_fp, d2i_DSA_PUBKEY_bio)
281IMPLEMENT_I2D_FP(DSA, i2d_DSA_PUBKEY_fp, i2d_DSA_PUBKEY_bio)
David Benjamin4969cc92016-04-22 15:02:23 -0400282# endif
Adam Langleyd9e397b2015-01-22 14:27:53 -0800283
Robert Sloanf068def2018-10-10 18:45:40 -0700284IMPLEMENT_D2I_BIO(DSA, d2i_DSAPrivateKey_bio, d2i_DSAPrivateKey)
285IMPLEMENT_I2D_BIO(DSA, i2d_DSAPrivateKey_bio, i2d_DSAPrivateKey)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800286
Robert Sloanf068def2018-10-10 18:45:40 -0700287IMPLEMENT_D2I_BIO(DSA, d2i_DSA_PUBKEY_bio, d2i_DSA_PUBKEY)
288IMPLEMENT_I2D_BIO(DSA, i2d_DSA_PUBKEY_bio, i2d_DSA_PUBKEY)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800289#endif
290
291#ifndef OPENSSL_NO_FP_API
Robert Sloanf068def2018-10-10 18:45:40 -0700292IMPLEMENT_D2I_FP(EC_KEY, d2i_ECPrivateKey_fp, d2i_ECPrivateKey_bio)
293IMPLEMENT_I2D_FP(EC_KEY, i2d_ECPrivateKey_fp, i2d_ECPrivateKey_bio)
David Benjamin4969cc92016-04-22 15:02:23 -0400294
Robert Sloanf068def2018-10-10 18:45:40 -0700295IMPLEMENT_D2I_FP(EC_KEY, d2i_EC_PUBKEY_fp, d2i_EC_PUBKEY_bio)
296IMPLEMENT_I2D_FP(EC_KEY, i2d_EC_PUBKEY_fp, i2d_EC_PUBKEY_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800297#endif
David Benjamin4969cc92016-04-22 15:02:23 -0400298
Robert Sloanf068def2018-10-10 18:45:40 -0700299IMPLEMENT_D2I_BIO(EC_KEY, d2i_ECPrivateKey_bio, d2i_ECPrivateKey)
300IMPLEMENT_I2D_BIO(EC_KEY, i2d_ECPrivateKey_bio, i2d_ECPrivateKey)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800301
Robert Sloanf068def2018-10-10 18:45:40 -0700302IMPLEMENT_D2I_BIO(EC_KEY, d2i_EC_PUBKEY_bio, d2i_EC_PUBKEY)
303IMPLEMENT_I2D_BIO(EC_KEY, i2d_EC_PUBKEY_bio, i2d_EC_PUBKEY)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800304
David Benjamin4969cc92016-04-22 15:02:23 -0400305int X509_pubkey_digest(const X509 *data, const EVP_MD *type,
306 unsigned char *md, unsigned int *len)
307{
308 ASN1_BIT_STRING *key;
309 key = X509_get0_pubkey_bitstr(data);
310 if (!key)
311 return 0;
312 return EVP_Digest(key->data, key->length, md, len, type, NULL);
313}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800314
315int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
David Benjamin4969cc92016-04-22 15:02:23 -0400316 unsigned int *len)
317{
318 return (ASN1_item_digest
319 (ASN1_ITEM_rptr(X509), type, (char *)data, md, len));
320}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800321
David Benjamin4969cc92016-04-22 15:02:23 -0400322int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type,
323 unsigned char *md, unsigned int *len)
324{
325 return (ASN1_item_digest
326 (ASN1_ITEM_rptr(X509_CRL), type, (char *)data, md, len));
327}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800328
David Benjamin4969cc92016-04-22 15:02:23 -0400329int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type,
330 unsigned char *md, unsigned int *len)
331{
332 return (ASN1_item_digest
333 (ASN1_ITEM_rptr(X509_REQ), type, (char *)data, md, len));
334}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800335
David Benjamin4969cc92016-04-22 15:02:23 -0400336int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type,
337 unsigned char *md, unsigned int *len)
338{
339 return (ASN1_item_digest
340 (ASN1_ITEM_rptr(X509_NAME), type, (char *)data, md, len));
341}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800342
Adam Langleyd9e397b2015-01-22 14:27:53 -0800343#ifndef OPENSSL_NO_FP_API
Robert Sloanf068def2018-10-10 18:45:40 -0700344IMPLEMENT_D2I_FP(X509_SIG, d2i_PKCS8_fp, d2i_PKCS8_bio)
345IMPLEMENT_I2D_FP(X509_SIG, i2d_PKCS8_fp, i2d_PKCS8_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800346#endif
347
Robert Sloanf068def2018-10-10 18:45:40 -0700348IMPLEMENT_D2I_BIO(X509_SIG, d2i_PKCS8_bio, d2i_X509_SIG)
349IMPLEMENT_I2D_BIO(X509_SIG, i2d_PKCS8_bio, i2d_X509_SIG)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800350
351#ifndef OPENSSL_NO_FP_API
Robert Sloanf068def2018-10-10 18:45:40 -0700352IMPLEMENT_D2I_FP(PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_fp,
353 d2i_PKCS8_PRIV_KEY_INFO_bio)
354IMPLEMENT_I2D_FP(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO_fp,
355 i2d_PKCS8_PRIV_KEY_INFO_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800356
357int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
David Benjamin4969cc92016-04-22 15:02:23 -0400358{
359 PKCS8_PRIV_KEY_INFO *p8inf;
360 int ret;
361 p8inf = EVP_PKEY2PKCS8(key);
362 if (!p8inf)
363 return 0;
364 ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
365 PKCS8_PRIV_KEY_INFO_free(p8inf);
366 return ret;
367}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800368
Robert Sloanf068def2018-10-10 18:45:40 -0700369IMPLEMENT_D2I_FP(EVP_PKEY, d2i_PrivateKey_fp, d2i_PrivateKey_bio)
370IMPLEMENT_I2D_FP(EVP_PKEY, i2d_PrivateKey_fp, i2d_PrivateKey_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800371
Robert Sloanf068def2018-10-10 18:45:40 -0700372IMPLEMENT_D2I_FP(EVP_PKEY, d2i_PUBKEY_fp, d2i_PUBKEY_bio)
373IMPLEMENT_I2D_FP(EVP_PKEY, i2d_PUBKEY_fp, i2d_PUBKEY_bio)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800374
Robert Sloanf068def2018-10-10 18:45:40 -0700375IMPLEMENT_D2I_BIO(PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_bio,
376 d2i_PKCS8_PRIV_KEY_INFO)
377IMPLEMENT_I2D_BIO(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO_bio,
378 i2d_PKCS8_PRIV_KEY_INFO)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800379
380int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
David Benjamin4969cc92016-04-22 15:02:23 -0400381{
382 PKCS8_PRIV_KEY_INFO *p8inf;
383 int ret;
384 p8inf = EVP_PKEY2PKCS8(key);
385 if (!p8inf)
386 return 0;
387 ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
388 PKCS8_PRIV_KEY_INFO_free(p8inf);
389 return ret;
390}
Adam Langleyd9e397b2015-01-22 14:27:53 -0800391#endif
392
Robert Sloanf068def2018-10-10 18:45:40 -0700393IMPLEMENT_D2I_BIO(EVP_PKEY, d2i_PrivateKey_bio, d2i_AutoPrivateKey)
394IMPLEMENT_I2D_BIO(EVP_PKEY, i2d_PrivateKey_bio, i2d_PrivateKey)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800395
Robert Sloanf068def2018-10-10 18:45:40 -0700396IMPLEMENT_D2I_BIO(EVP_PKEY, d2i_PUBKEY_bio, d2i_PUBKEY)
397IMPLEMENT_I2D_BIO(EVP_PKEY, i2d_PUBKEY_bio, i2d_PUBKEY)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800398
Robert Sloanf068def2018-10-10 18:45:40 -0700399IMPLEMENT_D2I_BIO(DH, d2i_DHparams_bio, d2i_DHparams)
400IMPLEMENT_I2D_BIO(const DH, i2d_DHparams_bio, i2d_DHparams)