~ubuntu-branches/ubuntu/hardy/openssl/hardy-security

« back to all changes in this revision

Viewing changes to crypto/pem/pem_lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051213213742-7em5nrw5c7ceegyd
Tags: 0.9.8a-5
Stop ssh from crashing randomly on sparc (Closes: #335912)
Patch from upstream cvs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
 
74
74
#define MIN_LENGTH      4
75
75
 
76
 
static int load_iv(unsigned char **fromp,unsigned char *to, int num);
 
76
static int load_iv(char **fromp,unsigned char *to, int num);
77
77
static int check_pem(const char *nm, const char *name);
78
78
 
79
79
int PEM_def_callback(char *buf, int num, int w, void *key)
81
81
#ifdef OPENSSL_NO_FP_API
82
82
        /* We should not ever call the default callback routine from
83
83
         * windows. */
84
 
        PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
 
84
        PEMerr(PEM_F_PEM_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85
85
        return(-1);
86
86
#else
87
87
        int i,j;
102
102
                i=EVP_read_pw_string(buf,num,prompt,w);
103
103
                if (i != 0)
104
104
                        {
105
 
                        PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
 
105
                        PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106
106
                        memset(buf,0,(unsigned int)num);
107
107
                        return(-1);
108
108
                        }
158
158
        }
159
159
 
160
160
#ifndef OPENSSL_NO_FP_API
161
 
char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162
 
             pem_password_cb *cb, void *u)
 
161
void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
 
162
                    pem_password_cb *cb, void *u)
163
163
        {
164
164
        BIO *b;
165
 
        char *ret;
 
165
        void *ret;
166
166
 
167
167
        if ((b=BIO_new(BIO_s_file())) == NULL)
168
168
                {
195
195
        if(!strcmp(nm,PEM_STRING_DSA) &&
196
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;
198
200
        /* Permit older strings */
199
201
 
200
202
        if(!strcmp(nm,PEM_STRING_X509_OLD) &&
258
260
        }
259
261
 
260
262
#ifndef OPENSSL_NO_FP_API
261
 
int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
262
 
             const EVP_CIPHER *enc, unsigned char *kstr, int klen,
263
 
             pem_password_cb *callback, void *u)
 
263
int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
 
264
                   char *x, const EVP_CIPHER *enc, unsigned char *kstr,
 
265
                   int klen, pem_password_cb *callback, void *u)
264
266
        {
265
267
        BIO *b;
266
268
        int ret;
277
279
        }
278
280
#endif
279
281
 
280
 
int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
281
 
             const EVP_CIPHER *enc, unsigned char *kstr, int klen,
282
 
             pem_password_cb *callback, void *u)
 
282
int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
 
283
                       char *x, const EVP_CIPHER *enc, unsigned char *kstr,
 
284
                       int klen, pem_password_cb *callback, void *u)
283
285
        {
284
286
        EVP_CIPHER_CTX ctx;
285
287
        int dsize=0,i,j,ret=0;
301
303
 
302
304
        if ((dsize=i2d(x,NULL)) < 0)
303
305
                {
304
 
                PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
 
306
                PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_ASN1_LIB);
305
307
                dsize=0;
306
308
                goto err;
307
309
                }
336
338
                        kstr=(unsigned char *)buf;
337
339
                        }
338
340
                RAND_add(data,i,0);/* put in the RSA key. */
339
 
                OPENSSL_assert(enc->iv_len <= sizeof iv);
 
341
                OPENSSL_assert(enc->iv_len <= (int)sizeof(iv));
340
342
                if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
341
343
                        goto err;
342
344
                /* The 'iv' is used as the iv and as a salt.  It is
432
434
        int o;
433
435
        const EVP_CIPHER *enc=NULL;
434
436
        char *p,c;
 
437
        char **header_pp = &header;
435
438
 
436
439
        cipher->cipher=NULL;
437
440
        if ((header == NULL) || (*header == '\0') || (*header == '\n'))
478
481
                PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION);
479
482
                return(0);
480
483
                }
481
 
        if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),enc->iv_len)) return(0);
 
484
        if (!load_iv(header_pp,&(cipher->iv[0]),enc->iv_len))
 
485
                return(0);
482
486
 
483
487
        return(1);
484
488
        }
485
489
 
486
 
static int load_iv(unsigned char **fromp, unsigned char *to, int num)
 
490
static int load_iv(char **fromp, unsigned char *to, int num)
487
491
        {
488
492
        int v,i;
489
 
        unsigned char *from;
 
493
        char *from;
490
494
 
491
495
        from= *fromp;
492
496
        for (i=0; i<num; i++) to[i]=0;
623
627
        dataB=BUF_MEM_new();
624
628
        if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))
625
629
                {
 
630
                BUF_MEM_free(nameB);
 
631
                BUF_MEM_free(headerB);
 
632
                BUF_MEM_free(dataB);
626
633
                PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
627
634
                return(0);
628
635
                }