~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to apps/enc.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
        unsigned char salt[PKCS5_SALT_LEN];
115
115
        char *str=NULL, *passarg = NULL, *pass = NULL;
116
116
        char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
 
117
        char *md=NULL;
117
118
        int enc=1,printkey=0,i,base64=0;
118
119
        int debug=0,olb64=0,nosalt=0;
119
120
        const EVP_CIPHER *cipher=NULL,*c;
124
125
#ifndef OPENSSL_NO_ENGINE
125
126
        char *engine = NULL;
126
127
#endif
 
128
        const EVP_MD *dgst=NULL;
127
129
 
128
130
        apps_startup();
129
131
 
253
255
                        if (--argc < 1) goto bad;
254
256
                        hiv= *(++argv);
255
257
                        }
 
258
                else if (strcmp(*argv,"-md") == 0)
 
259
                        {
 
260
                        if (--argc < 1) goto bad;
 
261
                        md= *(++argv);
 
262
                        }
256
263
                else if ((argv[0][0] == '-') &&
257
264
                        ((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))
258
265
                        {
271
278
                        BIO_printf(bio_err,"%-14s encrypt\n","-e");
272
279
                        BIO_printf(bio_err,"%-14s decrypt\n","-d");
273
280
                        BIO_printf(bio_err,"%-14s base64 encode/decode, depending on encryption flag\n","-a/-base64");
274
 
                        BIO_printf(bio_err,"%-14s key is the next argument\n","-k");
275
 
                        BIO_printf(bio_err,"%-14s key is the first line of the file argument\n","-kfile");
 
281
                        BIO_printf(bio_err,"%-14s passphrase is the next argument\n","-k");
 
282
                        BIO_printf(bio_err,"%-14s passphrase is the first line of the file argument\n","-kfile");
 
283
                        BIO_printf(bio_err,"%-14s the next argument is the md to use to create a key\n","-md");
 
284
                        BIO_printf(bio_err,"%-14s   from a passphrase.  One of md2, md5, sha or sha1\n","");
276
285
                        BIO_printf(bio_err,"%-14s key/iv in hex is the next argument\n","-K/-iv");
277
286
                        BIO_printf(bio_err,"%-14s print the iv/key (then exit if -P)\n","-[pP]");
278
287
                        BIO_printf(bio_err,"%-14s buffer size\n","-bufsize <n>");
296
305
        e = setup_engine(bio_err, engine, 0);
297
306
#endif
298
307
 
 
308
        if (md && (dgst=EVP_get_digestbyname(md)) == NULL)
 
309
                {
 
310
                BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
 
311
                goto end;
 
312
                }
 
313
 
 
314
        if (dgst == NULL)
 
315
                {
 
316
                if (in_FIPS_mode)
 
317
                        dgst = EVP_sha1();
 
318
                else
 
319
                        dgst = EVP_md5();
 
320
                }
 
321
 
299
322
        if (bufsize != NULL)
300
323
                {
301
324
                unsigned long n;
483
506
                                sptr = salt;
484
507
                        }
485
508
 
486
 
                        EVP_BytesToKey(cipher,EVP_md5(),sptr,
 
509
                        EVP_BytesToKey(cipher,dgst,sptr,
487
510
                                (unsigned char *)str,
488
511
                                strlen(str),1,key,iv);
489
512
                        /* zero the complete buffer or the string