Home | History | Annotate | Download | only in openssl
      1 /* Copyright (C) 1995-1997 Eric Young (eay (at) cryptsoft.com)
      2  * All rights reserved.
      3  *
      4  * This package is an SSL implementation written
      5  * by Eric Young (eay (at) 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 (at) 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 (at) 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 (at) 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 #ifndef OPENSSL_HEADER_PEM_H
     58 #define OPENSSL_HEADER_PEM_H
     59 
     60 #include <openssl/base64.h>
     61 #include <openssl/bio.h>
     62 #include <openssl/cipher.h>
     63 #include <openssl/digest.h>
     64 #include <openssl/evp.h>
     65 #include <openssl/stack.h>
     66 #include <openssl/x509.h>
     67 
     68 /* For compatibility with open-iscsi, which assumes that it can get
     69  * |OPENSSL_malloc| from pem.h or err.h */
     70 #include <openssl/crypto.h>
     71 
     72 #ifdef  __cplusplus
     73 extern "C" {
     74 #endif
     75 
     76 
     77 #define PEM_BUFSIZE		1024
     78 
     79 #define PEM_OBJ_UNDEF		0
     80 #define PEM_OBJ_X509		1
     81 #define PEM_OBJ_X509_REQ	2
     82 #define PEM_OBJ_CRL		3
     83 #define PEM_OBJ_SSL_SESSION	4
     84 #define PEM_OBJ_PRIV_KEY	10
     85 #define PEM_OBJ_PRIV_RSA	11
     86 #define PEM_OBJ_PRIV_DSA	12
     87 #define PEM_OBJ_PRIV_DH		13
     88 #define PEM_OBJ_PUB_RSA		14
     89 #define PEM_OBJ_PUB_DSA		15
     90 #define PEM_OBJ_PUB_DH		16
     91 #define PEM_OBJ_DHPARAMS	17
     92 #define PEM_OBJ_DSAPARAMS	18
     93 #define PEM_OBJ_PRIV_RSA_PUBLIC	19
     94 #define PEM_OBJ_PRIV_ECDSA	20
     95 #define PEM_OBJ_PUB_ECDSA	21
     96 #define PEM_OBJ_ECPARAMETERS	22
     97 
     98 #define PEM_ERROR		30
     99 #define PEM_DEK_DES_CBC         40
    100 #define PEM_DEK_IDEA_CBC        45
    101 #define PEM_DEK_DES_EDE         50
    102 #define PEM_DEK_DES_ECB         60
    103 #define PEM_DEK_RSA             70
    104 #define PEM_DEK_RSA_MD2         80
    105 #define PEM_DEK_RSA_MD5         90
    106 
    107 #define PEM_MD_MD2		NID_md2
    108 #define PEM_MD_MD5		NID_md5
    109 #define PEM_MD_SHA		NID_sha
    110 #define PEM_MD_MD2_RSA		NID_md2WithRSAEncryption
    111 #define PEM_MD_MD5_RSA		NID_md5WithRSAEncryption
    112 #define PEM_MD_SHA_RSA		NID_sha1WithRSAEncryption
    113 
    114 #define PEM_STRING_X509_OLD	"X509 CERTIFICATE"
    115 #define PEM_STRING_X509		"CERTIFICATE"
    116 #define PEM_STRING_X509_PAIR	"CERTIFICATE PAIR"
    117 #define PEM_STRING_X509_TRUSTED	"TRUSTED CERTIFICATE"
    118 #define PEM_STRING_X509_REQ_OLD	"NEW CERTIFICATE REQUEST"
    119 #define PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
    120 #define PEM_STRING_X509_CRL	"X509 CRL"
    121 #define PEM_STRING_EVP_PKEY	"ANY PRIVATE KEY"
    122 #define PEM_STRING_PUBLIC	"PUBLIC KEY"
    123 #define PEM_STRING_RSA		"RSA PRIVATE KEY"
    124 #define PEM_STRING_RSA_PUBLIC	"RSA PUBLIC KEY"
    125 #define PEM_STRING_DSA		"DSA PRIVATE KEY"
    126 #define PEM_STRING_DSA_PUBLIC	"DSA PUBLIC KEY"
    127 #define PEM_STRING_EC "EC PRIVATE KEY"
    128 #define PEM_STRING_PKCS7	"PKCS7"
    129 #define PEM_STRING_PKCS7_SIGNED	"PKCS #7 SIGNED DATA"
    130 #define PEM_STRING_PKCS8	"ENCRYPTED PRIVATE KEY"
    131 #define PEM_STRING_PKCS8INF	"PRIVATE KEY"
    132 #define PEM_STRING_DHPARAMS	"DH PARAMETERS"
    133 #define PEM_STRING_SSL_SESSION	"SSL SESSION PARAMETERS"
    134 #define PEM_STRING_DSAPARAMS	"DSA PARAMETERS"
    135 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
    136 #define PEM_STRING_ECPRIVATEKEY	"EC PRIVATE KEY"
    137 #define PEM_STRING_CMS		"CMS"
    138 
    139   /* Note that this structure is initialised by PEM_SealInit and cleaned up
    140      by PEM_SealFinal (at least for now) */
    141 typedef struct PEM_Encode_Seal_st
    142 	{
    143 	EVP_ENCODE_CTX encode;
    144 	EVP_MD_CTX md;
    145 	EVP_CIPHER_CTX cipher;
    146 	} PEM_ENCODE_SEAL_CTX;
    147 
    148 /* enc_type is one off */
    149 #define PEM_TYPE_ENCRYPTED      10
    150 #define PEM_TYPE_MIC_ONLY       20
    151 #define PEM_TYPE_MIC_CLEAR      30
    152 #define PEM_TYPE_CLEAR		40
    153 
    154 typedef struct pem_recip_st
    155 	{
    156 	char *name;
    157 	X509_NAME *dn;
    158 
    159 	int cipher;
    160 	int key_enc;
    161 	/*	char iv[8]; unused and wrong size */
    162 	} PEM_USER;
    163 
    164 typedef struct pem_ctx_st
    165 	{
    166 	int type;		/* what type of object */
    167 
    168 	struct	{
    169 		int version;
    170 		int mode;
    171 		} proc_type;
    172 
    173 	char *domain;
    174 
    175 	struct	{
    176 		int cipher;
    177 	/* unused, and wrong size
    178 	   unsigned char iv[8]; */
    179 		} DEK_info;
    180 
    181 	PEM_USER *originator;
    182 
    183 	int num_recipient;
    184 	PEM_USER **recipient;
    185 
    186 	EVP_MD *md;		/* signature type */
    187 
    188 	int md_enc;		/* is the md encrypted or not? */
    189 	int md_len;		/* length of md_data */
    190 	char *md_data;		/* message digest, could be pkey encrypted */
    191 
    192 	EVP_CIPHER *dec;	/* date encryption cipher */
    193 	int key_len;		/* key length */
    194 	unsigned char *key;	/* key */
    195 	/* unused, and wrong size
    196 	   unsigned char iv[8]; */
    197 
    198 
    199 	int  data_enc;		/* is the data encrypted */
    200 	int data_len;
    201 	unsigned char *data;
    202 	} PEM_CTX;
    203 
    204 /* These macros make the PEM_read/PEM_write functions easier to maintain and
    205  * write. Now they are all implemented with either:
    206  * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
    207  */
    208 
    209 #ifdef OPENSSL_NO_FP_API
    210 
    211 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
    212 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
    213 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
    214 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
    215 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
    216 
    217 #else
    218 
    219 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
    220 OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
    221 { \
    222 return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
    223 }
    224 
    225 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
    226 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \
    227 { \
    228 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
    229 }
    230 
    231 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
    232 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \
    233 { \
    234 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
    235 }
    236 
    237 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
    238 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
    239 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
    240 		  void *u) \
    241 	{ \
    242 	return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
    243 	}
    244 
    245 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
    246 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
    247 	     unsigned char *kstr, int klen, pem_password_cb *cb, \
    248 		  void *u) \
    249 	{ \
    250 	return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
    251 	}
    252 
    253 #endif
    254 
    255 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
    256 OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
    257 { \
    258 return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
    259 }
    260 
    261 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
    262 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \
    263 { \
    264 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
    265 }
    266 
    267 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
    268 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \
    269 { \
    270 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
    271 }
    272 
    273 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
    274 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
    275 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
    276 	{ \
    277 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
    278 	}
    279 
    280 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
    281 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
    282 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
    283 	{ \
    284 	return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
    285 	}
    286 
    287 #define IMPLEMENT_PEM_write(name, type, str, asn1) \
    288 	IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
    289 	IMPLEMENT_PEM_write_fp(name, type, str, asn1)
    290 
    291 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
    292 	IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
    293 	IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
    294 
    295 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
    296 	IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
    297 	IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
    298 
    299 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
    300 	IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
    301 	IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
    302 
    303 #define IMPLEMENT_PEM_read(name, type, str, asn1) \
    304 	IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
    305 	IMPLEMENT_PEM_read_fp(name, type, str, asn1)
    306 
    307 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
    308 	IMPLEMENT_PEM_read(name, type, str, asn1) \
    309 	IMPLEMENT_PEM_write(name, type, str, asn1)
    310 
    311 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
    312 	IMPLEMENT_PEM_read(name, type, str, asn1) \
    313 	IMPLEMENT_PEM_write_const(name, type, str, asn1)
    314 
    315 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
    316 	IMPLEMENT_PEM_read(name, type, str, asn1) \
    317 	IMPLEMENT_PEM_write_cb(name, type, str, asn1)
    318 
    319 /* These are the same except they are for the declarations */
    320 
    321 #if defined(OPENSSL_NO_FP_API)
    322 
    323 #define DECLARE_PEM_read_fp(name, type) /**/
    324 #define DECLARE_PEM_write_fp(name, type) /**/
    325 #define DECLARE_PEM_write_cb_fp(name, type) /**/
    326 
    327 #else
    328 
    329 #define DECLARE_PEM_read_fp(name, type) \
    330 	OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
    331 
    332 #define DECLARE_PEM_write_fp(name, type) \
    333 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
    334 
    335 #define DECLARE_PEM_write_fp_const(name, type) \
    336 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
    337 
    338 #define DECLARE_PEM_write_cb_fp(name, type) \
    339 	OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
    340 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
    341 
    342 #endif
    343 
    344 #define DECLARE_PEM_read_bio(name, type) \
    345 	OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
    346 
    347 #define DECLARE_PEM_write_bio(name, type) \
    348 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
    349 
    350 #define DECLARE_PEM_write_bio_const(name, type) \
    351 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
    352 
    353 #define DECLARE_PEM_write_cb_bio(name, type) \
    354 	OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
    355 	     unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
    356 
    357 
    358 #define DECLARE_PEM_write(name, type) \
    359 	DECLARE_PEM_write_bio(name, type) \
    360 	DECLARE_PEM_write_fp(name, type)
    361 
    362 #define DECLARE_PEM_write_const(name, type) \
    363 	DECLARE_PEM_write_bio_const(name, type) \
    364 	DECLARE_PEM_write_fp_const(name, type)
    365 
    366 #define DECLARE_PEM_write_cb(name, type) \
    367 	DECLARE_PEM_write_cb_bio(name, type) \
    368 	DECLARE_PEM_write_cb_fp(name, type)
    369 
    370 #define DECLARE_PEM_read(name, type) \
    371 	DECLARE_PEM_read_bio(name, type) \
    372 	DECLARE_PEM_read_fp(name, type)
    373 
    374 #define DECLARE_PEM_rw(name, type) \
    375 	DECLARE_PEM_read(name, type) \
    376 	DECLARE_PEM_write(name, type)
    377 
    378 #define DECLARE_PEM_rw_const(name, type) \
    379 	DECLARE_PEM_read(name, type) \
    380 	DECLARE_PEM_write_const(name, type)
    381 
    382 #define DECLARE_PEM_rw_cb(name, type) \
    383 	DECLARE_PEM_read(name, type) \
    384 	DECLARE_PEM_write_cb(name, type)
    385 
    386 /* "userdata": new with OpenSSL 0.9.4 */
    387 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
    388 
    389 OPENSSL_EXPORT int	PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
    390 OPENSSL_EXPORT int	PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u);
    391 
    392 OPENSSL_EXPORT int	PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len);
    393 OPENSSL_EXPORT int	PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
    394 OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, pem_password_cb *cb, void *u);
    395 OPENSSL_EXPORT void *	PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u);
    396 OPENSSL_EXPORT int	PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, const EVP_CIPHER *enc,unsigned char *kstr,int klen, pem_password_cb *cb, void *u);
    397 
    398 OPENSSL_EXPORT STACK_OF(X509_INFO) *	PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
    399 OPENSSL_EXPORT int	PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
    400 
    401 OPENSSL_EXPORT int	PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len);
    402 OPENSSL_EXPORT int	PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len);
    403 OPENSSL_EXPORT void *  PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u);
    404 OPENSSL_EXPORT int	PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, void *x,const EVP_CIPHER *enc,unsigned char *kstr, int klen,pem_password_cb *callback, void *u);
    405 OPENSSL_EXPORT STACK_OF(X509_INFO) *	PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
    406 
    407 OPENSSL_EXPORT int	PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
    408 OPENSSL_EXPORT void	PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl);
    409 OPENSSL_EXPORT int	PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv);
    410 
    411 OPENSSL_EXPORT void    PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
    412 OPENSSL_EXPORT void    PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
    413 OPENSSL_EXPORT int	PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey);
    414 
    415 /* PEM_def_callback treats |userdata| as a string and copies it into |buf|,
    416  * assuming its |size| is sufficient. Returns the length of the string, or 0
    417  * if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
    418  * returned. Note that this is different from OpenSSL, which prompts for a
    419  * password. */
    420 OPENSSL_EXPORT int	PEM_def_callback(char *buf, int size, int rwflag, void *userdata);
    421 OPENSSL_EXPORT void	PEM_proc_type(char *buf, int type);
    422 OPENSSL_EXPORT void	PEM_dek_info(char *buf, const char *type, int len, char *str);
    423 
    424 
    425 DECLARE_PEM_rw(X509, X509)
    426 
    427 DECLARE_PEM_rw(X509_AUX, X509)
    428 
    429 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
    430 
    431 DECLARE_PEM_rw(X509_REQ, X509_REQ)
    432 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
    433 
    434 DECLARE_PEM_rw(X509_CRL, X509_CRL)
    435 
    436 /* DECLARE_PEM_rw(PKCS7, PKCS7) */
    437 
    438 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
    439 
    440 DECLARE_PEM_rw(PKCS8, X509_SIG)
    441 
    442 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
    443 
    444 DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
    445 
    446 DECLARE_PEM_rw_const(RSAPublicKey, RSA)
    447 DECLARE_PEM_rw(RSA_PUBKEY, RSA)
    448 
    449 #ifndef OPENSSL_NO_DSA
    450 
    451 DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
    452 
    453 DECLARE_PEM_rw(DSA_PUBKEY, DSA)
    454 
    455 DECLARE_PEM_rw_const(DSAparams, DSA)
    456 
    457 #endif
    458 
    459 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
    460 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
    461 
    462 
    463 DECLARE_PEM_rw_const(DHparams, DH)
    464 
    465 
    466 DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
    467 
    468 DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
    469 
    470 OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
    471 OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *);
    472 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
    473 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
    474 OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
    475 
    476 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
    477 OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
    478 OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
    479 
    480 OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
    481 
    482 OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, char *kstr,int klen, pem_password_cb *cd, void *u);
    483 
    484 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
    485 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
    486 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
    487 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in);
    488 OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
    489 OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
    490 OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
    491 OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u);
    492 
    493 
    494 void ERR_load_PEM_strings(void);
    495 
    496 
    497 #ifdef  __cplusplus
    498 }
    499 #endif
    500 
    501 #define PEM_R_BAD_BASE64_DECODE 100
    502 #define PEM_R_BAD_DECRYPT 101
    503 #define PEM_R_BAD_END_LINE 102
    504 #define PEM_R_BAD_IV_CHARS 103
    505 #define PEM_R_BAD_PASSWORD_READ 104
    506 #define PEM_R_CIPHER_IS_NULL 105
    507 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106
    508 #define PEM_R_NOT_DEK_INFO 107
    509 #define PEM_R_NOT_ENCRYPTED 108
    510 #define PEM_R_NOT_PROC_TYPE 109
    511 #define PEM_R_NO_START_LINE 110
    512 #define PEM_R_READ_KEY 111
    513 #define PEM_R_SHORT_HEADER 112
    514 #define PEM_R_UNSUPPORTED_CIPHER 113
    515 #define PEM_R_UNSUPPORTED_ENCRYPTION 114
    516 
    517 #endif  /* OPENSSL_HEADER_PEM_H */
    518