1 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2 * All rights reserved. 3 * 4 * This package is an SSL implementation written 5 * by Eric Young (eay@cryptsoft.com). 6 * The implementation was written so as to conform with Netscapes SSL. 7 * 8 * This library is free for commercial and non-commercial use as long as 9 * the following conditions are aheared to. The following conditions 10 * apply to all code found in this distribution, be it the RC4, RSA, 11 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * included with this distribution is covered by the same copyright terms 13 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * 15 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * the code are not to be removed. 17 * If this package is used in a product, Eric Young should be given attribution 18 * as the author of the parts of the library used. 19 * This can be in the form of a textual message at program startup or 20 * in documentation (online or textual) provided with the package. 21 * 22 * Redistribution and use in source and binary forms, with or without 23 * modification, are permitted provided that the following conditions 24 * are met: 25 * 1. Redistributions of source code must retain the copyright 26 * notice, this list of conditions and the following disclaimer. 27 * 2. Redistributions in binary form must reproduce the above copyright 28 * notice, this list of conditions and the following disclaimer in the 29 * documentation and/or other materials provided with the distribution. 30 * 3. All advertising materials mentioning features or use of this software 31 * must display the following acknowledgement: 32 * "This product includes cryptographic software written by 33 * Eric Young (eay@cryptsoft.com)" 34 * The word 'cryptographic' can be left out if the rouines from the library 35 * being used are not cryptographic related :-). 36 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * the apps directory (application code) you must include an acknowledgement: 38 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * 40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * SUCH DAMAGE. 51 * 52 * The licence and distribution terms for any publically available version or 53 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * copied and put under another distribution licence 55 * [including the GNU Public Licence.] */ 56 57 #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 #ifdef __cplusplus 69 extern "C" { 70 #endif 71 72 73 #define PEM_BUFSIZE 1024 74 75 #define PEM_OBJ_UNDEF 0 76 #define PEM_OBJ_X509 1 77 #define PEM_OBJ_X509_REQ 2 78 #define PEM_OBJ_CRL 3 79 #define PEM_OBJ_SSL_SESSION 4 80 #define PEM_OBJ_PRIV_KEY 10 81 #define PEM_OBJ_PRIV_RSA 11 82 #define PEM_OBJ_PRIV_DSA 12 83 #define PEM_OBJ_PRIV_DH 13 84 #define PEM_OBJ_PUB_RSA 14 85 #define PEM_OBJ_PUB_DSA 15 86 #define PEM_OBJ_PUB_DH 16 87 #define PEM_OBJ_DHPARAMS 17 88 #define PEM_OBJ_DSAPARAMS 18 89 #define PEM_OBJ_PRIV_RSA_PUBLIC 19 90 #define PEM_OBJ_PRIV_ECDSA 20 91 #define PEM_OBJ_PUB_ECDSA 21 92 #define PEM_OBJ_ECPARAMETERS 22 93 94 #define PEM_ERROR 30 95 #define PEM_DEK_DES_CBC 40 96 #define PEM_DEK_IDEA_CBC 45 97 #define PEM_DEK_DES_EDE 50 98 #define PEM_DEK_DES_ECB 60 99 #define PEM_DEK_RSA 70 100 #define PEM_DEK_RSA_MD2 80 101 #define PEM_DEK_RSA_MD5 90 102 103 #define PEM_MD_MD2 NID_md2 104 #define PEM_MD_MD5 NID_md5 105 #define PEM_MD_SHA NID_sha 106 #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption 107 #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption 108 #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption 109 110 #define PEM_STRING_X509_OLD "X509 CERTIFICATE" 111 #define PEM_STRING_X509 "CERTIFICATE" 112 #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR" 113 #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" 114 #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 115 #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 116 #define PEM_STRING_X509_CRL "X509 CRL" 117 #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" 118 #define PEM_STRING_PUBLIC "PUBLIC KEY" 119 #define PEM_STRING_RSA "RSA PRIVATE KEY" 120 #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 121 #define PEM_STRING_DSA "DSA PRIVATE KEY" 122 #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" 123 #define PEM_STRING_PKCS7 "PKCS7" 124 #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" 125 #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" 126 #define PEM_STRING_PKCS8INF "PRIVATE KEY" 127 #define PEM_STRING_DHPARAMS "DH PARAMETERS" 128 #define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" 129 #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 130 #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 131 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" 132 #define PEM_STRING_ECPARAMETERS "EC PARAMETERS" 133 #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" 134 #define PEM_STRING_PARAMETERS "PARAMETERS" 135 #define PEM_STRING_CMS "CMS" 136 137 /* Note that this structure is initialised by PEM_SealInit and cleaned up 138 by PEM_SealFinal (at least for now) */ 139 typedef struct PEM_Encode_Seal_st 140 { 141 EVP_ENCODE_CTX encode; 142 EVP_MD_CTX md; 143 EVP_CIPHER_CTX cipher; 144 } PEM_ENCODE_SEAL_CTX; 145 146 /* enc_type is one off */ 147 #define PEM_TYPE_ENCRYPTED 10 148 #define PEM_TYPE_MIC_ONLY 20 149 #define PEM_TYPE_MIC_CLEAR 30 150 #define PEM_TYPE_CLEAR 40 151 152 typedef struct pem_recip_st 153 { 154 char *name; 155 X509_NAME *dn; 156 157 int cipher; 158 int key_enc; 159 /* char iv[8]; unused and wrong size */ 160 } PEM_USER; 161 162 typedef struct pem_ctx_st 163 { 164 int type; /* what type of object */ 165 166 struct { 167 int version; 168 int mode; 169 } proc_type; 170 171 char *domain; 172 173 struct { 174 int cipher; 175 /* unused, and wrong size 176 unsigned char iv[8]; */ 177 } DEK_info; 178 179 PEM_USER *originator; 180 181 int num_recipient; 182 PEM_USER **recipient; 183 184 EVP_MD *md; /* signature type */ 185 186 int md_enc; /* is the md encrypted or not? */ 187 int md_len; /* length of md_data */ 188 char *md_data; /* message digest, could be pkey encrypted */ 189 190 EVP_CIPHER *dec; /* date encryption cipher */ 191 int key_len; /* key length */ 192 unsigned char *key; /* key */ 193 /* unused, and wrong size 194 unsigned char iv[8]; */ 195 196 197 int data_enc; /* is the data encrypted */ 198 int data_len; 199 unsigned char *data; 200 } PEM_CTX; 201 202 /* These macros make the PEM_read/PEM_write functions easier to maintain and 203 * write. Now they are all implemented with either: 204 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) 205 */ 206 207 #ifdef OPENSSL_NO_FP_API 208 209 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ 210 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ 211 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ 212 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ 213 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ 214 215 #else 216 217 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 218 OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ 219 { \ 220 return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ 221 } 222 223 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 224 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \ 225 { \ 226 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ 227 } 228 229 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 230 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \ 231 { \ 232 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ 233 } 234 235 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 236 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 237 unsigned char *kstr, int klen, pem_password_cb *cb, \ 238 void *u) \ 239 { \ 240 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 241 } 242 243 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 244 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 245 unsigned char *kstr, int klen, pem_password_cb *cb, \ 246 void *u) \ 247 { \ 248 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 249 } 250 251 #endif 252 253 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 254 OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ 255 { \ 256 return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ 257 } 258 259 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 260 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \ 261 { \ 262 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ 263 } 264 265 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 266 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \ 267 { \ 268 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ 269 } 270 271 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 272 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 273 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 274 { \ 275 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ 276 } 277 278 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 279 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 280 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 281 { \ 282 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ 283 } 284 285 #define IMPLEMENT_PEM_write(name, type, str, asn1) \ 286 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 287 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 288 289 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ 290 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 291 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 292 293 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 294 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 295 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 296 297 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ 298 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 299 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 300 301 #define IMPLEMENT_PEM_read(name, type, str, asn1) \ 302 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 303 IMPLEMENT_PEM_read_fp(name, type, str, asn1) 304 305 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ 306 IMPLEMENT_PEM_read(name, type, str, asn1) \ 307 IMPLEMENT_PEM_write(name, type, str, asn1) 308 309 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ 310 IMPLEMENT_PEM_read(name, type, str, asn1) \ 311 IMPLEMENT_PEM_write_const(name, type, str, asn1) 312 313 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 314 IMPLEMENT_PEM_read(name, type, str, asn1) \ 315 IMPLEMENT_PEM_write_cb(name, type, str, asn1) 316 317 /* These are the same except they are for the declarations */ 318 319 #if defined(OPENSSL_NO_FP_API) 320 321 #define DECLARE_PEM_read_fp(name, type) /**/ 322 #define DECLARE_PEM_write_fp(name, type) /**/ 323 #define DECLARE_PEM_write_cb_fp(name, type) /**/ 324 325 #else 326 327 #define DECLARE_PEM_read_fp(name, type) \ 328 OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); 329 330 #define DECLARE_PEM_write_fp(name, type) \ 331 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x); 332 333 #define DECLARE_PEM_write_fp_const(name, type) \ 334 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x); 335 336 #define DECLARE_PEM_write_cb_fp(name, type) \ 337 OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 338 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 339 340 #endif 341 342 #define DECLARE_PEM_read_bio(name, type) \ 343 OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); 344 345 #define DECLARE_PEM_write_bio(name, type) \ 346 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x); 347 348 #define DECLARE_PEM_write_bio_const(name, type) \ 349 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x); 350 351 #define DECLARE_PEM_write_cb_bio(name, type) \ 352 OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 353 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 354 355 356 #define DECLARE_PEM_write(name, type) \ 357 DECLARE_PEM_write_bio(name, type) \ 358 DECLARE_PEM_write_fp(name, type) 359 360 #define DECLARE_PEM_write_const(name, type) \ 361 DECLARE_PEM_write_bio_const(name, type) \ 362 DECLARE_PEM_write_fp_const(name, type) 363 364 #define DECLARE_PEM_write_cb(name, type) \ 365 DECLARE_PEM_write_cb_bio(name, type) \ 366 DECLARE_PEM_write_cb_fp(name, type) 367 368 #define DECLARE_PEM_read(name, type) \ 369 DECLARE_PEM_read_bio(name, type) \ 370 DECLARE_PEM_read_fp(name, type) 371 372 #define DECLARE_PEM_rw(name, type) \ 373 DECLARE_PEM_read(name, type) \ 374 DECLARE_PEM_write(name, type) 375 376 #define DECLARE_PEM_rw_const(name, type) \ 377 DECLARE_PEM_read(name, type) \ 378 DECLARE_PEM_write_const(name, type) 379 380 #define DECLARE_PEM_rw_cb(name, type) \ 381 DECLARE_PEM_read(name, type) \ 382 DECLARE_PEM_write_cb(name, type) 383 384 /* "userdata": new with OpenSSL 0.9.4 */ 385 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); 386 387 OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 388 OPENSSL_EXPORT int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u); 389 390 OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len); 391 OPENSSL_EXPORT int PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len); 392 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); 393 OPENSSL_EXPORT void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u); 394 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); 395 396 OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 397 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); 398 399 OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len); 400 OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len); 401 OPENSSL_EXPORT void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u); 402 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); 403 OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 404 405 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); 406 OPENSSL_EXPORT void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); 407 OPENSSL_EXPORT int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv); 408 409 OPENSSL_EXPORT void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); 410 OPENSSL_EXPORT void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); 411 OPENSSL_EXPORT int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey); 412 413 /* |PEM_def_callback| treats |userdata| as a string and copies it into |buf|, 414 * assuming its |size| is sufficient. Returns the length of the string, or 0 415 * if there is not enough room. If either |buf| or |userdata| is NULL, 0 is 416 * returned. Note that this is different from OpenSSL, which prompts for a 417 * password. */ 418 OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag, void *userdata); 419 OPENSSL_EXPORT void PEM_proc_type(char *buf, int type); 420 OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len, char *str); 421 422 423 DECLARE_PEM_rw(X509, X509) 424 425 DECLARE_PEM_rw(X509_AUX, X509) 426 427 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR) 428 429 DECLARE_PEM_rw(X509_REQ, X509_REQ) 430 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) 431 432 DECLARE_PEM_rw(X509_CRL, X509_CRL) 433 434 /* DECLARE_PEM_rw(PKCS7, PKCS7) */ 435 436 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) 437 438 DECLARE_PEM_rw(PKCS8, X509_SIG) 439 440 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) 441 442 DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) 443 444 DECLARE_PEM_rw_const(RSAPublicKey, RSA) 445 DECLARE_PEM_rw(RSA_PUBKEY, RSA) 446 447 #ifndef OPENSSL_NO_DSA 448 449 DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) 450 451 DECLARE_PEM_rw(DSA_PUBKEY, DSA) 452 453 DECLARE_PEM_rw_const(DSAparams, DSA) 454 455 #endif 456 457 DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) 458 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) 459 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) 460 461 462 DECLARE_PEM_rw_const(DHparams, DH) 463 DECLARE_PEM_write_const(DHxparams, 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 *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); 485 OPENSSL_EXPORT int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); 486 487 488 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); 489 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); 490 OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in); 491 OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in); 492 OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); 493 OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); 494 OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); 495 OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u); 496 497 498 void ERR_load_PEM_strings(void); 499 500 501 #ifdef __cplusplus 502 } 503 #endif 504 505 #define PEM_F_PEM_ASN1_read 100 506 #define PEM_F_PEM_ASN1_read_bio 101 507 #define PEM_F_PEM_ASN1_write 102 508 #define PEM_F_PEM_ASN1_write_bio 103 509 #define PEM_F_PEM_X509_INFO_read 104 510 #define PEM_F_PEM_X509_INFO_read_bio 105 511 #define PEM_F_PEM_X509_INFO_write_bio 106 512 #define PEM_F_PEM_do_header 107 513 #define PEM_F_PEM_get_EVP_CIPHER_INFO 108 514 #define PEM_F_PEM_read 109 515 #define PEM_F_PEM_read_DHparams 110 516 #define PEM_F_PEM_read_PrivateKey 111 517 #define PEM_F_PEM_read_bio 112 518 #define PEM_F_PEM_read_bio_DHparams 113 519 #define PEM_F_PEM_read_bio_Parameters 114 520 #define PEM_F_PEM_read_bio_PrivateKey 115 521 #define PEM_F_PEM_write 116 522 #define PEM_F_PEM_write_PrivateKey 117 523 #define PEM_F_PEM_write_bio 118 524 #define PEM_F_d2i_PKCS8PrivateKey_bio 119 525 #define PEM_F_d2i_PKCS8PrivateKey_fp 120 526 #define PEM_F_do_pk8pkey 121 527 #define PEM_F_do_pk8pkey_fp 122 528 #define PEM_F_load_iv 123 529 #define PEM_R_BAD_BASE64_DECODE 100 530 #define PEM_R_BAD_DECRYPT 101 531 #define PEM_R_BAD_END_LINE 102 532 #define PEM_R_BAD_IV_CHARS 103 533 #define PEM_R_BAD_PASSWORD_READ 104 534 #define PEM_R_CIPHER_IS_NULL 105 535 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106 536 #define PEM_R_NOT_DEK_INFO 107 537 #define PEM_R_NOT_ENCRYPTED 108 538 #define PEM_R_NOT_PROC_TYPE 109 539 #define PEM_R_NO_START_LINE 110 540 #define PEM_R_READ_KEY 111 541 #define PEM_R_SHORT_HEADER 112 542 #define PEM_R_UNSUPPORTED_CIPHER 113 543 #define PEM_R_UNSUPPORTED_ENCRYPTION 114 544 545 #endif /* OPENSSL_HEADER_PEM_H */ 546