/src/boringssl/crypto/x509/x_all.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* 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 | | |
57 | | #include <openssl/x509.h> |
58 | | |
59 | | #include <limits.h> |
60 | | |
61 | | #include <openssl/asn1.h> |
62 | | #include <openssl/digest.h> |
63 | | #include <openssl/dsa.h> |
64 | | #include <openssl/evp.h> |
65 | | #include <openssl/mem.h> |
66 | | #include <openssl/rsa.h> |
67 | | #include <openssl/stack.h> |
68 | | |
69 | | #include "../asn1/internal.h" |
70 | | #include "internal.h" |
71 | | |
72 | | |
73 | 0 | int X509_verify(X509 *x509, EVP_PKEY *pkey) { |
74 | 0 | if (X509_ALGOR_cmp(x509->sig_alg, x509->cert_info->signature)) { |
75 | 0 | OPENSSL_PUT_ERROR(X509, X509_R_SIGNATURE_ALGORITHM_MISMATCH); |
76 | 0 | return 0; |
77 | 0 | } |
78 | 0 | return ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), x509->sig_alg, |
79 | 0 | x509->signature, x509->cert_info, pkey); |
80 | 0 | } |
81 | | |
82 | 0 | int X509_REQ_verify(X509_REQ *req, EVP_PKEY *pkey) { |
83 | 0 | return ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), req->sig_alg, |
84 | 0 | req->signature, req->req_info, pkey); |
85 | 0 | } |
86 | | |
87 | 0 | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) { |
88 | 0 | asn1_encoding_clear(&x->cert_info->enc); |
89 | 0 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature, |
90 | 0 | x->sig_alg, x->signature, x->cert_info, pkey, md)); |
91 | 0 | } |
92 | | |
93 | 0 | int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) { |
94 | 0 | asn1_encoding_clear(&x->cert_info->enc); |
95 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature, |
96 | 0 | x->sig_alg, x->signature, x->cert_info, ctx); |
97 | 0 | } |
98 | | |
99 | 0 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) { |
100 | 0 | asn1_encoding_clear(&x->req_info->enc); |
101 | 0 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO), x->sig_alg, NULL, |
102 | 0 | x->signature, x->req_info, pkey, md)); |
103 | 0 | } |
104 | | |
105 | 0 | int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) { |
106 | 0 | asn1_encoding_clear(&x->req_info->enc); |
107 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), x->sig_alg, NULL, |
108 | 0 | x->signature, x->req_info, ctx); |
109 | 0 | } |
110 | | |
111 | 0 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) { |
112 | 0 | asn1_encoding_clear(&x->crl->enc); |
113 | 0 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg, |
114 | 0 | x->sig_alg, x->signature, x->crl, pkey, md)); |
115 | 0 | } |
116 | | |
117 | 0 | int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) { |
118 | 0 | asn1_encoding_clear(&x->crl->enc); |
119 | 0 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg, |
120 | 0 | x->sig_alg, x->signature, x->crl, ctx); |
121 | 0 | } |
122 | | |
123 | 0 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) { |
124 | 0 | return (ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor, NULL, |
125 | 0 | x->signature, x->spkac, pkey, md)); |
126 | 0 | } |
127 | | |
128 | 0 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *spki, EVP_PKEY *pkey) { |
129 | 0 | return (ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), spki->sig_algor, |
130 | 0 | spki->signature, spki->spkac, pkey)); |
131 | 0 | } |
132 | | |
133 | 0 | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) { |
134 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
135 | 0 | } |
136 | | |
137 | 0 | int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) { |
138 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
139 | 0 | } |
140 | | |
141 | 0 | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) { |
142 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
143 | 0 | } |
144 | | |
145 | 0 | int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) { |
146 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
147 | 0 | } |
148 | | |
149 | 0 | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) { |
150 | 0 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
151 | 0 | } |
152 | | |
153 | 0 | int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) { |
154 | 0 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
155 | 0 | } |
156 | | |
157 | 0 | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) { |
158 | 0 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
159 | 0 | } |
160 | | |
161 | 0 | int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) { |
162 | 0 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
163 | 0 | } |
164 | | |
165 | | |
166 | | #define IMPLEMENT_D2I_FP(type, name, bio_func) \ |
167 | 0 | type *name(FILE *fp, type **obj) { \ |
168 | 0 | BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); \ |
169 | 0 | if (bio == NULL) { \ |
170 | 0 | return NULL; \ |
171 | 0 | } \ |
172 | 0 | type *ret = bio_func(bio, obj); \ |
173 | 0 | BIO_free(bio); \ |
174 | 0 | return ret; \ |
175 | 0 | } Unexecuted instantiation: d2i_X509_fp Unexecuted instantiation: d2i_RSAPrivateKey_fp Unexecuted instantiation: d2i_RSAPublicKey_fp Unexecuted instantiation: d2i_RSA_PUBKEY_fp Unexecuted instantiation: d2i_DSAPrivateKey_fp Unexecuted instantiation: d2i_DSA_PUBKEY_fp Unexecuted instantiation: d2i_ECPrivateKey_fp Unexecuted instantiation: d2i_EC_PUBKEY_fp Unexecuted instantiation: d2i_PKCS8_fp Unexecuted instantiation: d2i_PKCS8_PRIV_KEY_INFO_fp Unexecuted instantiation: d2i_PrivateKey_fp Unexecuted instantiation: d2i_PUBKEY_fp |
176 | | |
177 | | #define IMPLEMENT_I2D_FP(type, name, bio_func) \ |
178 | 0 | int name(FILE *fp, type *obj) { \ |
179 | 0 | BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); \ |
180 | 0 | if (bio == NULL) { \ |
181 | 0 | return 0; \ |
182 | 0 | } \ |
183 | 0 | int ret = bio_func(bio, obj); \ |
184 | 0 | BIO_free(bio); \ |
185 | 0 | return ret; \ |
186 | 0 | } Unexecuted instantiation: i2d_X509_fp Unexecuted instantiation: i2d_RSAPrivateKey_fp Unexecuted instantiation: i2d_RSAPublicKey_fp Unexecuted instantiation: i2d_RSA_PUBKEY_fp Unexecuted instantiation: i2d_DSAPrivateKey_fp Unexecuted instantiation: i2d_DSA_PUBKEY_fp Unexecuted instantiation: i2d_ECPrivateKey_fp Unexecuted instantiation: i2d_EC_PUBKEY_fp Unexecuted instantiation: i2d_PKCS8_fp Unexecuted instantiation: i2d_PKCS8_PRIV_KEY_INFO_fp Unexecuted instantiation: i2d_PrivateKey_fp Unexecuted instantiation: i2d_PUBKEY_fp |
187 | | |
188 | | IMPLEMENT_D2I_FP(X509, d2i_X509_fp, d2i_X509_bio); |
189 | | IMPLEMENT_I2D_FP(X509, i2d_X509_fp, i2d_X509_bio); |
190 | | |
191 | | IMPLEMENT_D2I_FP(RSA, d2i_RSAPrivateKey_fp, d2i_RSAPrivateKey_bio) |
192 | | IMPLEMENT_I2D_FP(RSA, i2d_RSAPrivateKey_fp, i2d_RSAPrivateKey_bio) |
193 | | |
194 | | IMPLEMENT_D2I_FP(RSA, d2i_RSAPublicKey_fp, d2i_RSAPublicKey_bio) |
195 | | IMPLEMENT_I2D_FP(RSA, i2d_RSAPublicKey_fp, i2d_RSAPublicKey_bio) |
196 | | |
197 | | IMPLEMENT_D2I_FP(RSA, d2i_RSA_PUBKEY_fp, d2i_RSA_PUBKEY_bio) |
198 | | IMPLEMENT_I2D_FP(RSA, i2d_RSA_PUBKEY_fp, i2d_RSA_PUBKEY_bio) |
199 | | |
200 | | #define IMPLEMENT_D2I_BIO(type, name, d2i_func) \ |
201 | 0 | type *name(BIO *bio, type **obj) { \ |
202 | 0 | uint8_t *data; \ |
203 | 0 | size_t len; \ |
204 | 0 | if (!BIO_read_asn1(bio, &data, &len, 100 * 1024)) { \ |
205 | 0 | return NULL; \ |
206 | 0 | } \ |
207 | 0 | const uint8_t *ptr = data; \ |
208 | 0 | type *ret = d2i_func(obj, &ptr, (long)len); \ |
209 | 0 | OPENSSL_free(data); \ |
210 | 0 | return ret; \ |
211 | 0 | } Unexecuted instantiation: d2i_X509_bio Unexecuted instantiation: d2i_RSAPrivateKey_bio Unexecuted instantiation: d2i_RSAPublicKey_bio Unexecuted instantiation: d2i_RSA_PUBKEY_bio Unexecuted instantiation: d2i_DSAPrivateKey_bio Unexecuted instantiation: d2i_DSA_PUBKEY_bio Unexecuted instantiation: d2i_ECPrivateKey_bio Unexecuted instantiation: d2i_EC_PUBKEY_bio Unexecuted instantiation: d2i_PKCS8_bio Unexecuted instantiation: d2i_PKCS8_PRIV_KEY_INFO_bio Unexecuted instantiation: d2i_PrivateKey_bio Unexecuted instantiation: d2i_PUBKEY_bio Unexecuted instantiation: d2i_DHparams_bio |
212 | | |
213 | | #define IMPLEMENT_I2D_BIO(type, name, i2d_func) \ |
214 | 0 | int name(BIO *bio, type *obj) { \ |
215 | 0 | uint8_t *data = NULL; \ |
216 | 0 | int len = i2d_func(obj, &data); \ |
217 | 0 | if (len < 0) { \ |
218 | 0 | return 0; \ |
219 | 0 | } \ |
220 | 0 | int ret = BIO_write_all(bio, data, len); \ |
221 | 0 | OPENSSL_free(data); \ |
222 | 0 | return ret; \ |
223 | 0 | } Unexecuted instantiation: i2d_X509_bio Unexecuted instantiation: i2d_RSAPrivateKey_bio Unexecuted instantiation: i2d_RSAPublicKey_bio Unexecuted instantiation: i2d_RSA_PUBKEY_bio Unexecuted instantiation: i2d_DSAPrivateKey_bio Unexecuted instantiation: i2d_DSA_PUBKEY_bio Unexecuted instantiation: i2d_ECPrivateKey_bio Unexecuted instantiation: i2d_EC_PUBKEY_bio Unexecuted instantiation: i2d_PKCS8_bio Unexecuted instantiation: i2d_PKCS8_PRIV_KEY_INFO_bio Unexecuted instantiation: i2d_PrivateKey_bio Unexecuted instantiation: i2d_PUBKEY_bio Unexecuted instantiation: i2d_DHparams_bio |
224 | | |
225 | | IMPLEMENT_D2I_BIO(X509, d2i_X509_bio, d2i_X509) |
226 | | IMPLEMENT_I2D_BIO(X509, i2d_X509_bio, i2d_X509) |
227 | | |
228 | | IMPLEMENT_D2I_BIO(RSA, d2i_RSAPrivateKey_bio, d2i_RSAPrivateKey) |
229 | | IMPLEMENT_I2D_BIO(RSA, i2d_RSAPrivateKey_bio, i2d_RSAPrivateKey) |
230 | | |
231 | | IMPLEMENT_D2I_BIO(RSA, d2i_RSAPublicKey_bio, d2i_RSAPublicKey) |
232 | | IMPLEMENT_I2D_BIO(RSA, i2d_RSAPublicKey_bio, i2d_RSAPublicKey) |
233 | | |
234 | | IMPLEMENT_D2I_BIO(RSA, d2i_RSA_PUBKEY_bio, d2i_RSA_PUBKEY) |
235 | | IMPLEMENT_I2D_BIO(RSA, i2d_RSA_PUBKEY_bio, i2d_RSA_PUBKEY) |
236 | | |
237 | | IMPLEMENT_D2I_FP(DSA, d2i_DSAPrivateKey_fp, d2i_DSAPrivateKey_bio) |
238 | | IMPLEMENT_I2D_FP(DSA, i2d_DSAPrivateKey_fp, i2d_DSAPrivateKey_bio) |
239 | | |
240 | | IMPLEMENT_D2I_FP(DSA, d2i_DSA_PUBKEY_fp, d2i_DSA_PUBKEY_bio) |
241 | | IMPLEMENT_I2D_FP(DSA, i2d_DSA_PUBKEY_fp, i2d_DSA_PUBKEY_bio) |
242 | | |
243 | | IMPLEMENT_D2I_BIO(DSA, d2i_DSAPrivateKey_bio, d2i_DSAPrivateKey) |
244 | | IMPLEMENT_I2D_BIO(DSA, i2d_DSAPrivateKey_bio, i2d_DSAPrivateKey) |
245 | | |
246 | | IMPLEMENT_D2I_BIO(DSA, d2i_DSA_PUBKEY_bio, d2i_DSA_PUBKEY) |
247 | | IMPLEMENT_I2D_BIO(DSA, i2d_DSA_PUBKEY_bio, i2d_DSA_PUBKEY) |
248 | | |
249 | | IMPLEMENT_D2I_FP(EC_KEY, d2i_ECPrivateKey_fp, d2i_ECPrivateKey_bio) |
250 | | IMPLEMENT_I2D_FP(EC_KEY, i2d_ECPrivateKey_fp, i2d_ECPrivateKey_bio) |
251 | | |
252 | | IMPLEMENT_D2I_FP(EC_KEY, d2i_EC_PUBKEY_fp, d2i_EC_PUBKEY_bio) |
253 | | IMPLEMENT_I2D_FP(EC_KEY, i2d_EC_PUBKEY_fp, i2d_EC_PUBKEY_bio) |
254 | | |
255 | | IMPLEMENT_D2I_BIO(EC_KEY, d2i_ECPrivateKey_bio, d2i_ECPrivateKey) |
256 | | IMPLEMENT_I2D_BIO(EC_KEY, i2d_ECPrivateKey_bio, i2d_ECPrivateKey) |
257 | | |
258 | | IMPLEMENT_D2I_BIO(EC_KEY, d2i_EC_PUBKEY_bio, d2i_EC_PUBKEY) |
259 | | IMPLEMENT_I2D_BIO(EC_KEY, i2d_EC_PUBKEY_bio, i2d_EC_PUBKEY) |
260 | | |
261 | | int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
262 | 0 | unsigned int *len) { |
263 | 0 | ASN1_BIT_STRING *key; |
264 | 0 | key = X509_get0_pubkey_bitstr(data); |
265 | 0 | if (!key) { |
266 | 0 | return 0; |
267 | 0 | } |
268 | 0 | return EVP_Digest(key->data, key->length, md, len, type, NULL); |
269 | 0 | } |
270 | | |
271 | | int X509_digest(const X509 *x509, const EVP_MD *md, uint8_t *out, |
272 | 2.54k | unsigned *out_len) { |
273 | 2.54k | uint8_t *der = NULL; |
274 | | // TODO(https://crbug.com/boringssl/407): This function is not const-correct. |
275 | 2.54k | int der_len = i2d_X509((X509 *)x509, &der); |
276 | 2.54k | if (der_len < 0) { |
277 | 0 | return 0; |
278 | 0 | } |
279 | | |
280 | 2.54k | int ret = EVP_Digest(der, der_len, out, out_len, md, NULL); |
281 | 2.54k | OPENSSL_free(der); |
282 | 2.54k | return ret; |
283 | 2.54k | } |
284 | | |
285 | | int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, |
286 | 0 | unsigned int *len) { |
287 | 0 | return ( |
288 | 0 | ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, md, len)); |
289 | 0 | } |
290 | | |
291 | | int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, |
292 | 0 | unsigned int *len) { |
293 | 0 | return ( |
294 | 0 | ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ), type, (char *)data, md, len)); |
295 | 0 | } |
296 | | |
297 | | int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, |
298 | 0 | unsigned char *md, unsigned int *len) { |
299 | 0 | return ( |
300 | 0 | ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME), type, (char *)data, md, len)); |
301 | 0 | } |
302 | | |
303 | | IMPLEMENT_D2I_FP(X509_SIG, d2i_PKCS8_fp, d2i_PKCS8_bio) |
304 | | IMPLEMENT_I2D_FP(X509_SIG, i2d_PKCS8_fp, i2d_PKCS8_bio) |
305 | | |
306 | | IMPLEMENT_D2I_BIO(X509_SIG, d2i_PKCS8_bio, d2i_X509_SIG) |
307 | | IMPLEMENT_I2D_BIO(X509_SIG, i2d_PKCS8_bio, i2d_X509_SIG) |
308 | | |
309 | | IMPLEMENT_D2I_FP(PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_fp, |
310 | | d2i_PKCS8_PRIV_KEY_INFO_bio) |
311 | | IMPLEMENT_I2D_FP(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO_fp, |
312 | | i2d_PKCS8_PRIV_KEY_INFO_bio) |
313 | | |
314 | 0 | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) { |
315 | 0 | PKCS8_PRIV_KEY_INFO *p8inf; |
316 | 0 | int ret; |
317 | 0 | p8inf = EVP_PKEY2PKCS8(key); |
318 | 0 | if (!p8inf) { |
319 | 0 | return 0; |
320 | 0 | } |
321 | 0 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); |
322 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
323 | 0 | return ret; |
324 | 0 | } |
325 | | |
326 | | IMPLEMENT_D2I_FP(EVP_PKEY, d2i_PrivateKey_fp, d2i_PrivateKey_bio) |
327 | | IMPLEMENT_I2D_FP(EVP_PKEY, i2d_PrivateKey_fp, i2d_PrivateKey_bio) |
328 | | |
329 | | IMPLEMENT_D2I_FP(EVP_PKEY, d2i_PUBKEY_fp, d2i_PUBKEY_bio) |
330 | | IMPLEMENT_I2D_FP(EVP_PKEY, i2d_PUBKEY_fp, i2d_PUBKEY_bio) |
331 | | |
332 | | IMPLEMENT_D2I_BIO(PKCS8_PRIV_KEY_INFO, d2i_PKCS8_PRIV_KEY_INFO_bio, |
333 | | d2i_PKCS8_PRIV_KEY_INFO) |
334 | | IMPLEMENT_I2D_BIO(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO_bio, |
335 | | i2d_PKCS8_PRIV_KEY_INFO) |
336 | | |
337 | 0 | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) { |
338 | 0 | PKCS8_PRIV_KEY_INFO *p8inf; |
339 | 0 | int ret; |
340 | 0 | p8inf = EVP_PKEY2PKCS8(key); |
341 | 0 | if (!p8inf) { |
342 | 0 | return 0; |
343 | 0 | } |
344 | 0 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); |
345 | 0 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
346 | 0 | return ret; |
347 | 0 | } |
348 | | |
349 | | IMPLEMENT_D2I_BIO(EVP_PKEY, d2i_PrivateKey_bio, d2i_AutoPrivateKey) |
350 | | IMPLEMENT_I2D_BIO(EVP_PKEY, i2d_PrivateKey_bio, i2d_PrivateKey) |
351 | | |
352 | | IMPLEMENT_D2I_BIO(EVP_PKEY, d2i_PUBKEY_bio, d2i_PUBKEY) |
353 | | IMPLEMENT_I2D_BIO(EVP_PKEY, i2d_PUBKEY_bio, i2d_PUBKEY) |
354 | | |
355 | | IMPLEMENT_D2I_BIO(DH, d2i_DHparams_bio, d2i_DHparams) |
356 | | IMPLEMENT_I2D_BIO(const DH, i2d_DHparams_bio, i2d_DHparams) |