73 int set_hex(
char *in,
unsigned char *out,
int size);
79 #define BSIZE (8*1024)
82 static void show_ciphers(
const OBJ_NAME *name,
void *bio_)
87 if(!islower((
unsigned char)*name->
name))
100 int MAIN(
int,
char **);
102 int MAIN(
int argc,
char **argv)
104 static const char magic[]=
"Salted__";
105 char mbuf[
sizeof magic-1];
107 unsigned char *buff=NULL,*bufsize=NULL;
113 char *str=NULL, *passarg = NULL, *
pass = NULL;
114 char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
116 int enc=1,printkey=0,i,base64=0;
121 int debug=0,olb64=0,nosalt=0;
124 char *inf=NULL,*outf=NULL;
125 BIO *
in=NULL,*
out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;
126 #define PROG_NAME_SIZE 39
128 #ifndef OPENSSL_NO_ENGINE
132 int non_fips_allow = 0;
145 if (strcmp(pname,
"base64") == 0)
148 if (strcmp(pname,
"zlib") == 0)
154 if (!do_zlib && !base64 && (cipher == NULL)
155 && (strcmp(pname,
"enc") != 0))
157 if (!base64 && (cipher == NULL) && (strcmp(pname,
"enc") != 0))
168 if (strcmp(*argv,
"-e") == 0)
170 else if (strcmp(*argv,
"-in") == 0)
172 if (--argc < 1)
goto bad;
175 else if (strcmp(*argv,
"-out") == 0)
177 if (--argc < 1)
goto bad;
180 else if (strcmp(*argv,
"-pass") == 0)
182 if (--argc < 1)
goto bad;
185 #ifndef OPENSSL_NO_ENGINE
186 else if (strcmp(*argv,
"-engine") == 0)
188 if (--argc < 1)
goto bad;
192 else if (strcmp(*argv,
"-d") == 0)
194 else if (strcmp(*argv,
"-p") == 0)
196 else if (strcmp(*argv,
"-v") == 0)
198 else if (strcmp(*argv,
"-nopad") == 0)
200 else if (strcmp(*argv,
"-salt") == 0)
202 else if (strcmp(*argv,
"-nosalt") == 0)
204 else if (strcmp(*argv,
"-debug") == 0)
206 else if (strcmp(*argv,
"-P") == 0)
208 else if (strcmp(*argv,
"-A") == 0)
210 else if (strcmp(*argv,
"-a") == 0)
212 else if (strcmp(*argv,
"-base64") == 0)
215 else if (strcmp(*argv,
"-z") == 0)
218 else if (strcmp(*argv,
"-bufsize") == 0)
220 if (--argc < 1)
goto bad;
221 bufsize=(
unsigned char *)*(++argv);
223 else if (strcmp(*argv,
"-k") == 0)
225 if (--argc < 1)
goto bad;
228 else if (strcmp(*argv,
"-kfile") == 0)
230 static char buf[128];
234 if (--argc < 1)
goto bad;
236 infile=fopen(file,
"r");
244 if (!fgets(buf,
sizeof buf,infile))
253 ((buf[i-1] ==
'\n') || (buf[i-1] ==
'\r')))
256 ((buf[i-1] ==
'\n') || (buf[i-1] ==
'\r')))
265 else if (strcmp(*argv,
"-K") == 0)
267 if (--argc < 1)
goto bad;
270 else if (strcmp(*argv,
"-S") == 0)
272 if (--argc < 1)
goto bad;
275 else if (strcmp(*argv,
"-iv") == 0)
277 if (--argc < 1)
goto bad;
280 else if (strcmp(*argv,
"-md") == 0)
282 if (--argc < 1)
goto bad;
285 else if (strcmp(*argv,
"-non-fips-allow") == 0)
287 else if ((argv[0][0] ==
'-') &&
292 else if (strcmp(*argv,
"-none") == 0)
304 BIO_printf(
bio_err,
"%-14s base64 encode/decode, depending on encryption flag\n",
"-a/-base64");
306 BIO_printf(
bio_err,
"%-14s passphrase is the first line of the file argument\n",
"-kfile");
307 BIO_printf(
bio_err,
"%-14s the next argument is the md to use to create a key\n",
"-md");
308 BIO_printf(
bio_err,
"%-14s from a passphrase. One of md2, md5, sha or sha1\n",
"");
314 #ifndef OPENSSL_NO_ENGINE
315 BIO_printf(
bio_err,
"%-14s use engine e, possibly a hardware device.\n",
"-engine e");
330 #ifndef OPENSSL_NO_ENGINE
349 for (n=0; *bufsize; bufsize++)
352 if ((i <=
'9') && (i >=
'0'))
361 if (*bufsize !=
'\0')
368 if (base64 && n < 80) n=80;
376 if ((buff == NULL) || (strbuf == NULL))
384 if ((in == NULL) || (out == NULL))
399 #ifndef OPENSSL_NO_SETVBUF_IONBF
401 setvbuf(stdin, (
char *)NULL, _IONBF, 0);
414 if(!str && passarg) {
422 if ((str == NULL) && (cipher != NULL) && (hkey == NULL))
430 (enc)?
"encryption":
"decryption");
435 if (strbuf[0] ==
'\0')
455 #ifndef OPENSSL_NO_SETVBUF_IONBF
457 setvbuf(stdout, (
char *)NULL, _IONBF, 0);
459 #ifdef OPENSSL_SYS_VMS
482 if ((bzl=
BIO_new(BIO_f_zlib())) == NULL)
520 if(nosalt) sptr = NULL;
524 if(!
set_hex(hsalt,salt,
sizeof salt)) {
526 "invalid hex salt value\n");
534 sizeof magic-1) !=
sizeof magic-1
537 sizeof salt) !=
sizeof salt)) {
541 }
else if(
BIO_read(rbio,mbuf,
sizeof mbuf) !=
sizeof mbuf
543 (
unsigned char *)salt,
544 sizeof salt) !=
sizeof salt) {
547 }
else if(memcmp(mbuf,magic,
sizeof magic-1)) {
556 (
unsigned char *)str,
557 strlen(str),1,key,iv);
567 if ((hiv != NULL) && !
set_hex(hiv,iv,
sizeof iv))
572 if ((hiv == NULL) && (str == NULL)
581 if ((hkey != NULL) && !
set_hex(hkey,key,
sizeof key))
630 for (i=0; i<(int)
sizeof(salt); i++)
631 printf(
"%02X",salt[i]);
637 for (i=0; i<cipher->
key_len; i++)
638 printf(
"%02X",key[i]);
644 for (i=0; i<cipher->
iv_len; i++)
645 printf(
"%02X",iv[i]);
662 inl=
BIO_read(rbio,(
char *)buff,bsize);
664 if (
BIO_write(wbio,(
char *)buff,inl) != inl)
698 int set_hex(
char *in,
unsigned char *out,
int size)
712 j=(
unsigned char)*in;
715 if ((j >=
'0') && (j <=
'9'))
717 else if ((j >=
'A') && (j <=
'F'))
719 else if ((j >=
'a') && (j <=
'f'))