version 1.10, 2003/06/03 02:56:06 |
version 1.11, 2003/06/10 22:20:45 |
|
|
|
|
|
|
int |
int |
main(ac, av) |
main(int ac, char *av[]) |
int ac; /* arg count */ |
|
char **av; /* arg vector */ |
|
{ |
{ |
extern int optind; /* option (argument) number */ |
extern int optind; /* option (argument) number */ |
extern char *optarg; /* argument to option if any */ |
extern char *optarg; /* argument to option if any */ |
|
|
* map a hex character to an integer |
* map a hex character to an integer |
*/ |
*/ |
int |
int |
tobinhex(c, radix) |
tobinhex(char c, int radix) |
char c; /* char to be converted */ |
|
int radix; /* base (2 to 16) */ |
|
{ |
{ |
switch(c) { |
switch(c) { |
case '0': return(0x0); |
case '0': return(0x0); |
|
|
* convert the key to a bit pattern |
* convert the key to a bit pattern |
*/ |
*/ |
void |
void |
cvtkey(obuf, ibuf) |
cvtkey(char *obuf, char *ibuf) |
char *obuf; /* bit pattern */ |
|
char *ibuf; /* the key itself */ |
|
{ |
{ |
int i, j; /* counter in a for loop */ |
int i, j; /* counter in a for loop */ |
int nbuf[64]; /* used for hex/key translation */ |
int nbuf[64]; /* used for hex/key translation */ |
|
|
* 3. must be a multiple of mult |
* 3. must be a multiple of mult |
*/ |
*/ |
int |
int |
setbits(s, mult) |
setbits(char *s, int mult) |
char *s; /* the ASCII string */ |
|
int mult; /* what it must be a multiple of */ |
|
{ |
{ |
char *p; /* pointer in a for loop */ |
char *p; /* pointer in a for loop */ |
int n = 0; /* the integer collected */ |
int n = 0; /* the integer collected */ |
|
|
* DES ignores the low order bit of each character. |
* DES ignores the low order bit of each character. |
*/ |
*/ |
void |
void |
makekey(buf) |
makekey(Desbuf buf) |
Desbuf buf; /* key block */ |
|
{ |
{ |
int i, j; /* counter in a for loop */ |
int i, j; /* counter in a for loop */ |
int par; /* parity counter */ |
int par; /* parity counter */ |
|
|
* This encrypts using the Electronic Code Book mode of DES |
* This encrypts using the Electronic Code Book mode of DES |
*/ |
*/ |
void |
void |
ecbenc() |
ecbenc(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int bn; /* block number */ |
int bn; /* block number */ |
|
|
* This decrypts using the Electronic Code Book mode of DES |
* This decrypts using the Electronic Code Book mode of DES |
*/ |
*/ |
void |
void |
ecbdec() |
ecbdec(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int c; /* used to test for EOF */ |
int c; /* used to test for EOF */ |
|
|
* This encrypts using the Cipher Block Chaining mode of DES |
* This encrypts using the Cipher Block Chaining mode of DES |
*/ |
*/ |
void |
void |
cbcenc() |
cbcenc(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int bn; /* block number */ |
int bn; /* block number */ |
|
|
* This decrypts using the Cipher Block Chaining mode of DES |
* This decrypts using the Cipher Block Chaining mode of DES |
*/ |
*/ |
void |
void |
cbcdec() |
cbcdec(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
Desbuf msgbuf; /* I/O buffer */ |
Desbuf msgbuf; /* I/O buffer */ |
|
|
* This authenticates using the Cipher Block Chaining mode of DES |
* This authenticates using the Cipher Block Chaining mode of DES |
*/ |
*/ |
void |
void |
cbcauth() |
cbcauth(void) |
{ |
{ |
int n, j; /* number of bytes actually read */ |
int n, j; /* number of bytes actually read */ |
Desbuf msgbuf; /* I/O buffer */ |
Desbuf msgbuf; /* I/O buffer */ |
|
|
* This encrypts using the Cipher FeedBack mode of DES |
* This encrypts using the Cipher FeedBack mode of DES |
*/ |
*/ |
void |
void |
cfbenc() |
cfbenc(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int nbytes; /* number of bytes to read */ |
int nbytes; /* number of bytes to read */ |
|
|
* This decrypts using the Cipher Block Chaining mode of DES |
* This decrypts using the Cipher Block Chaining mode of DES |
*/ |
*/ |
void |
void |
cfbdec() |
cfbdec(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int c; /* used to test for EOF */ |
int c; /* used to test for EOF */ |
|
|
* This encrypts using the alternative Cipher FeedBack mode of DES |
* This encrypts using the alternative Cipher FeedBack mode of DES |
*/ |
*/ |
void |
void |
cfbaenc() |
cfbaenc(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int nbytes; /* number of bytes to read */ |
int nbytes; /* number of bytes to read */ |
|
|
* This decrypts using the alternative Cipher Block Chaining mode of DES |
* This decrypts using the alternative Cipher Block Chaining mode of DES |
*/ |
*/ |
void |
void |
cfbadec() |
cfbadec(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int c; /* used to test for EOF */ |
int c; /* used to test for EOF */ |
|
|
* This encrypts using the Output FeedBack mode of DES |
* This encrypts using the Output FeedBack mode of DES |
*/ |
*/ |
void |
void |
ofbenc() |
ofbenc(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int c; /* used to test for EOF */ |
int c; /* used to test for EOF */ |
|
|
* This decrypts using the Output Block Chaining mode of DES |
* This decrypts using the Output Block Chaining mode of DES |
*/ |
*/ |
void |
void |
ofbdec() |
ofbdec(void) |
{ |
{ |
int n; /* number of bytes actually read */ |
int n; /* number of bytes actually read */ |
int c; /* used to test for EOF */ |
int c; /* used to test for EOF */ |
|
|
* This authenticates using the Cipher FeedBack mode of DES |
* This authenticates using the Cipher FeedBack mode of DES |
*/ |
*/ |
void |
void |
cfbauth() |
cfbauth(void) |
{ |
{ |
int n, j; /* number of bytes actually read */ |
int n, j; /* number of bytes actually read */ |
int nbytes; /* number of bytes to read */ |
int nbytes; /* number of bytes to read */ |
|
|
* message about usage |
* message about usage |
*/ |
*/ |
void |
void |
usage() |
usage(void) |
{ |
{ |
(void)fprintf(stderr, "%s\n", |
(void)fprintf(stderr, "%s\n", |
"usage: bdes [-abdp] [-F bit] [-f bit] [-k key] [-m bit] [-o bit] [-v vector]"); |
"usage: bdes [-abdp] [-F bit] [-f bit] [-k key] [-m bit] [-o bit] [-v vector]"); |