xref: /onnv-gate/usr/src/common/openssl/crypto/pem/pem.h (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* crypto/pem/pem.h */
20Sstevel@tonic-gate /* Copyright (C) 1995-1997 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 #ifndef HEADER_PEM_H
600Sstevel@tonic-gate #define HEADER_PEM_H
610Sstevel@tonic-gate 
62*2139Sjp161948 #include <openssl/e_os2.h>
630Sstevel@tonic-gate #ifndef OPENSSL_NO_BIO
640Sstevel@tonic-gate #include <openssl/bio.h>
650Sstevel@tonic-gate #endif
660Sstevel@tonic-gate #ifndef OPENSSL_NO_STACK
670Sstevel@tonic-gate #include <openssl/stack.h>
680Sstevel@tonic-gate #endif
690Sstevel@tonic-gate #include <openssl/evp.h>
700Sstevel@tonic-gate #include <openssl/x509.h>
710Sstevel@tonic-gate #include <openssl/pem2.h>
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #ifdef  __cplusplus
740Sstevel@tonic-gate extern "C" {
750Sstevel@tonic-gate #endif
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #define PEM_BUFSIZE		1024
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define PEM_OBJ_UNDEF		0
800Sstevel@tonic-gate #define PEM_OBJ_X509		1
810Sstevel@tonic-gate #define PEM_OBJ_X509_REQ	2
820Sstevel@tonic-gate #define PEM_OBJ_CRL		3
830Sstevel@tonic-gate #define PEM_OBJ_SSL_SESSION	4
840Sstevel@tonic-gate #define PEM_OBJ_PRIV_KEY	10
850Sstevel@tonic-gate #define PEM_OBJ_PRIV_RSA	11
860Sstevel@tonic-gate #define PEM_OBJ_PRIV_DSA	12
870Sstevel@tonic-gate #define PEM_OBJ_PRIV_DH		13
880Sstevel@tonic-gate #define PEM_OBJ_PUB_RSA		14
890Sstevel@tonic-gate #define PEM_OBJ_PUB_DSA		15
900Sstevel@tonic-gate #define PEM_OBJ_PUB_DH		16
910Sstevel@tonic-gate #define PEM_OBJ_DHPARAMS	17
920Sstevel@tonic-gate #define PEM_OBJ_DSAPARAMS	18
930Sstevel@tonic-gate #define PEM_OBJ_PRIV_RSA_PUBLIC	19
94*2139Sjp161948 #define PEM_OBJ_PRIV_ECDSA	20
95*2139Sjp161948 #define PEM_OBJ_PUB_ECDSA	21
96*2139Sjp161948 #define PEM_OBJ_ECPARAMETERS	22
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #define PEM_ERROR		30
990Sstevel@tonic-gate #define PEM_DEK_DES_CBC         40
1000Sstevel@tonic-gate #define PEM_DEK_IDEA_CBC        45
1010Sstevel@tonic-gate #define PEM_DEK_DES_EDE         50
1020Sstevel@tonic-gate #define PEM_DEK_DES_ECB         60
1030Sstevel@tonic-gate #define PEM_DEK_RSA             70
1040Sstevel@tonic-gate #define PEM_DEK_RSA_MD2         80
1050Sstevel@tonic-gate #define PEM_DEK_RSA_MD5         90
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define PEM_MD_MD2		NID_md2
1080Sstevel@tonic-gate #define PEM_MD_MD5		NID_md5
1090Sstevel@tonic-gate #define PEM_MD_SHA		NID_sha
1100Sstevel@tonic-gate #define PEM_MD_MD2_RSA		NID_md2WithRSAEncryption
1110Sstevel@tonic-gate #define PEM_MD_MD5_RSA		NID_md5WithRSAEncryption
1120Sstevel@tonic-gate #define PEM_MD_SHA_RSA		NID_sha1WithRSAEncryption
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #define PEM_STRING_X509_OLD	"X509 CERTIFICATE"
1150Sstevel@tonic-gate #define PEM_STRING_X509		"CERTIFICATE"
116*2139Sjp161948 #define PEM_STRING_X509_PAIR	"CERTIFICATE PAIR"
1170Sstevel@tonic-gate #define PEM_STRING_X509_TRUSTED	"TRUSTED CERTIFICATE"
1180Sstevel@tonic-gate #define PEM_STRING_X509_REQ_OLD	"NEW CERTIFICATE REQUEST"
1190Sstevel@tonic-gate #define PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
1200Sstevel@tonic-gate #define PEM_STRING_X509_CRL	"X509 CRL"
1210Sstevel@tonic-gate #define PEM_STRING_EVP_PKEY	"ANY PRIVATE KEY"
1220Sstevel@tonic-gate #define PEM_STRING_PUBLIC	"PUBLIC KEY"
1230Sstevel@tonic-gate #define PEM_STRING_RSA		"RSA PRIVATE KEY"
1240Sstevel@tonic-gate #define PEM_STRING_RSA_PUBLIC	"RSA PUBLIC KEY"
1250Sstevel@tonic-gate #define PEM_STRING_DSA		"DSA PRIVATE KEY"
1260Sstevel@tonic-gate #define PEM_STRING_DSA_PUBLIC	"DSA PUBLIC KEY"
1270Sstevel@tonic-gate #define PEM_STRING_PKCS7	"PKCS7"
1280Sstevel@tonic-gate #define PEM_STRING_PKCS8	"ENCRYPTED PRIVATE KEY"
1290Sstevel@tonic-gate #define PEM_STRING_PKCS8INF	"PRIVATE KEY"
1300Sstevel@tonic-gate #define PEM_STRING_DHPARAMS	"DH PARAMETERS"
1310Sstevel@tonic-gate #define PEM_STRING_SSL_SESSION	"SSL SESSION PARAMETERS"
1320Sstevel@tonic-gate #define PEM_STRING_DSAPARAMS	"DSA PARAMETERS"
133*2139Sjp161948 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
134*2139Sjp161948 #define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
135*2139Sjp161948 #define PEM_STRING_ECPRIVATEKEY	"EC PRIVATE KEY"
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate   /* Note that this structure is initialised by PEM_SealInit and cleaned up
1380Sstevel@tonic-gate      by PEM_SealFinal (at least for now) */
1390Sstevel@tonic-gate typedef struct PEM_Encode_Seal_st
1400Sstevel@tonic-gate 	{
1410Sstevel@tonic-gate 	EVP_ENCODE_CTX encode;
1420Sstevel@tonic-gate 	EVP_MD_CTX md;
1430Sstevel@tonic-gate 	EVP_CIPHER_CTX cipher;
1440Sstevel@tonic-gate 	} PEM_ENCODE_SEAL_CTX;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /* enc_type is one off */
1470Sstevel@tonic-gate #define PEM_TYPE_ENCRYPTED      10
1480Sstevel@tonic-gate #define PEM_TYPE_MIC_ONLY       20
1490Sstevel@tonic-gate #define PEM_TYPE_MIC_CLEAR      30
1500Sstevel@tonic-gate #define PEM_TYPE_CLEAR		40
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate typedef struct pem_recip_st
1530Sstevel@tonic-gate 	{
1540Sstevel@tonic-gate 	char *name;
1550Sstevel@tonic-gate 	X509_NAME *dn;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	int cipher;
1580Sstevel@tonic-gate 	int key_enc;
1590Sstevel@tonic-gate 	/*	char iv[8]; unused and wrong size */
1600Sstevel@tonic-gate 	} PEM_USER;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate typedef struct pem_ctx_st
1630Sstevel@tonic-gate 	{
1640Sstevel@tonic-gate 	int type;		/* what type of object */
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	struct	{
1670Sstevel@tonic-gate 		int version;
1680Sstevel@tonic-gate 		int mode;
1690Sstevel@tonic-gate 		} proc_type;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	char *domain;
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 	struct	{
1740Sstevel@tonic-gate 		int cipher;
1750Sstevel@tonic-gate 	/* unused, and wrong size
1760Sstevel@tonic-gate 	   unsigned char iv[8]; */
1770Sstevel@tonic-gate 		} DEK_info;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	PEM_USER *originator;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	int num_recipient;
1820Sstevel@tonic-gate 	PEM_USER **recipient;
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #ifndef OPENSSL_NO_STACK
1850Sstevel@tonic-gate 	STACK *x509_chain;	/* certificate chain */
1860Sstevel@tonic-gate #else
1870Sstevel@tonic-gate 	char *x509_chain;	/* certificate chain */
1880Sstevel@tonic-gate #endif
1890Sstevel@tonic-gate 	EVP_MD *md;		/* signature type */
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	int md_enc;		/* is the md encrypted or not? */
1920Sstevel@tonic-gate 	int md_len;		/* length of md_data */
1930Sstevel@tonic-gate 	char *md_data;		/* message digest, could be pkey encrypted */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	EVP_CIPHER *dec;	/* date encryption cipher */
1960Sstevel@tonic-gate 	int key_len;		/* key length */
1970Sstevel@tonic-gate 	unsigned char *key;	/* key */
1980Sstevel@tonic-gate 	/* unused, and wrong size
1990Sstevel@tonic-gate 	   unsigned char iv[8]; */
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	int  data_enc;		/* is the data encrypted */
2030Sstevel@tonic-gate 	int data_len;
2040Sstevel@tonic-gate 	unsigned char *data;
2050Sstevel@tonic-gate 	} PEM_CTX;
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate /* These macros make the PEM_read/PEM_write functions easier to maintain and
2080Sstevel@tonic-gate  * write. Now they are all implemented with either:
2090Sstevel@tonic-gate  * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
2100Sstevel@tonic-gate  */
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #ifdef OPENSSL_NO_FP_API
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
2150Sstevel@tonic-gate #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
2160Sstevel@tonic-gate #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate #else
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
2210Sstevel@tonic-gate type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
2220Sstevel@tonic-gate { \
223*2139Sjp161948 return(((type *(*)(D2I_OF(type),char *,FILE *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read))(d2i_##asn1, str,fp,x,cb,u)); \
2240Sstevel@tonic-gate } \
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
2270Sstevel@tonic-gate int PEM_write_##name(FILE *fp, type *x) \
2280Sstevel@tonic-gate { \
229*2139Sjp161948 return(((int (*)(I2D_OF(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL)); \
230*2139Sjp161948 }
231*2139Sjp161948 
232*2139Sjp161948 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
233*2139Sjp161948 int PEM_write_##name(FILE *fp, const type *x) \
234*2139Sjp161948 { \
235*2139Sjp161948 return(((int (*)(I2D_OF_const(type),const char *,FILE *, const type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL)); \
236*2139Sjp161948 }
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
2390Sstevel@tonic-gate int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
2400Sstevel@tonic-gate 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
2410Sstevel@tonic-gate 		  void *u) \
2420Sstevel@tonic-gate 	{ \
243*2139Sjp161948 	return(((int (*)(I2D_OF(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u)); \
244*2139Sjp161948 	}
245*2139Sjp161948 
246*2139Sjp161948 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
247*2139Sjp161948 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
248*2139Sjp161948 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
249*2139Sjp161948 		  void *u) \
250*2139Sjp161948 	{ \
251*2139Sjp161948 	return(((int (*)(I2D_OF_const(type),const char *,FILE *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write))(i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u)); \
2520Sstevel@tonic-gate 	}
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate #endif
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
2570Sstevel@tonic-gate type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
2580Sstevel@tonic-gate { \
259*2139Sjp161948 return(((type *(*)(D2I_OF(type),const char *,BIO *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read_bio))(d2i_##asn1, str,bp,x,cb,u)); \
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
2630Sstevel@tonic-gate int PEM_write_bio_##name(BIO *bp, type *x) \
2640Sstevel@tonic-gate { \
265*2139Sjp161948 return(((int (*)(I2D_OF(type),const char *,BIO *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL)); \
266*2139Sjp161948 }
267*2139Sjp161948 
268*2139Sjp161948 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
269*2139Sjp161948 int PEM_write_bio_##name(BIO *bp, const type *x) \
270*2139Sjp161948 { \
271*2139Sjp161948 return(((int (*)(I2D_OF_const(type),const char *,BIO *,const type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL)); \
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
2750Sstevel@tonic-gate int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
2760Sstevel@tonic-gate 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
2770Sstevel@tonic-gate 	{ \
278*2139Sjp161948 	return(((int (*)(I2D_OF(type),const char *,BIO *,type *,const EVP_CIPHER *,unsigned char *,int,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u)); \
279*2139Sjp161948 	}
280*2139Sjp161948 
281*2139Sjp161948 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
282*2139Sjp161948 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
283*2139Sjp161948 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
284*2139Sjp161948 	{ \
285*2139Sjp161948 	return(((int (*)(I2D_OF_const(type),const char *,BIO *,type *,const EVP_CIPHER *,unsigned char *,int,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u)); \
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate #define IMPLEMENT_PEM_write(name, type, str, asn1) \
2890Sstevel@tonic-gate 	IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
2900Sstevel@tonic-gate 	IMPLEMENT_PEM_write_fp(name, type, str, asn1)
2910Sstevel@tonic-gate 
292*2139Sjp161948 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
293*2139Sjp161948 	IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
294*2139Sjp161948 	IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
295*2139Sjp161948 
2960Sstevel@tonic-gate #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
2970Sstevel@tonic-gate 	IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
2980Sstevel@tonic-gate 	IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
2990Sstevel@tonic-gate 
300*2139Sjp161948 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
301*2139Sjp161948 	IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
302*2139Sjp161948 	IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
303*2139Sjp161948 
3040Sstevel@tonic-gate #define IMPLEMENT_PEM_read(name, type, str, asn1) \
3050Sstevel@tonic-gate 	IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
3060Sstevel@tonic-gate 	IMPLEMENT_PEM_read_fp(name, type, str, asn1)
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
3090Sstevel@tonic-gate 	IMPLEMENT_PEM_read(name, type, str, asn1) \
3100Sstevel@tonic-gate 	IMPLEMENT_PEM_write(name, type, str, asn1)
3110Sstevel@tonic-gate 
312*2139Sjp161948 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
313*2139Sjp161948 	IMPLEMENT_PEM_read(name, type, str, asn1) \
314*2139Sjp161948 	IMPLEMENT_PEM_write_const(name, type, str, asn1)
315*2139Sjp161948 
3160Sstevel@tonic-gate #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
3170Sstevel@tonic-gate 	IMPLEMENT_PEM_read(name, type, str, asn1) \
3180Sstevel@tonic-gate 	IMPLEMENT_PEM_write_cb(name, type, str, asn1)
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate /* These are the same except they are for the declarations */
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate #if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate #define DECLARE_PEM_read_fp(name, type) /**/
3250Sstevel@tonic-gate #define DECLARE_PEM_write_fp(name, type) /**/
3260Sstevel@tonic-gate #define DECLARE_PEM_write_cb_fp(name, type) /**/
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate #else
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate #define DECLARE_PEM_read_fp(name, type) \
3310Sstevel@tonic-gate 	type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate #define DECLARE_PEM_write_fp(name, type) \
3340Sstevel@tonic-gate 	int PEM_write_##name(FILE *fp, type *x);
3350Sstevel@tonic-gate 
336*2139Sjp161948 #define DECLARE_PEM_write_fp_const(name, type) \
337*2139Sjp161948 	int PEM_write_##name(FILE *fp, const type *x);
338*2139Sjp161948 
3390Sstevel@tonic-gate #define DECLARE_PEM_write_cb_fp(name, type) \
3400Sstevel@tonic-gate 	int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
3410Sstevel@tonic-gate 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate #endif
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate #ifndef OPENSSL_NO_BIO
3460Sstevel@tonic-gate #define DECLARE_PEM_read_bio(name, type) \
3470Sstevel@tonic-gate 	type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate #define DECLARE_PEM_write_bio(name, type) \
3500Sstevel@tonic-gate 	int PEM_write_bio_##name(BIO *bp, type *x);
3510Sstevel@tonic-gate 
352*2139Sjp161948 #define DECLARE_PEM_write_bio_const(name, type) \
353*2139Sjp161948 	int PEM_write_bio_##name(BIO *bp, const type *x);
354*2139Sjp161948 
3550Sstevel@tonic-gate #define DECLARE_PEM_write_cb_bio(name, type) \
3560Sstevel@tonic-gate 	int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
3570Sstevel@tonic-gate 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate #else
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate #define DECLARE_PEM_read_bio(name, type) /**/
3620Sstevel@tonic-gate #define DECLARE_PEM_write_bio(name, type) /**/
3630Sstevel@tonic-gate #define DECLARE_PEM_write_cb_bio(name, type) /**/
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate #endif
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate #define DECLARE_PEM_write(name, type) \
3680Sstevel@tonic-gate 	DECLARE_PEM_write_bio(name, type) \
3690Sstevel@tonic-gate 	DECLARE_PEM_write_fp(name, type)
3700Sstevel@tonic-gate 
371*2139Sjp161948 #define DECLARE_PEM_write_const(name, type) \
372*2139Sjp161948 	DECLARE_PEM_write_bio_const(name, type) \
373*2139Sjp161948 	DECLARE_PEM_write_fp_const(name, type)
374*2139Sjp161948 
3750Sstevel@tonic-gate #define DECLARE_PEM_write_cb(name, type) \
3760Sstevel@tonic-gate 	DECLARE_PEM_write_cb_bio(name, type) \
3770Sstevel@tonic-gate 	DECLARE_PEM_write_cb_fp(name, type)
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate #define DECLARE_PEM_read(name, type) \
3800Sstevel@tonic-gate 	DECLARE_PEM_read_bio(name, type) \
3810Sstevel@tonic-gate 	DECLARE_PEM_read_fp(name, type)
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate #define DECLARE_PEM_rw(name, type) \
3840Sstevel@tonic-gate 	DECLARE_PEM_read(name, type) \
3850Sstevel@tonic-gate 	DECLARE_PEM_write(name, type)
3860Sstevel@tonic-gate 
387*2139Sjp161948 #define DECLARE_PEM_rw_const(name, type) \
388*2139Sjp161948 	DECLARE_PEM_read(name, type) \
389*2139Sjp161948 	DECLARE_PEM_write_const(name, type)
390*2139Sjp161948 
3910Sstevel@tonic-gate #define DECLARE_PEM_rw_cb(name, type) \
3920Sstevel@tonic-gate 	DECLARE_PEM_read(name, type) \
3930Sstevel@tonic-gate 	DECLARE_PEM_write_cb(name, type)
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate #ifdef SSLEAY_MACROS
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate #define PEM_write_SSL_SESSION(fp,x) \
3980Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
3990Sstevel@tonic-gate 			PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
4000Sstevel@tonic-gate #define PEM_write_X509(fp,x) \
4010Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
4020Sstevel@tonic-gate 			(char *)x, NULL,NULL,0,NULL,NULL)
4030Sstevel@tonic-gate #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
4040Sstevel@tonic-gate 		(int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
4050Sstevel@tonic-gate 			NULL,NULL,0,NULL,NULL)
4060Sstevel@tonic-gate #define PEM_write_X509_CRL(fp,x) \
4070Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
4080Sstevel@tonic-gate 			fp,(char *)x, NULL,NULL,0,NULL,NULL)
4090Sstevel@tonic-gate #define	PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
4100Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
4110Sstevel@tonic-gate 			(char *)x,enc,kstr,klen,cb,u)
4120Sstevel@tonic-gate #define	PEM_write_RSAPublicKey(fp,x) \
4130Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
4140Sstevel@tonic-gate 			PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
4150Sstevel@tonic-gate #define	PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
4160Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
4170Sstevel@tonic-gate 			(char *)x,enc,kstr,klen,cb,u)
4180Sstevel@tonic-gate #define	PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
4190Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_PrivateKey,\
4200Sstevel@tonic-gate 		(((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
4210Sstevel@tonic-gate 			bp,(char *)x,enc,kstr,klen,cb,u)
4220Sstevel@tonic-gate #define PEM_write_PKCS7(fp,x) \
4230Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
4240Sstevel@tonic-gate 			(char *)x, NULL,NULL,0,NULL,NULL)
4250Sstevel@tonic-gate #define PEM_write_DHparams(fp,x) \
4260Sstevel@tonic-gate 		PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
4270Sstevel@tonic-gate 			(char *)x,NULL,NULL,0,NULL,NULL)
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate #define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
4300Sstevel@tonic-gate                 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
4310Sstevel@tonic-gate 			PEM_STRING_X509,fp, \
4320Sstevel@tonic-gate                         (char *)x, NULL,NULL,0,NULL,NULL)
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate #define	PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
4350Sstevel@tonic-gate 	(char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
4360Sstevel@tonic-gate #define	PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
4370Sstevel@tonic-gate 	(char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
4380Sstevel@tonic-gate #define	PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
4390Sstevel@tonic-gate 	(char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
4400Sstevel@tonic-gate #define	PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
4410Sstevel@tonic-gate 	(char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
4420Sstevel@tonic-gate #define	PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
4430Sstevel@tonic-gate 	(char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
4440Sstevel@tonic-gate #define	PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
4450Sstevel@tonic-gate 	(char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
4460Sstevel@tonic-gate #define	PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
4470Sstevel@tonic-gate 	(char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
4480Sstevel@tonic-gate #define	PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
4490Sstevel@tonic-gate 	(char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
4500Sstevel@tonic-gate #define	PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
4510Sstevel@tonic-gate 	(char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
4520Sstevel@tonic-gate #define	PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
4530Sstevel@tonic-gate 	(char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate #define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
4560Sstevel@tonic-gate 		(NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
4570Sstevel@tonic-gate         (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
4580Sstevel@tonic-gate 							(char **)x,cb,u)
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate #define PEM_write_bio_X509(bp,x) \
4610Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
4620Sstevel@tonic-gate 			(char *)x, NULL,NULL,0,NULL,NULL)
4630Sstevel@tonic-gate #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
4640Sstevel@tonic-gate 		(int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
4650Sstevel@tonic-gate 			NULL,NULL,0,NULL,NULL)
4660Sstevel@tonic-gate #define PEM_write_bio_X509_CRL(bp,x) \
4670Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
4680Sstevel@tonic-gate 			bp,(char *)x, NULL,NULL,0,NULL,NULL)
4690Sstevel@tonic-gate #define	PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
4700Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
4710Sstevel@tonic-gate 			bp,(char *)x,enc,kstr,klen,cb,u)
4720Sstevel@tonic-gate #define	PEM_write_bio_RSAPublicKey(bp,x) \
4730Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
4740Sstevel@tonic-gate 			PEM_STRING_RSA_PUBLIC,\
4750Sstevel@tonic-gate 			bp,(char *)x,NULL,NULL,0,NULL,NULL)
4760Sstevel@tonic-gate #define	PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
4770Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
4780Sstevel@tonic-gate 			bp,(char *)x,enc,kstr,klen,cb,u)
4790Sstevel@tonic-gate #define	PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
4800Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
4810Sstevel@tonic-gate 		(((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
4820Sstevel@tonic-gate 			bp,(char *)x,enc,kstr,klen,cb,u)
4830Sstevel@tonic-gate #define PEM_write_bio_PKCS7(bp,x) \
4840Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
4850Sstevel@tonic-gate 			(char *)x, NULL,NULL,0,NULL,NULL)
4860Sstevel@tonic-gate #define PEM_write_bio_DHparams(bp,x) \
4870Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
4880Sstevel@tonic-gate 			bp,(char *)x,NULL,NULL,0,NULL,NULL)
4890Sstevel@tonic-gate #define PEM_write_bio_DSAparams(bp,x) \
4900Sstevel@tonic-gate 		PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
4910Sstevel@tonic-gate 			PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate #define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
4940Sstevel@tonic-gate                 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
4950Sstevel@tonic-gate 			PEM_STRING_X509,bp, \
4960Sstevel@tonic-gate                         (char *)x, NULL,NULL,0,NULL,NULL)
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate #define	PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
4990Sstevel@tonic-gate 	(char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
5000Sstevel@tonic-gate #define	PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
5010Sstevel@tonic-gate 	(char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
5020Sstevel@tonic-gate #define	PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
5030Sstevel@tonic-gate 	(char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
5040Sstevel@tonic-gate #define	PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
5050Sstevel@tonic-gate 	(char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
5060Sstevel@tonic-gate #define	PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
5070Sstevel@tonic-gate 	(char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
5080Sstevel@tonic-gate #define	PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
5090Sstevel@tonic-gate 	(char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
5100Sstevel@tonic-gate #define	PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
5110Sstevel@tonic-gate 	(char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate #define	PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
5140Sstevel@tonic-gate 	(char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
5150Sstevel@tonic-gate #define	PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
5160Sstevel@tonic-gate 	(char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
5170Sstevel@tonic-gate #define	PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
5180Sstevel@tonic-gate 	(char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate #define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
5210Sstevel@tonic-gate 		(NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
5220Sstevel@tonic-gate         (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
5230Sstevel@tonic-gate 							(char **)x,cb,u)
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate #endif
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate #if 1
5280Sstevel@tonic-gate /* "userdata": new with OpenSSL 0.9.4 */
5290Sstevel@tonic-gate typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
5300Sstevel@tonic-gate #else
5310Sstevel@tonic-gate /* OpenSSL 0.9.3, 0.9.3a */
5320Sstevel@tonic-gate typedef int pem_password_cb(char *buf, int size, int rwflag);
5330Sstevel@tonic-gate #endif
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate int	PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
5360Sstevel@tonic-gate int	PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
5370Sstevel@tonic-gate 	pem_password_cb *callback,void *u);
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate #ifndef OPENSSL_NO_BIO
5400Sstevel@tonic-gate int	PEM_read_bio(BIO *bp, char **name, char **header,
5410Sstevel@tonic-gate 		unsigned char **data,long *len);
5420Sstevel@tonic-gate int	PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
5430Sstevel@tonic-gate 		long len);
5440Sstevel@tonic-gate int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
5450Sstevel@tonic-gate 	     pem_password_cb *cb, void *u);
546*2139Sjp161948 void *	PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp,
547*2139Sjp161948 			  void **x, pem_password_cb *cb, void *u);
548*2139Sjp161948 #define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \
549*2139Sjp161948 ((type *(*)(D2I_OF(type),const char *,BIO *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read_bio))(d2i,name,bp,x,cb,u)
550*2139Sjp161948 int	PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,
5510Sstevel@tonic-gate 			   const EVP_CIPHER *enc,unsigned char *kstr,int klen,
5520Sstevel@tonic-gate 			   pem_password_cb *cb, void *u);
553*2139Sjp161948 #define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \
554*2139Sjp161948 	((int (*)(I2D_OF(type),const char *,BIO *,type *, const EVP_CIPHER *,unsigned char *,int, pem_password_cb *,void *))openssl_fcast(PEM_ASN1_write_bio))(i2d,name,bp,x,enc,kstr,klen,cb,u)
555*2139Sjp161948 
5560Sstevel@tonic-gate STACK_OF(X509_INFO) *	PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
5570Sstevel@tonic-gate int	PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
5580Sstevel@tonic-gate 		unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
5590Sstevel@tonic-gate #endif
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate #ifndef OPENSSL_SYS_WIN16
5620Sstevel@tonic-gate int	PEM_read(FILE *fp, char **name, char **header,
5630Sstevel@tonic-gate 		unsigned char **data,long *len);
5640Sstevel@tonic-gate int	PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
565*2139Sjp161948 void *  PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
566*2139Sjp161948 		      pem_password_cb *cb, void *u);
567*2139Sjp161948 int	PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp,
568*2139Sjp161948 		       char *x,const EVP_CIPHER *enc,unsigned char *kstr,
569*2139Sjp161948 		       int klen,pem_password_cb *callback, void *u);
5700Sstevel@tonic-gate STACK_OF(X509_INFO) *	PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
5710Sstevel@tonic-gate 	pem_password_cb *cb, void *u);
5720Sstevel@tonic-gate #endif
5730Sstevel@tonic-gate 
5740Sstevel@tonic-gate int	PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
5750Sstevel@tonic-gate 		EVP_MD *md_type, unsigned char **ek, int *ekl,
5760Sstevel@tonic-gate 		unsigned char *iv, EVP_PKEY **pubk, int npubk);
5770Sstevel@tonic-gate void	PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
5780Sstevel@tonic-gate 		unsigned char *in, int inl);
5790Sstevel@tonic-gate int	PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
5800Sstevel@tonic-gate 		unsigned char *out, int *outl, EVP_PKEY *priv);
5810Sstevel@tonic-gate 
5820Sstevel@tonic-gate void    PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
5830Sstevel@tonic-gate void    PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
5840Sstevel@tonic-gate int	PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
5850Sstevel@tonic-gate 		unsigned int *siglen, EVP_PKEY *pkey);
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate int	PEM_def_callback(char *buf, int num, int w, void *key);
5880Sstevel@tonic-gate void	PEM_proc_type(char *buf, int type);
5890Sstevel@tonic-gate void	PEM_dek_info(char *buf, const char *type, int len, char *str);
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate #ifndef SSLEAY_MACROS
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate #include <openssl/symhacks.h>
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate DECLARE_PEM_rw(X509, X509)
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate DECLARE_PEM_rw(X509_AUX, X509)
5980Sstevel@tonic-gate 
599*2139Sjp161948 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
600*2139Sjp161948 
6010Sstevel@tonic-gate DECLARE_PEM_rw(X509_REQ, X509_REQ)
6020Sstevel@tonic-gate DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate DECLARE_PEM_rw(X509_CRL, X509_CRL)
6050Sstevel@tonic-gate 
6060Sstevel@tonic-gate DECLARE_PEM_rw(PKCS7, PKCS7)
6070Sstevel@tonic-gate 
6080Sstevel@tonic-gate DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate DECLARE_PEM_rw(PKCS8, X509_SIG)
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
6170Sstevel@tonic-gate 
618*2139Sjp161948 DECLARE_PEM_rw_const(RSAPublicKey, RSA)
6190Sstevel@tonic-gate DECLARE_PEM_rw(RSA_PUBKEY, RSA)
6200Sstevel@tonic-gate 
6210Sstevel@tonic-gate #endif
6220Sstevel@tonic-gate 
6230Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
6260Sstevel@tonic-gate 
6270Sstevel@tonic-gate DECLARE_PEM_rw(DSA_PUBKEY, DSA)
6280Sstevel@tonic-gate 
629*2139Sjp161948 DECLARE_PEM_rw_const(DSAparams, DSA)
630*2139Sjp161948 
631*2139Sjp161948 #endif
6320Sstevel@tonic-gate 
633*2139Sjp161948 #ifndef OPENSSL_NO_EC
634*2139Sjp161948 DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)
635*2139Sjp161948 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
636*2139Sjp161948 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
6370Sstevel@tonic-gate #endif
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate #ifndef OPENSSL_NO_DH
6400Sstevel@tonic-gate 
641*2139Sjp161948 DECLARE_PEM_rw_const(DHparams, DH)
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate #endif
6440Sstevel@tonic-gate 
6450Sstevel@tonic-gate DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
6500Sstevel@tonic-gate 				  char *kstr, int klen,
6510Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6520Sstevel@tonic-gate int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
6530Sstevel@tonic-gate                                   char *, int, pem_password_cb *, void *);
6540Sstevel@tonic-gate int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
6550Sstevel@tonic-gate 				  char *kstr, int klen,
6560Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6570Sstevel@tonic-gate int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
6580Sstevel@tonic-gate 				  char *kstr, int klen,
6590Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6600Sstevel@tonic-gate EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
6610Sstevel@tonic-gate 
6620Sstevel@tonic-gate int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
6630Sstevel@tonic-gate 				  char *kstr, int klen,
6640Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6650Sstevel@tonic-gate int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
6660Sstevel@tonic-gate 				  char *kstr, int klen,
6670Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6680Sstevel@tonic-gate int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
6690Sstevel@tonic-gate 				  char *kstr, int klen,
6700Sstevel@tonic-gate 				  pem_password_cb *cb, void *u);
6710Sstevel@tonic-gate 
6720Sstevel@tonic-gate EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
6750Sstevel@tonic-gate 			      char *kstr,int klen, pem_password_cb *cd, void *u);
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate #endif /* SSLEAY_MACROS */
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 
6800Sstevel@tonic-gate /* BEGIN ERROR CODES */
6810Sstevel@tonic-gate /* The following lines are auto generated by the script mkerr.pl. Any changes
6820Sstevel@tonic-gate  * made after this point may be overwritten when the script is next run.
6830Sstevel@tonic-gate  */
6840Sstevel@tonic-gate void ERR_load_PEM_strings(void);
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate /* Error codes for the PEM functions. */
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate /* Function codes. */
6890Sstevel@tonic-gate #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO			 120
6900Sstevel@tonic-gate #define PEM_F_D2I_PKCS8PRIVATEKEY_FP			 121
691*2139Sjp161948 #define PEM_F_DO_PK8PKEY				 126
692*2139Sjp161948 #define PEM_F_DO_PK8PKEY_FP				 125
6930Sstevel@tonic-gate #define PEM_F_LOAD_IV					 101
6940Sstevel@tonic-gate #define PEM_F_PEM_ASN1_READ				 102
6950Sstevel@tonic-gate #define PEM_F_PEM_ASN1_READ_BIO				 103
6960Sstevel@tonic-gate #define PEM_F_PEM_ASN1_WRITE				 104
6970Sstevel@tonic-gate #define PEM_F_PEM_ASN1_WRITE_BIO			 105
698*2139Sjp161948 #define PEM_F_PEM_DEF_CALLBACK				 100
6990Sstevel@tonic-gate #define PEM_F_PEM_DO_HEADER				 106
7000Sstevel@tonic-gate #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY		 118
7010Sstevel@tonic-gate #define PEM_F_PEM_GET_EVP_CIPHER_INFO			 107
702*2139Sjp161948 #define PEM_F_PEM_PK8PKEY				 119
7030Sstevel@tonic-gate #define PEM_F_PEM_READ					 108
7040Sstevel@tonic-gate #define PEM_F_PEM_READ_BIO				 109
705*2139Sjp161948 #define PEM_F_PEM_READ_BIO_PRIVATEKEY			 123
706*2139Sjp161948 #define PEM_F_PEM_READ_PRIVATEKEY			 124
7070Sstevel@tonic-gate #define PEM_F_PEM_SEALFINAL				 110
7080Sstevel@tonic-gate #define PEM_F_PEM_SEALINIT				 111
7090Sstevel@tonic-gate #define PEM_F_PEM_SIGNFINAL				 112
7100Sstevel@tonic-gate #define PEM_F_PEM_WRITE					 113
7110Sstevel@tonic-gate #define PEM_F_PEM_WRITE_BIO				 114
7120Sstevel@tonic-gate #define PEM_F_PEM_X509_INFO_READ			 115
7130Sstevel@tonic-gate #define PEM_F_PEM_X509_INFO_READ_BIO			 116
7140Sstevel@tonic-gate #define PEM_F_PEM_X509_INFO_WRITE_BIO			 117
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate /* Reason codes. */
7170Sstevel@tonic-gate #define PEM_R_BAD_BASE64_DECODE				 100
7180Sstevel@tonic-gate #define PEM_R_BAD_DECRYPT				 101
7190Sstevel@tonic-gate #define PEM_R_BAD_END_LINE				 102
7200Sstevel@tonic-gate #define PEM_R_BAD_IV_CHARS				 103
7210Sstevel@tonic-gate #define PEM_R_BAD_PASSWORD_READ				 104
7220Sstevel@tonic-gate #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY		 115
7230Sstevel@tonic-gate #define PEM_R_NOT_DEK_INFO				 105
7240Sstevel@tonic-gate #define PEM_R_NOT_ENCRYPTED				 106
7250Sstevel@tonic-gate #define PEM_R_NOT_PROC_TYPE				 107
7260Sstevel@tonic-gate #define PEM_R_NO_START_LINE				 108
7270Sstevel@tonic-gate #define PEM_R_PROBLEMS_GETTING_PASSWORD			 109
7280Sstevel@tonic-gate #define PEM_R_PUBLIC_KEY_NO_RSA				 110
7290Sstevel@tonic-gate #define PEM_R_READ_KEY					 111
7300Sstevel@tonic-gate #define PEM_R_SHORT_HEADER				 112
7310Sstevel@tonic-gate #define PEM_R_UNSUPPORTED_CIPHER			 113
7320Sstevel@tonic-gate #define PEM_R_UNSUPPORTED_ENCRYPTION			 114
7330Sstevel@tonic-gate 
7340Sstevel@tonic-gate #ifdef  __cplusplus
7350Sstevel@tonic-gate }
7360Sstevel@tonic-gate #endif
7370Sstevel@tonic-gate #endif
738