00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #ifndef HEADER_PEM_H
00063 #define HEADER_PEM_H
00064
00065 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00066 #define SYMBIAN
00067 #endif
00068
00069 #ifdef SYMBIAN
00070 #include <e32def.h>
00071 #endif
00072 #include <openssl/e_os2.h>
00073 #ifndef OPENSSL_NO_BIO
00074 #include <openssl/bio.h>
00075 #endif
00076 #ifndef OPENSSL_NO_STACK
00077 #include <openssl/stack.h>
00078 #endif
00079 #include <openssl/evp.h>
00080 #include <openssl/x509.h>
00081 #include <openssl/pem2.h>
00082
00083 #ifdef __cplusplus
00084 extern "C" {
00085 #endif
00086
00087 #define PEM_BUFSIZE 1024
00088
00089 #define PEM_OBJ_UNDEF 0
00090 #define PEM_OBJ_X509 1
00091 #define PEM_OBJ_X509_REQ 2
00092 #define PEM_OBJ_CRL 3
00093 #define PEM_OBJ_SSL_SESSION 4
00094 #define PEM_OBJ_PRIV_KEY 10
00095 #define PEM_OBJ_PRIV_RSA 11
00096 #define PEM_OBJ_PRIV_DSA 12
00097 #define PEM_OBJ_PRIV_DH 13
00098 #define PEM_OBJ_PUB_RSA 14
00099 #define PEM_OBJ_PUB_DSA 15
00100 #define PEM_OBJ_PUB_DH 16
00101 #define PEM_OBJ_DHPARAMS 17
00102 #define PEM_OBJ_DSAPARAMS 18
00103 #define PEM_OBJ_PRIV_RSA_PUBLIC 19
00104 #define PEM_OBJ_PRIV_ECDSA 20
00105 #define PEM_OBJ_PUB_ECDSA 21
00106 #define PEM_OBJ_ECPARAMETERS 22
00107
00108 #define PEM_ERROR 30
00109 #define PEM_DEK_DES_CBC 40
00110 #define PEM_DEK_IDEA_CBC 45
00111 #define PEM_DEK_DES_EDE 50
00112 #define PEM_DEK_DES_ECB 60
00113 #define PEM_DEK_RSA 70
00114 #define PEM_DEK_RSA_MD2 80
00115 #define PEM_DEK_RSA_MD5 90
00116
00117 #define PEM_MD_MD2 NID_md2
00118 #define PEM_MD_MD5 NID_md5
00119 #define PEM_MD_SHA NID_sha
00120 #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
00121 #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
00122 #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
00123
00124 #define PEM_STRING_X509_OLD "X509 CERTIFICATE"
00125 #define PEM_STRING_X509 "CERTIFICATE"
00126 #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
00127 #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
00128 #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
00129 #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
00130 #define PEM_STRING_X509_CRL "X509 CRL"
00131 #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
00132 #define PEM_STRING_PUBLIC "PUBLIC KEY"
00133 #define PEM_STRING_RSA "RSA PRIVATE KEY"
00134 #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
00135 #define PEM_STRING_DSA "DSA PRIVATE KEY"
00136 #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
00137 #define PEM_STRING_PKCS7 "PKCS7"
00138 #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
00139 #define PEM_STRING_PKCS8INF "PRIVATE KEY"
00140 #define PEM_STRING_DHPARAMS "DH PARAMETERS"
00141 #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
00142 #define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
00143 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
00144 #define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
00145 #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
00146
00147
00148
00149 typedef struct PEM_Encode_Seal_st
00150 {
00151 EVP_ENCODE_CTX encode;
00152 EVP_MD_CTX md;
00153 EVP_CIPHER_CTX cipher;
00154 } PEM_ENCODE_SEAL_CTX;
00155
00156
00157 #define PEM_TYPE_ENCRYPTED 10
00158 #define PEM_TYPE_MIC_ONLY 20
00159 #define PEM_TYPE_MIC_CLEAR 30
00160 #define PEM_TYPE_CLEAR 40
00161
00162 typedef struct pem_recip_st
00163 {
00164 char *name;
00165 X509_NAME *dn;
00166
00167 int cipher;
00168 int key_enc;
00169
00170 } PEM_USER;
00171
00172 typedef struct pem_ctx_st
00173 {
00174 int type;
00175
00176 struct {
00177 int version;
00178 int mode;
00179 } proc_type;
00180
00181 char *domain;
00182
00183 struct {
00184 int cipher;
00185
00186
00187 } DEK_info;
00188
00189 PEM_USER *originator;
00190
00191 int num_recipient;
00192 PEM_USER **recipient;
00193
00194 #ifndef OPENSSL_NO_STACK
00195 STACK *x509_chain;
00196 #else
00197 char *x509_chain;
00198 #endif
00199 EVP_MD *md;
00200
00201 int md_enc;
00202 int md_len;
00203 char *md_data;
00204
00205 EVP_CIPHER *dec;
00206 int key_len;
00207 unsigned char *key;
00208
00209
00210
00211
00212 int data_enc;
00213 int data_len;
00214 unsigned char *data;
00215 } PEM_CTX;
00216
00217
00218
00219
00220
00221
00222 #ifdef OPENSSL_NO_FP_API
00223
00224 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1)
00225 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1)
00226 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
00227
00228 #else
00229
00230 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
00231 EXPORT_C type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
00232 { \
00233 return(((type *(*)(D2I_OF(type),char *,FILE *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read))(d2i_##asn1, str,fp,x,cb,u)); \
00234 } \
00235
00236 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
00237 EXPORT_C int PEM_write_##name(FILE *fp, type *x) \
00238 { \
00239 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)); \
00240 }
00241
00242 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
00243 EXPORT_C int PEM_write_##name(FILE *fp, const type *x) \
00244 { \
00245 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)); \
00246 }
00247
00248 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
00249 EXPORT_C int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
00250 unsigned char *kstr, int klen, pem_password_cb *cb, \
00251 void *u) \
00252 { \
00253 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)); \
00254 }
00255
00256 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
00257 EXPORT_C int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
00258 unsigned char *kstr, int klen, pem_password_cb *cb, \
00259 void *u) \
00260 { \
00261 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)); \
00262 }
00263
00264 #endif
00265
00266 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
00267 EXPORT_C type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
00268 { \
00269 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)); \
00270 }
00271
00272 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
00273 EXPORT_C int PEM_write_bio_##name(BIO *bp, type *x) \
00274 { \
00275 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)); \
00276 }
00277
00278 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
00279 EXPORT_C int PEM_write_bio_##name(BIO *bp, const type *x) \
00280 { \
00281 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)); \
00282 }
00283
00284 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
00285 EXPORT_C int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
00286 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
00287 { \
00288 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)); \
00289 }
00290
00291 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
00292 EXPORT_C int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
00293 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
00294 { \
00295 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)); \
00296 }
00297
00298 #define IMPLEMENT_PEM_write(name, type, str, asn1) \
00299 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
00300 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
00301
00302 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
00303 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
00304 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
00305
00306 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
00307 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
00308 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
00309
00310 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
00311 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
00312 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
00313
00314 #define IMPLEMENT_PEM_read(name, type, str, asn1) \
00315 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
00316 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
00317
00318 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
00319 IMPLEMENT_PEM_read(name, type, str, asn1) \
00320 IMPLEMENT_PEM_write(name, type, str, asn1)
00321
00322 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
00323 IMPLEMENT_PEM_read(name, type, str, asn1) \
00324 IMPLEMENT_PEM_write_const(name, type, str, asn1)
00325
00326 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
00327 IMPLEMENT_PEM_read(name, type, str, asn1) \
00328 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
00329
00330
00331
00332 #if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API)
00333
00334 #define DECLARE_PEM_read_fp(name, type)
00335 #define DECLARE_PEM_write_fp(name, type)
00336 #define DECLARE_PEM_write_cb_fp(name, type)
00337
00338 #else
00339
00340 #define DECLARE_PEM_read_fp(name, type) \
00341 IMPORT_C type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
00342
00343 #define DECLARE_PEM_write_fp(name, type) \
00344 IMPORT_C int PEM_write_##name(FILE *fp, type *x);
00345
00346 #define DECLARE_PEM_write_fp_const(name, type) \
00347 IMPORT_C int PEM_write_##name(FILE *fp, const type *x);
00348
00349 #define DECLARE_PEM_write_cb_fp(name, type) \
00350 IMPORT_C int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
00351 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
00352
00353 #endif
00354
00355 #ifndef OPENSSL_NO_BIO
00356 #define DECLARE_PEM_read_bio(name, type) \
00357 IMPORT_C type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
00358
00359 #define DECLARE_PEM_write_bio(name, type) \
00360 IMPORT_C int PEM_write_bio_##name(BIO *bp, type *x);
00361
00362 #define DECLARE_PEM_write_bio_const(name, type) \
00363 IMPORT_C int PEM_write_bio_##name(BIO *bp, const type *x);
00364
00365 #define DECLARE_PEM_write_cb_bio(name, type) \
00366 IMPORT_C int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
00367 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
00368
00369 #else
00370
00371 #define DECLARE_PEM_read_bio(name, type)
00372 #define DECLARE_PEM_write_bio(name, type)
00373 #define DECLARE_PEM_write_cb_bio(name, type)
00374
00375 #endif
00376
00377 #define DECLARE_PEM_write(name, type) \
00378 DECLARE_PEM_write_bio(name, type) \
00379 DECLARE_PEM_write_fp(name, type)
00380
00381 #define DECLARE_PEM_write_const(name, type) \
00382 DECLARE_PEM_write_bio_const(name, type) \
00383 DECLARE_PEM_write_fp_const(name, type)
00384
00385 #define DECLARE_PEM_write_cb(name, type) \
00386 DECLARE_PEM_write_cb_bio(name, type) \
00387 DECLARE_PEM_write_cb_fp(name, type)
00388
00389 #define DECLARE_PEM_read(name, type) \
00390 DECLARE_PEM_read_bio(name, type) \
00391 DECLARE_PEM_read_fp(name, type)
00392
00393 #define DECLARE_PEM_rw(name, type) \
00394 DECLARE_PEM_read(name, type) \
00395 DECLARE_PEM_write(name, type)
00396
00397 #define DECLARE_PEM_rw_const(name, type) \
00398 DECLARE_PEM_read(name, type) \
00399 DECLARE_PEM_write_const(name, type)
00400
00401 #define DECLARE_PEM_rw_cb(name, type) \
00402 DECLARE_PEM_read(name, type) \
00403 DECLARE_PEM_write_cb(name, type)
00404
00405 #ifdef SSLEAY_MACROS
00406
00407 #define PEM_write_SSL_SESSION(fp,x) \
00408 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
00409 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
00410 #define PEM_write_X509(fp,x) \
00411 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
00412 (char *)x, NULL,NULL,0,NULL,NULL)
00413 #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
00414 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
00415 NULL,NULL,0,NULL,NULL)
00416 #define PEM_write_X509_CRL(fp,x) \
00417 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
00418 fp,(char *)x, NULL,NULL,0,NULL,NULL)
00419 #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
00420 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
00421 (char *)x,enc,kstr,klen,cb,u)
00422 #define PEM_write_RSAPublicKey(fp,x) \
00423 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
00424 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
00425 #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
00426 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
00427 (char *)x,enc,kstr,klen,cb,u)
00428 #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
00429 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
00430 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
00431 bp,(char *)x,enc,kstr,klen,cb,u)
00432 #define PEM_write_PKCS7(fp,x) \
00433 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
00434 (char *)x, NULL,NULL,0,NULL,NULL)
00435 #define PEM_write_DHparams(fp,x) \
00436 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
00437 (char *)x,NULL,NULL,0,NULL,NULL)
00438
00439 #define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
00440 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
00441 PEM_STRING_X509,fp, \
00442 (char *)x, NULL,NULL,0,NULL,NULL)
00443
00444 #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
00445 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
00446 #define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
00447 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
00448 #define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
00449 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
00450 #define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
00451 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
00452 #define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
00453 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
00454 #define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
00455 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
00456 #define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
00457 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
00458 #define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
00459 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
00460 #define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
00461 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
00462 #define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
00463 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
00464
00465 #define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
00466 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
00467 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
00468 (char **)x,cb,u)
00469
00470 #define PEM_write_bio_X509(bp,x) \
00471 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
00472 (char *)x, NULL,NULL,0,NULL,NULL)
00473 #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
00474 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
00475 NULL,NULL,0,NULL,NULL)
00476 #define PEM_write_bio_X509_CRL(bp,x) \
00477 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
00478 bp,(char *)x, NULL,NULL,0,NULL,NULL)
00479 #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
00480 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
00481 bp,(char *)x,enc,kstr,klen,cb,u)
00482 #define PEM_write_bio_RSAPublicKey(bp,x) \
00483 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
00484 PEM_STRING_RSA_PUBLIC,\
00485 bp,(char *)x,NULL,NULL,0,NULL,NULL)
00486 #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
00487 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
00488 bp,(char *)x,enc,kstr,klen,cb,u)
00489 #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
00490 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
00491 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
00492 bp,(char *)x,enc,kstr,klen,cb,u)
00493 #define PEM_write_bio_PKCS7(bp,x) \
00494 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
00495 (char *)x, NULL,NULL,0,NULL,NULL)
00496 #define PEM_write_bio_DHparams(bp,x) \
00497 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
00498 bp,(char *)x,NULL,NULL,0,NULL,NULL)
00499 #define PEM_write_bio_DSAparams(bp,x) \
00500 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
00501 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
00502
00503 #define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
00504 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
00505 PEM_STRING_X509,bp, \
00506 (char *)x, NULL,NULL,0,NULL,NULL)
00507
00508 #define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
00509 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
00510 #define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
00511 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
00512 #define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
00513 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
00514 #define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
00515 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
00516 #define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
00517 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
00518 #define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
00519 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
00520 #define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
00521 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
00522
00523 #define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
00524 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
00525 #define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
00526 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
00527 #define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
00528 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
00529
00530 #define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
00531 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
00532 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
00533 (char **)x,cb,u)
00534
00535 #endif
00536
00537 #if 1
00538
00539 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
00540 #else
00541
00542 typedef int pem_password_cb(char *buf, int size, int rwflag);
00543 #endif
00544
00545 IMPORT_C int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
00546 IMPORT_C int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
00547 pem_password_cb *callback,void *u);
00548
00549 #ifndef OPENSSL_NO_BIO
00550 IMPORT_C int PEM_read_bio(BIO *bp, char **name, char **header,
00551 unsigned char **data,long *len);
00552 IMPORT_C int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
00553 long len);
00554 IMPORT_C int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
00555 pem_password_cb *cb, void *u);
00556 IMPORT_C void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp,
00557 void **x, pem_password_cb *cb, void *u);
00558 #define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \
00559 ((type *(*)(D2I_OF(type),const char *,BIO *,type **,pem_password_cb *,void *))openssl_fcast(PEM_ASN1_read_bio))(d2i,name,bp,x,cb,u)
00560 IMPORT_C int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,
00561 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
00562 pem_password_cb *cb, void *u);
00563 #define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \
00564 ((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)
00565
00566 IMPORT_C STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
00567 IMPORT_C int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
00568 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
00569 #endif
00570
00571 #ifndef OPENSSL_SYS_WIN16
00572 IMPORT_C int PEM_read(FILE *fp, char **name, char **header,
00573 unsigned char **data,long *len);
00574 IMPORT_C int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
00575 IMPORT_C void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
00576 pem_password_cb *cb, void *u);
00577 IMPORT_C int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp,
00578 char *x,const EVP_CIPHER *enc,unsigned char *kstr,
00579 int klen,pem_password_cb *callback, void *u);
00580 IMPORT_C STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
00581 pem_password_cb *cb, void *u);
00582 #endif
00583
00584 IMPORT_C int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
00585 EVP_MD *md_type, unsigned char **ek, int *ekl,
00586 unsigned char *iv, EVP_PKEY **pubk, int npubk);
00587 IMPORT_C void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
00588 unsigned char *in, int inl);
00589 IMPORT_C int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
00590 unsigned char *out, int *outl, EVP_PKEY *priv);
00591
00592 IMPORT_C void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
00593 IMPORT_C void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
00594 IMPORT_C int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
00595 unsigned int *siglen, EVP_PKEY *pkey);
00596
00597 IMPORT_C int PEM_def_callback(char *buf, int num, int w, void *key);
00598 IMPORT_C void PEM_proc_type(char *buf, int type);
00599 IMPORT_C void PEM_dek_info(char *buf, const char *type, int len, char *str);
00600
00601 #ifndef SSLEAY_MACROS
00602
00603 #include <openssl/symhacks.h>
00604
00605 DECLARE_PEM_rw(X509, X509)
00606
00607 DECLARE_PEM_rw(X509_AUX, X509)
00608
00609 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
00610
00611 DECLARE_PEM_rw(X509_REQ, X509_REQ)
00612 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
00613
00614 DECLARE_PEM_rw(X509_CRL, X509_CRL)
00615
00616 DECLARE_PEM_rw(PKCS7, PKCS7)
00617
00618 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
00619
00620 DECLARE_PEM_rw(PKCS8, X509_SIG)
00621
00622 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
00623
00624 #ifndef OPENSSL_NO_RSA
00625
00626 DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
00627
00628 DECLARE_PEM_rw_const(RSAPublicKey, RSA)
00629 DECLARE_PEM_rw(RSA_PUBKEY, RSA)
00630
00631 #endif
00632
00633 #ifndef OPENSSL_NO_DSA
00634
00635 DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
00636
00637 DECLARE_PEM_rw(DSA_PUBKEY, DSA)
00638
00639 DECLARE_PEM_rw_const(DSAparams, DSA)
00640
00641 #endif
00642
00643 #ifndef OPENSSL_NO_EC
00644 DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)
00645 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
00646 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
00647 #endif
00648
00649 #ifndef OPENSSL_NO_DH
00650
00651 DECLARE_PEM_rw_const(DHparams, DH)
00652
00653 #endif
00654
00655 DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
00656
00657 DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
00658
00659 IMPORT_C int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
00660 char *kstr, int klen,
00661 pem_password_cb *cb, void *u);
00662 IMPORT_C int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
00663 char *, int, pem_password_cb *, void *);
00664 IMPORT_C int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
00665 char *kstr, int klen,
00666 pem_password_cb *cb, void *u);
00667 IMPORT_C int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
00668 char *kstr, int klen,
00669 pem_password_cb *cb, void *u);
00670 IMPORT_C EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
00671
00672 IMPORT_C int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
00673 char *kstr, int klen,
00674 pem_password_cb *cb, void *u);
00675 IMPORT_C int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
00676 char *kstr, int klen,
00677 pem_password_cb *cb, void *u);
00678 IMPORT_C int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
00679 char *kstr, int klen,
00680 pem_password_cb *cb, void *u);
00681
00682 IMPORT_C EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
00683
00684 IMPORT_C int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
00685 char *kstr,int klen, pem_password_cb *cd, void *u);
00686
00687 #endif
00688
00689
00690
00691
00692
00693
00694 IMPORT_C void ERR_load_PEM_strings(void);
00695
00696
00697
00698
00699 #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
00700 #define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
00701 #define PEM_F_DO_PK8PKEY 126
00702 #define PEM_F_DO_PK8PKEY_FP 125
00703 #define PEM_F_LOAD_IV 101
00704 #define PEM_F_PEM_ASN1_READ 102
00705 #define PEM_F_PEM_ASN1_READ_BIO 103
00706 #define PEM_F_PEM_ASN1_WRITE 104
00707 #define PEM_F_PEM_ASN1_WRITE_BIO 105
00708 #define PEM_F_PEM_DEF_CALLBACK 100
00709 #define PEM_F_PEM_DO_HEADER 106
00710 #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
00711 #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
00712 #define PEM_F_PEM_PK8PKEY 119
00713 #define PEM_F_PEM_READ 108
00714 #define PEM_F_PEM_READ_BIO 109
00715 #define PEM_F_PEM_READ_BIO_PRIVATEKEY 123
00716 #define PEM_F_PEM_READ_PRIVATEKEY 124
00717 #define PEM_F_PEM_SEALFINAL 110
00718 #define PEM_F_PEM_SEALINIT 111
00719 #define PEM_F_PEM_SIGNFINAL 112
00720 #define PEM_F_PEM_WRITE 113
00721 #define PEM_F_PEM_WRITE_BIO 114
00722 #define PEM_F_PEM_X509_INFO_READ 115
00723 #define PEM_F_PEM_X509_INFO_READ_BIO 116
00724 #define PEM_F_PEM_X509_INFO_WRITE_BIO 117
00725
00726
00727 #define PEM_R_BAD_BASE64_DECODE 100
00728 #define PEM_R_BAD_DECRYPT 101
00729 #define PEM_R_BAD_END_LINE 102
00730 #define PEM_R_BAD_IV_CHARS 103
00731 #define PEM_R_BAD_PASSWORD_READ 104
00732 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
00733 #define PEM_R_NOT_DEK_INFO 105
00734 #define PEM_R_NOT_ENCRYPTED 106
00735 #define PEM_R_NOT_PROC_TYPE 107
00736 #define PEM_R_NO_START_LINE 108
00737 #define PEM_R_PROBLEMS_GETTING_PASSWORD 109
00738 #define PEM_R_PUBLIC_KEY_NO_RSA 110
00739 #define PEM_R_READ_KEY 111
00740 #define PEM_R_SHORT_HEADER 112
00741 #define PEM_R_UNSUPPORTED_CIPHER 113
00742 #define PEM_R_UNSUPPORTED_ENCRYPTION 114
00743
00744 #ifdef __cplusplus
00745 }
00746 #endif
00747 #endif