63 #ifndef OPENSSL_SYS_MSDOS
64 #ifndef OPENSSL_SYS_VMS
65 #include OPENSSL_UNISTD
80 #ifdef OPENSSL_SYS_VMS
85 #include <sys/types.h>
97 int uufread(
unsigned char *out,
int size,
unsigned int num,FILE *
fp);
98 int uuencode(
unsigned char *in,
int num,
unsigned char *out);
99 int uudecode(
unsigned char *in,
int num,
unsigned char *out);
103 #ifdef OPENSSL_SYS_VMS
104 #define EXIT(a) exit(a&0x10000000L)
106 #define EXIT(a) exit(a)
109 #define BUFSIZE (8*1024)
119 #define INUUBUFN (45*100)
120 #define OUTUUBUF (65*100)
122 unsigned char bb[300];
126 int vflag,
cflag,
eflag,
dflag,
kflag,
bflag,
fflag,
sflag,
uflag,
flag3,
hflag,
error;
128 int main(
int argc,
char **argv)
131 struct stat ins,outs;
133 char *
in=NULL,*
out=NULL;
137 memset(
key,0,
sizeof(
key));
139 for (i=1; i<argc; i++)
142 if ((p[0] ==
'-') && (p[1] !=
'\0'))
205 fputs(
"must have a key with the -k option\n",stderr);
214 for (j=strlen(argv[i])-1; j>=0; j--)
219 fprintf(stderr,
"'%c' unknown flag\n",p[-1]);
229 else if (out == NULL)
265 #ifndef OPENSSL_SYS_MSDOS
266 (stat(in,&ins) != -1) &&
267 (stat(out,&outs) != -1) &&
268 (ins.st_dev == outs.st_dev) &&
269 (ins.st_ino == outs.st_ino))
271 (strcmp(in,out) == 0))
274 fputs(
"input and output file are the same\n",stderr);
281 fputs(
"password error\n",stderr);
287 else if ((
DES_IN=fopen(in,
"r")) == NULL)
289 perror(
"opening input file");
299 else if ((
DES_OUT=fopen(out,
"w")) == NULL)
301 perror(
"opening output file");
305 #ifdef OPENSSL_SYS_MSDOS
325 static const char *Usage[]={
326 "des <options> [input-file [output-file]]",
328 "-v : des(1) version number",
329 "-e : encrypt using SunOS compatible user key to DES key conversion.",
331 "-d : decrypt using SunOS compatible user key to DES key conversion.",
333 "-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
334 " DES key conversion and output to ckname (stdout default,",
335 " stderr if data being output on stdout). The checksum is",
336 " generated before encryption and after decryption if used",
337 " in conjunction with -[eEdD].",
338 "-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
339 "-k key : use key 'key'",
340 "-h : the key that is entered will be a hexadecimal number",
341 " that is used directly as the des key",
342 "-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
343 " (uuname is the filename to put in the uuencode header).",
344 "-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
345 "-3 : encrypt using triple DES encryption. This uses 2 keys",
346 " generated from the input key. If the input key is less",
347 " than 8 characters long, this is equivalent to normal",
348 " encryption. Default is triple cbc, -b makes it triple ecb.",
351 for (u=(
char **)Usage; *
u; u++)
363 extern unsigned long time();
374 #ifndef OPENSSL_SYS_MSDOS
377 static unsigned char *buf=NULL,*obuf=NULL;
384 fputs(
"Not enough memory\n",stderr);
398 if ((*p <=
'9') && (*p >=
'0'))
400 else if ((*p <=
'f') && (*p >=
'a'))
402 else if ((*p <=
'F') && (*p >=
'A'))
406 fputs(
"Bad hex key\n",stderr);
411 if ((*p <=
'9') && (*p >=
'0'))
413 else if ((*p <=
'f') && (*p >=
'a'))
415 else if ((*p <=
'F') && (*p >=
'A'))
419 fputs(
"Bad hex key\n",stderr);
463 memset(iv,0,
sizeof(iv));
464 memset(iv2,0,
sizeof(iv2));
478 perror(
"read error");
487 for (i=7-rem; i>0; i--)
499 (
long)len,&ks,&
cksum);
523 if (rem) memcpy(tmpbuf,&(buf[l]),
529 if (rem) memcpy(&(buf[l]),tmpbuf,
537 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
539 if (rem) memcpy(buf,&(buf[l]),(
unsigned int)rem);
545 j=
uufwrite(obuf,1,(
unsigned int)l-i,
548 j=fwrite(obuf,1,(
unsigned int)l-i,
552 perror(
"Write error");
581 perror(
"read error");
610 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
620 if (feof(
DES_IN) && (ll == 0))
624 if ((last > 7) || (last < 0))
626 fputs(
"The file was not decrypted correctly.\n",
639 j=fwrite(obuf,1,(
unsigned int)l-i,
DES_OUT);
642 perror(
"Write error");
649 if ((l == 0) && feof(
DES_IN))
break;
681 if (Exit)
EXIT(Exit);
687 int i,j,left,rem,ret=
num;
692 fprintf(fp,
"begin 600 %s\n",
710 fwrite(
b,1,(
unsigned int)j,fp);
720 fwrite(
b,1,(
unsigned int)j,fp);
727 fwrite(
b,1,(
unsigned int)j,fp);
732 memcpy(
uubuf,&(data[i]),(
unsigned int)rem);
741 static const char *end=
" \nend\n";
749 fwrite(
b,1,(
unsigned int)j,fp);
751 fwrite(end,1,strlen(end),fp);
767 fgets((
char *)
b,300,fp);
770 fprintf(stderr,
"no 'begin' found in uuencoded input\n");
773 if (strncmp((
char *)
b,
"begin ",6) == 0)
break;
781 memcpy(out,
bb,(
unsigned int)valid);
788 fgets((
char *)
b,300,fp);
789 if (
b[0] ==
'\0')
break;
791 if ((
b[0] ==
'e') && (
b[1] ==
'n') && (
b[2] ==
'd'))
796 fgets((
char *)
b,300,fp);
806 memcpy(&(out[tot]),
bb,(
unsigned int)j);
808 memcpy(
bb,&(
bb[j]),(
unsigned int)i-j);
812 memcpy(&(out[tot]),
bb,(
unsigned int)i);
818 #define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
819 l|=((DES_LONG)(*((c)++)))<< 8, \
820 l|=((DES_LONG)(*((c)++))))
822 #define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
823 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
824 *((c)++)=(unsigned char)(((l) )&0xff))
831 register unsigned char *
p;
834 for (j=0; j<
num; j+=45)
843 *(p++)=((l>>18)&0x3f)+
' ';
844 *(p++)=((l>>12)&0x3f)+
' ';
845 *(p++)=((l>> 6)&0x3f)+
' ';
846 *(p++)=((l )&0x3f)+
' ';
860 unsigned int n=0,space=0;
863 unsigned int blank=(
unsigned int)
'\n'-
' ';
875 fprintf(stderr,
"uuencoded line length too long\n");
880 for (i=0; i<n; j+=4,i+=3)
896 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
912 fprintf(stderr,
"bad uuencoded data values\n");
918 l=(w<<18)|(x<<12)|(y<< 6)|(z );
923 fprintf(stderr,
"missing nl in uuencoded line\n");