summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem/pem_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pem/pem_lib.c')
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 9bae4c8850..82815067b3 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -69,7 +69,7 @@
69#include <openssl/des.h> 69#include <openssl/des.h>
70#endif 70#endif
71 71
72const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT; 72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
73 73
74#define MIN_LENGTH 4 74#define MIN_LENGTH 4
75 75
@@ -81,7 +81,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
81#ifdef OPENSSL_NO_FP_API 81#ifdef OPENSSL_NO_FP_API
82 /* We should not ever call the default callback routine from 82 /* We should not ever call the default callback routine from
83 * windows. */ 83 * windows. */
84 PEMerr(PEM_F_PEM_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1); 85 return(-1);
86#else 86#else
87 int i,j; 87 int i,j;
@@ -102,7 +102,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
102 i=EVP_read_pw_string(buf,num,prompt,w); 102 i=EVP_read_pw_string(buf,num,prompt,w);
103 if (i != 0) 103 if (i != 0)
104 { 104 {
105 PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); 105 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106 memset(buf,0,(unsigned int)num); 106 memset(buf,0,(unsigned int)num);
107 return(-1); 107 return(-1);
108 } 108 }
@@ -158,11 +158,11 @@ void PEM_dek_info(char *buf, const char *type, int len, char *str)
158 } 158 }
159 159
160#ifndef OPENSSL_NO_FP_API 160#ifndef OPENSSL_NO_FP_API
161void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 161char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162 pem_password_cb *cb, void *u) 162 pem_password_cb *cb, void *u)
163 { 163 {
164 BIO *b; 164 BIO *b;
165 void *ret; 165 char *ret;
166 166
167 if ((b=BIO_new(BIO_s_file())) == NULL) 167 if ((b=BIO_new(BIO_s_file())) == NULL)
168 { 168 {
@@ -195,8 +195,6 @@ static int check_pem(const char *nm, const char *name)
195 if(!strcmp(nm,PEM_STRING_DSA) && 195 if(!strcmp(nm,PEM_STRING_DSA) &&
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
197 197
198 if(!strcmp(nm,PEM_STRING_ECPRIVATEKEY) &&
199 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
200 /* Permit older strings */ 198 /* Permit older strings */
201 199
202 if(!strcmp(nm,PEM_STRING_X509_OLD) && 200 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
@@ -260,9 +258,9 @@ err:
260 } 258 }
261 259
262#ifndef OPENSSL_NO_FP_API 260#ifndef OPENSSL_NO_FP_API
263int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, 261int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
264 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 262 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
265 int klen, pem_password_cb *callback, void *u) 263 pem_password_cb *callback, void *u)
266 { 264 {
267 BIO *b; 265 BIO *b;
268 int ret; 266 int ret;
@@ -279,9 +277,9 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
279 } 277 }
280#endif 278#endif
281 279
282int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, 280int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
283 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 281 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
284 int klen, pem_password_cb *callback, void *u) 282 pem_password_cb *callback, void *u)
285 { 283 {
286 EVP_CIPHER_CTX ctx; 284 EVP_CIPHER_CTX ctx;
287 int dsize=0,i,j,ret=0; 285 int dsize=0,i,j,ret=0;
@@ -338,7 +336,7 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
338 kstr=(unsigned char *)buf; 336 kstr=(unsigned char *)buf;
339 } 337 }
340 RAND_add(data,i,0);/* put in the RSA key. */ 338 RAND_add(data,i,0);/* put in the RSA key. */
341 OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); 339 OPENSSL_assert(enc->iv_len <= sizeof iv);
342 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ 340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
343 goto err; 341 goto err;
344 /* The 'iv' is used as the iv and as a salt. It is 342 /* The 'iv' is used as the iv and as a salt. It is
@@ -579,7 +577,6 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
579 } 577 }
580 EVP_EncodeFinal(&ctx,buf,&outl); 578 EVP_EncodeFinal(&ctx,buf,&outl);
581 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; 579 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
582 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
583 OPENSSL_free(buf); 580 OPENSSL_free(buf);
584 buf = NULL; 581 buf = NULL;
585 if ( (BIO_write(bp,"-----END ",9) != 9) || 582 if ( (BIO_write(bp,"-----END ",9) != 9) ||
@@ -588,10 +585,8 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
588 goto err; 585 goto err;
589 return(i+outl); 586 return(i+outl);
590err: 587err:
591 if (buf) { 588 if (buf)
592 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
593 OPENSSL_free(buf); 589 OPENSSL_free(buf);
594 }
595 PEMerr(PEM_F_PEM_WRITE_BIO,reason); 590 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
596 return(0); 591 return(0);
597 } 592 }