version 1.11, 2003/06/10 22:20:45 |
version 1.12, 2003/07/02 21:04:09 |
|
|
#include <string.h> |
#include <string.h> |
|
|
typedef char Desbuf[8]; |
typedef char Desbuf[8]; |
int tobinhexi(char, int); |
int tobinhex(char, int); |
void cvtkey(char *, char *); |
void cvtkey(char *, char *); |
int setbits(char *, int); |
int setbits(char *, int); |
void makekey(Desbuf); |
void makekey(Desbuf); |
|
|
/* process the argument list */ |
/* process the argument list */ |
kflag = 0; |
kflag = 0; |
while ((i = getopt(argc, argv, "abdF:f:k:m:o:pv:")) != -1) |
while ((i = getopt(argc, argv, "abdF:f:k:m:o:pv:")) != -1) |
switch(i) { |
switch (i) { |
case 'a': /* key is ASCII */ |
case 'a': /* key is ASCII */ |
keybase = KEY_ASCII; |
keybase = KEY_ASCII; |
break; |
break; |
|
|
makekey(msgbuf); |
makekey(msgbuf); |
inverse = (alg == ALG_CBC || alg == ALG_ECB) && mode == MODE_DECRYPT; |
inverse = (alg == ALG_CBC || alg == ALG_ECB) && mode == MODE_DECRYPT; |
|
|
switch(alg) { |
switch (alg) { |
case ALG_CBC: |
case ALG_CBC: |
switch(mode) { |
switch (mode) { |
case MODE_AUTHENTICATE: /* authenticate using CBC mode */ |
case MODE_AUTHENTICATE: /* authenticate using CBC mode */ |
cbcauth(); |
cbcauth(); |
break; |
break; |
|
|
} |
} |
break; |
break; |
case ALG_CFB: |
case ALG_CFB: |
switch(mode) { |
switch (mode) { |
case MODE_AUTHENTICATE: /* authenticate using CFB mode */ |
case MODE_AUTHENTICATE: /* authenticate using CFB mode */ |
cfbauth(); |
cfbauth(); |
break; |
break; |
|
|
} |
} |
break; |
break; |
case ALG_CFBA: |
case ALG_CFBA: |
switch(mode) { |
switch (mode) { |
case MODE_AUTHENTICATE: /* authenticate using CFBA mode */ |
case MODE_AUTHENTICATE: /* authenticate using CFBA mode */ |
err(1, "can't authenticate with CFBA mode"); |
err(1, "can't authenticate with CFBA mode"); |
break; |
break; |
|
|
} |
} |
break; |
break; |
case ALG_ECB: |
case ALG_ECB: |
switch(mode) { |
switch (mode) { |
case MODE_AUTHENTICATE: /* authenticate using ECB mode */ |
case MODE_AUTHENTICATE: /* authenticate using ECB mode */ |
err(1, "can't authenticate with ECB mode"); |
err(1, "can't authenticate with ECB mode"); |
break; |
break; |
|
|
} |
} |
break; |
break; |
case ALG_OFB: |
case ALG_OFB: |
switch(mode) { |
switch (mode) { |
case MODE_AUTHENTICATE: /* authenticate using OFB mode */ |
case MODE_AUTHENTICATE: /* authenticate using OFB mode */ |
err(1, "can't authenticate with OFB mode"); |
err(1, "can't authenticate with OFB mode"); |
break; |
break; |
|
|
int |
int |
tobinhex(char c, int radix) |
tobinhex(char c, int radix) |
{ |
{ |
switch(c) { |
switch (c) { |
case '0': return(0x0); |
case '0': return(0x0); |
case '1': return(0x1); |
case '1': return(0x1); |
case '2': return(radix > 2 ? 0x2 : -1); |
case '2': return(radix > 2 ? 0x2 : -1); |
|
|
/* |
/* |
* just switch on the key base |
* just switch on the key base |
*/ |
*/ |
switch(keybase) { |
switch (keybase) { |
case KEY_ASCII: /* ASCII to integer */ |
case KEY_ASCII: /* ASCII to integer */ |
(void)strncpy(obuf, ibuf, 8); |
(void)strncpy(obuf, ibuf, 8); |
return; |
return; |