10Sstevel@tonic-gate /* crypto/x509/x_all.c */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * This package is an SSL implementation written
60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions
110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation
130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate * the code are not to be removed.
180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate * as the author of the parts of the library used.
200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate *
230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate * are met:
260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate * must display the following acknowledgement:
330Sstevel@tonic-gate * "This product includes cryptographic software written by
340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate * being used are not cryptographic related :-).
370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate * SUCH DAMAGE.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be
550Sstevel@tonic-gate * copied and put under another distribution licence
560Sstevel@tonic-gate * [including the GNU Public Licence.]
570Sstevel@tonic-gate */
580Sstevel@tonic-gate
590Sstevel@tonic-gate #include <stdio.h>
600Sstevel@tonic-gate #undef SSLEAY_MACROS
610Sstevel@tonic-gate #include <openssl/stack.h>
620Sstevel@tonic-gate #include "cryptlib.h"
630Sstevel@tonic-gate #include <openssl/buffer.h>
640Sstevel@tonic-gate #include <openssl/asn1.h>
650Sstevel@tonic-gate #include <openssl/evp.h>
660Sstevel@tonic-gate #include <openssl/x509.h>
67*2139Sjp161948 #ifndef OPENSSL_NO_RSA
68*2139Sjp161948 #include <openssl/rsa.h>
69*2139Sjp161948 #endif
70*2139Sjp161948 #ifndef OPENSSL_NO_DSA
71*2139Sjp161948 #include <openssl/dsa.h>
72*2139Sjp161948 #endif
730Sstevel@tonic-gate
X509_verify(X509 * a,EVP_PKEY * r)740Sstevel@tonic-gate int X509_verify(X509 *a, EVP_PKEY *r)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg,
770Sstevel@tonic-gate a->signature,a->cert_info,r));
780Sstevel@tonic-gate }
790Sstevel@tonic-gate
X509_REQ_verify(X509_REQ * a,EVP_PKEY * r)800Sstevel@tonic-gate int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO),
830Sstevel@tonic-gate a->sig_alg,a->signature,a->req_info,r));
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
X509_CRL_verify(X509_CRL * a,EVP_PKEY * r)860Sstevel@tonic-gate int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
890Sstevel@tonic-gate a->sig_alg, a->signature,a->crl,r));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate
NETSCAPE_SPKI_verify(NETSCAPE_SPKI * a,EVP_PKEY * r)920Sstevel@tonic-gate int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC),
950Sstevel@tonic-gate a->sig_algor,a->signature,a->spkac,r));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
X509_sign(X509 * x,EVP_PKEY * pkey,const EVP_MD * md)980Sstevel@tonic-gate int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature,
1010Sstevel@tonic-gate x->sig_alg, x->signature, x->cert_info,pkey,md));
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
X509_REQ_sign(X509_REQ * x,EVP_PKEY * pkey,const EVP_MD * md)1040Sstevel@tonic-gate int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate return(ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL,
1070Sstevel@tonic-gate x->signature, x->req_info,pkey,md));
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate
X509_CRL_sign(X509_CRL * x,EVP_PKEY * pkey,const EVP_MD * md)1100Sstevel@tonic-gate int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
1110Sstevel@tonic-gate {
112*2139Sjp161948 x->crl->enc.modified = 1;
1130Sstevel@tonic-gate return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg,
1140Sstevel@tonic-gate x->sig_alg, x->signature, x->crl,pkey,md));
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate
NETSCAPE_SPKI_sign(NETSCAPE_SPKI * x,EVP_PKEY * pkey,const EVP_MD * md)1170Sstevel@tonic-gate int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL,
1200Sstevel@tonic-gate x->signature, x->spkac,pkey,md));
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_X509_fp(FILE * fp,X509 ** x509)1240Sstevel@tonic-gate X509 *d2i_X509_fp(FILE *fp, X509 **x509)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
i2d_X509_fp(FILE * fp,X509 * x509)1290Sstevel@tonic-gate int i2d_X509_fp(FILE *fp, X509 *x509)
1300Sstevel@tonic-gate {
1310Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509);
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate #endif
1340Sstevel@tonic-gate
d2i_X509_bio(BIO * bp,X509 ** x509)1350Sstevel@tonic-gate X509 *d2i_X509_bio(BIO *bp, X509 **x509)
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate
i2d_X509_bio(BIO * bp,X509 * x509)1400Sstevel@tonic-gate int i2d_X509_bio(BIO *bp, X509 *x509)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_X509_CRL_fp(FILE * fp,X509_CRL ** crl)1460Sstevel@tonic-gate X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate
i2d_X509_CRL_fp(FILE * fp,X509_CRL * crl)1510Sstevel@tonic-gate int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate #endif
1560Sstevel@tonic-gate
d2i_X509_CRL_bio(BIO * bp,X509_CRL ** crl)1570Sstevel@tonic-gate X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
i2d_X509_CRL_bio(BIO * bp,X509_CRL * crl)1620Sstevel@tonic-gate int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
1630Sstevel@tonic-gate {
1640Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_PKCS7_fp(FILE * fp,PKCS7 ** p7)1680Sstevel@tonic-gate PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
i2d_PKCS7_fp(FILE * fp,PKCS7 * p7)1730Sstevel@tonic-gate int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate #endif
1780Sstevel@tonic-gate
d2i_PKCS7_bio(BIO * bp,PKCS7 ** p7)1790Sstevel@tonic-gate PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate
i2d_PKCS7_bio(BIO * bp,PKCS7 * p7)1840Sstevel@tonic-gate int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_X509_REQ_fp(FILE * fp,X509_REQ ** req)1900Sstevel@tonic-gate X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
1910Sstevel@tonic-gate {
1920Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate
i2d_X509_REQ_fp(FILE * fp,X509_REQ * req)1950Sstevel@tonic-gate int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req);
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate #endif
2000Sstevel@tonic-gate
d2i_X509_REQ_bio(BIO * bp,X509_REQ ** req)2010Sstevel@tonic-gate X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate
i2d_X509_REQ_bio(BIO * bp,X509_REQ * req)2060Sstevel@tonic-gate int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_RSAPrivateKey_fp(FILE * fp,RSA ** rsa)2140Sstevel@tonic-gate RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa)
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate
i2d_RSAPrivateKey_fp(FILE * fp,RSA * rsa)2190Sstevel@tonic-gate int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa)
2200Sstevel@tonic-gate {
2210Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate
d2i_RSAPublicKey_fp(FILE * fp,RSA ** rsa)2240Sstevel@tonic-gate RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate
d2i_RSA_PUBKEY_fp(FILE * fp,RSA ** rsa)2300Sstevel@tonic-gate RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
2310Sstevel@tonic-gate {
232*2139Sjp161948 return ASN1_d2i_fp((void *(*)(void))
233*2139Sjp161948 RSA_new,(D2I_OF(void))d2i_RSA_PUBKEY, fp,
234*2139Sjp161948 (void **)rsa);
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
i2d_RSAPublicKey_fp(FILE * fp,RSA * rsa)2370Sstevel@tonic-gate int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
2380Sstevel@tonic-gate {
2390Sstevel@tonic-gate return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa);
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate
i2d_RSA_PUBKEY_fp(FILE * fp,RSA * rsa)2420Sstevel@tonic-gate int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
2430Sstevel@tonic-gate {
244*2139Sjp161948 return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY,fp,rsa);
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate #endif
2470Sstevel@tonic-gate
d2i_RSAPrivateKey_bio(BIO * bp,RSA ** rsa)2480Sstevel@tonic-gate RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
2490Sstevel@tonic-gate {
2500Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
i2d_RSAPrivateKey_bio(BIO * bp,RSA * rsa)2530Sstevel@tonic-gate int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
2540Sstevel@tonic-gate {
2550Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa);
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate
d2i_RSAPublicKey_bio(BIO * bp,RSA ** rsa)2580Sstevel@tonic-gate RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
2590Sstevel@tonic-gate {
2600Sstevel@tonic-gate return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate
d2i_RSA_PUBKEY_bio(BIO * bp,RSA ** rsa)2640Sstevel@tonic-gate RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
2650Sstevel@tonic-gate {
266*2139Sjp161948 return ASN1_d2i_bio_of(RSA,RSA_new,d2i_RSA_PUBKEY,bp,rsa);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate
i2d_RSAPublicKey_bio(BIO * bp,RSA * rsa)2690Sstevel@tonic-gate int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate
i2d_RSA_PUBKEY_bio(BIO * bp,RSA * rsa)2740Sstevel@tonic-gate int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
2750Sstevel@tonic-gate {
276*2139Sjp161948 return ASN1_i2d_bio_of(RSA,i2d_RSA_PUBKEY,bp,rsa);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate #endif
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
2810Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_DSAPrivateKey_fp(FILE * fp,DSA ** dsa)2820Sstevel@tonic-gate DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
2830Sstevel@tonic-gate {
284*2139Sjp161948 return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSAPrivateKey,fp,dsa);
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate
i2d_DSAPrivateKey_fp(FILE * fp,DSA * dsa)2870Sstevel@tonic-gate int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
2880Sstevel@tonic-gate {
289*2139Sjp161948 return ASN1_i2d_fp_of_const(DSA,i2d_DSAPrivateKey,fp,dsa);
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate
d2i_DSA_PUBKEY_fp(FILE * fp,DSA ** dsa)2920Sstevel@tonic-gate DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
2930Sstevel@tonic-gate {
294*2139Sjp161948 return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSA_PUBKEY,fp,dsa);
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate
i2d_DSA_PUBKEY_fp(FILE * fp,DSA * dsa)2970Sstevel@tonic-gate int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
2980Sstevel@tonic-gate {
299*2139Sjp161948 return ASN1_i2d_fp_of(DSA,i2d_DSA_PUBKEY,fp,dsa);
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate #endif
3020Sstevel@tonic-gate
d2i_DSAPrivateKey_bio(BIO * bp,DSA ** dsa)3030Sstevel@tonic-gate DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
3040Sstevel@tonic-gate {
305*2139Sjp161948 return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAPrivateKey,bp,dsa
306*2139Sjp161948 );
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate
i2d_DSAPrivateKey_bio(BIO * bp,DSA * dsa)3090Sstevel@tonic-gate int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
3100Sstevel@tonic-gate {
311*2139Sjp161948 return ASN1_i2d_bio_of_const(DSA,i2d_DSAPrivateKey,bp,dsa);
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate
d2i_DSA_PUBKEY_bio(BIO * bp,DSA ** dsa)3140Sstevel@tonic-gate DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
3150Sstevel@tonic-gate {
316*2139Sjp161948 return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSA_PUBKEY,bp,dsa);
3170Sstevel@tonic-gate }
3180Sstevel@tonic-gate
i2d_DSA_PUBKEY_bio(BIO * bp,DSA * dsa)3190Sstevel@tonic-gate int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
3200Sstevel@tonic-gate {
321*2139Sjp161948 return ASN1_i2d_bio_of(DSA,i2d_DSA_PUBKEY,bp,dsa);
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate #endif
3250Sstevel@tonic-gate
326*2139Sjp161948 #ifndef OPENSSL_NO_EC
327*2139Sjp161948 #ifndef OPENSSL_NO_FP_API
d2i_EC_PUBKEY_fp(FILE * fp,EC_KEY ** eckey)328*2139Sjp161948 EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey)
329*2139Sjp161948 {
330*2139Sjp161948 return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,fp,eckey);
331*2139Sjp161948 }
332*2139Sjp161948
i2d_EC_PUBKEY_fp(FILE * fp,EC_KEY * eckey)333*2139Sjp161948 int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey)
334*2139Sjp161948 {
335*2139Sjp161948 return ASN1_i2d_fp_of(EC_KEY,i2d_EC_PUBKEY,fp,eckey);
336*2139Sjp161948 }
337*2139Sjp161948
d2i_ECPrivateKey_fp(FILE * fp,EC_KEY ** eckey)338*2139Sjp161948 EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey)
339*2139Sjp161948 {
340*2139Sjp161948 return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,fp,eckey);
341*2139Sjp161948 }
342*2139Sjp161948
i2d_ECPrivateKey_fp(FILE * fp,EC_KEY * eckey)343*2139Sjp161948 int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey)
344*2139Sjp161948 {
345*2139Sjp161948 return ASN1_i2d_fp_of(EC_KEY,i2d_ECPrivateKey,fp,eckey);
346*2139Sjp161948 }
347*2139Sjp161948 #endif
d2i_EC_PUBKEY_bio(BIO * bp,EC_KEY ** eckey)348*2139Sjp161948 EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey)
349*2139Sjp161948 {
350*2139Sjp161948 return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,bp,eckey);
351*2139Sjp161948 }
352*2139Sjp161948
i2d_EC_PUBKEY_bio(BIO * bp,EC_KEY * ecdsa)353*2139Sjp161948 int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa)
354*2139Sjp161948 {
355*2139Sjp161948 return ASN1_i2d_bio_of(EC_KEY,i2d_EC_PUBKEY,bp,ecdsa);
356*2139Sjp161948 }
357*2139Sjp161948
d2i_ECPrivateKey_bio(BIO * bp,EC_KEY ** eckey)358*2139Sjp161948 EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey)
359*2139Sjp161948 {
360*2139Sjp161948 return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,bp,eckey);
361*2139Sjp161948 }
362*2139Sjp161948
i2d_ECPrivateKey_bio(BIO * bp,EC_KEY * eckey)363*2139Sjp161948 int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey)
364*2139Sjp161948 {
365*2139Sjp161948 return ASN1_i2d_bio_of(EC_KEY,i2d_ECPrivateKey,bp,eckey);
366*2139Sjp161948 }
367*2139Sjp161948 #endif
368*2139Sjp161948
369*2139Sjp161948
X509_pubkey_digest(const X509 * data,const EVP_MD * type,unsigned char * md,unsigned int * len)3700Sstevel@tonic-gate int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
3710Sstevel@tonic-gate unsigned int *len)
3720Sstevel@tonic-gate {
3730Sstevel@tonic-gate ASN1_BIT_STRING *key;
3740Sstevel@tonic-gate key = X509_get0_pubkey_bitstr(data);
3750Sstevel@tonic-gate if(!key) return 0;
3760Sstevel@tonic-gate return EVP_Digest(key->data, key->length, md, len, type, NULL);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
X509_digest(const X509 * data,const EVP_MD * type,unsigned char * md,unsigned int * len)3790Sstevel@tonic-gate int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
3800Sstevel@tonic-gate unsigned int *len)
3810Sstevel@tonic-gate {
3820Sstevel@tonic-gate return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len));
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate
X509_CRL_digest(const X509_CRL * data,const EVP_MD * type,unsigned char * md,unsigned int * len)3850Sstevel@tonic-gate int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md,
3860Sstevel@tonic-gate unsigned int *len)
3870Sstevel@tonic-gate {
3880Sstevel@tonic-gate return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len));
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate
X509_REQ_digest(const X509_REQ * data,const EVP_MD * type,unsigned char * md,unsigned int * len)3910Sstevel@tonic-gate int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md,
3920Sstevel@tonic-gate unsigned int *len)
3930Sstevel@tonic-gate {
3940Sstevel@tonic-gate return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len));
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate
X509_NAME_digest(const X509_NAME * data,const EVP_MD * type,unsigned char * md,unsigned int * len)3970Sstevel@tonic-gate int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md,
3980Sstevel@tonic-gate unsigned int *len)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len));
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate
PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL * data,const EVP_MD * type,unsigned char * md,unsigned int * len)4030Sstevel@tonic-gate int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type,
4040Sstevel@tonic-gate unsigned char *md, unsigned int *len)
4050Sstevel@tonic-gate {
4060Sstevel@tonic-gate return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type,
4070Sstevel@tonic-gate (char *)data,md,len));
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_PKCS8_fp(FILE * fp,X509_SIG ** p8)4120Sstevel@tonic-gate X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
4130Sstevel@tonic-gate {
414*2139Sjp161948 return ASN1_d2i_fp_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,fp,p8);
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
i2d_PKCS8_fp(FILE * fp,X509_SIG * p8)4170Sstevel@tonic-gate int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
4180Sstevel@tonic-gate {
419*2139Sjp161948 return ASN1_i2d_fp_of(X509_SIG,i2d_X509_SIG,fp,p8);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate #endif
4220Sstevel@tonic-gate
d2i_PKCS8_bio(BIO * bp,X509_SIG ** p8)4230Sstevel@tonic-gate X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
4240Sstevel@tonic-gate {
425*2139Sjp161948 return ASN1_d2i_bio_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,bp,p8);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate
i2d_PKCS8_bio(BIO * bp,X509_SIG * p8)4280Sstevel@tonic-gate int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
4290Sstevel@tonic-gate {
430*2139Sjp161948 return ASN1_i2d_bio_of(X509_SIG,i2d_X509_SIG,bp,p8);
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate #ifndef OPENSSL_NO_FP_API
d2i_PKCS8_PRIV_KEY_INFO_fp(FILE * fp,PKCS8_PRIV_KEY_INFO ** p8inf)4340Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
4350Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO **p8inf)
4360Sstevel@tonic-gate {
437*2139Sjp161948 return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new,
438*2139Sjp161948 d2i_PKCS8_PRIV_KEY_INFO,fp,p8inf);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
i2d_PKCS8_PRIV_KEY_INFO_fp(FILE * fp,PKCS8_PRIV_KEY_INFO * p8inf)4410Sstevel@tonic-gate int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
4420Sstevel@tonic-gate {
443*2139Sjp161948 return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,fp,
444*2139Sjp161948 p8inf);
4450Sstevel@tonic-gate }
4460Sstevel@tonic-gate
i2d_PKCS8PrivateKeyInfo_fp(FILE * fp,EVP_PKEY * key)4470Sstevel@tonic-gate int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
4480Sstevel@tonic-gate {
4490Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO *p8inf;
4500Sstevel@tonic-gate int ret;
4510Sstevel@tonic-gate p8inf = EVP_PKEY2PKCS8(key);
4520Sstevel@tonic-gate if(!p8inf) return 0;
4530Sstevel@tonic-gate ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf);
4540Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO_free(p8inf);
4550Sstevel@tonic-gate return ret;
4560Sstevel@tonic-gate }
4570Sstevel@tonic-gate
i2d_PrivateKey_fp(FILE * fp,EVP_PKEY * pkey)4580Sstevel@tonic-gate int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
4590Sstevel@tonic-gate {
460*2139Sjp161948 return ASN1_i2d_fp_of(EVP_PKEY,i2d_PrivateKey,fp,pkey);
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate
d2i_PrivateKey_fp(FILE * fp,EVP_PKEY ** a)4630Sstevel@tonic-gate EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
4640Sstevel@tonic-gate {
465*2139Sjp161948 return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,fp,a);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate
i2d_PUBKEY_fp(FILE * fp,EVP_PKEY * pkey)4680Sstevel@tonic-gate int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
4690Sstevel@tonic-gate {
470*2139Sjp161948 return ASN1_i2d_fp_of(EVP_PKEY,i2d_PUBKEY,fp,pkey);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate
d2i_PUBKEY_fp(FILE * fp,EVP_PKEY ** a)4730Sstevel@tonic-gate EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
4740Sstevel@tonic-gate {
475*2139Sjp161948 return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,fp,a);
4760Sstevel@tonic-gate }
4770Sstevel@tonic-gate
4780Sstevel@tonic-gate #endif
4790Sstevel@tonic-gate
d2i_PKCS8_PRIV_KEY_INFO_bio(BIO * bp,PKCS8_PRIV_KEY_INFO ** p8inf)4800Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
4810Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO **p8inf)
4820Sstevel@tonic-gate {
483*2139Sjp161948 return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new,
484*2139Sjp161948 d2i_PKCS8_PRIV_KEY_INFO,bp,p8inf);
4850Sstevel@tonic-gate }
4860Sstevel@tonic-gate
i2d_PKCS8_PRIV_KEY_INFO_bio(BIO * bp,PKCS8_PRIV_KEY_INFO * p8inf)4870Sstevel@tonic-gate int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
4880Sstevel@tonic-gate {
489*2139Sjp161948 return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,bp,
490*2139Sjp161948 p8inf);
4910Sstevel@tonic-gate }
4920Sstevel@tonic-gate
i2d_PKCS8PrivateKeyInfo_bio(BIO * bp,EVP_PKEY * key)4930Sstevel@tonic-gate int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
4940Sstevel@tonic-gate {
4950Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO *p8inf;
4960Sstevel@tonic-gate int ret;
4970Sstevel@tonic-gate p8inf = EVP_PKEY2PKCS8(key);
4980Sstevel@tonic-gate if(!p8inf) return 0;
4990Sstevel@tonic-gate ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
5000Sstevel@tonic-gate PKCS8_PRIV_KEY_INFO_free(p8inf);
5010Sstevel@tonic-gate return ret;
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate
i2d_PrivateKey_bio(BIO * bp,EVP_PKEY * pkey)5040Sstevel@tonic-gate int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
5050Sstevel@tonic-gate {
506*2139Sjp161948 return ASN1_i2d_bio_of(EVP_PKEY,i2d_PrivateKey,bp,pkey);
5070Sstevel@tonic-gate }
5080Sstevel@tonic-gate
d2i_PrivateKey_bio(BIO * bp,EVP_PKEY ** a)5090Sstevel@tonic-gate EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
5100Sstevel@tonic-gate {
511*2139Sjp161948 return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,bp,a);
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate
i2d_PUBKEY_bio(BIO * bp,EVP_PKEY * pkey)5140Sstevel@tonic-gate int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
5150Sstevel@tonic-gate {
516*2139Sjp161948 return ASN1_i2d_bio_of(EVP_PKEY,i2d_PUBKEY,bp,pkey);
5170Sstevel@tonic-gate }
5180Sstevel@tonic-gate
d2i_PUBKEY_bio(BIO * bp,EVP_PKEY ** a)5190Sstevel@tonic-gate EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a)
5200Sstevel@tonic-gate {
521*2139Sjp161948 return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,bp,a);
5220Sstevel@tonic-gate }
523