[BACK]Return to bdes.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / bdes

Diff for /src/usr.bin/bdes/Attic/bdes.c between version 1.4 and 1.5

version 1.4, 1998/05/07 19:12:17 version 1.5, 2001/02/05 08:38:23
Line 85 
Line 85 
  * or the technical report for a complete reference).   * or the technical report for a complete reference).
  */   */
   
   #include <err.h>
 #include <errno.h>  #include <errno.h>
 #include <unistd.h>  #include <unistd.h>
 #include <stdio.h>  #include <stdio.h>
Line 92 
Line 93 
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
   typedef char Desbuf[8];
   int     tobinhexi __P((char, int));
   void    cvtkey __P((char *, char *));
   int     setbits __P((char *, int));
   void    makekey __P((Desbuf));
   void    ecbenc __P((void));
   void    ecbdec __P((void));
   void    cbcenc __P((void));
   void    cbcdec __P((void));
   void    cbcauth __P((void));
   void    cfbenc __P((void));
   void    cfbdec __P((void));
   void    cfbaenc __P((void));
   void    cfbadec __P((void));
   void    cfbauth __P((void));
   void    ofbdec __P((void));
   void    ofbenc __P((void));
   void    usage __P((void));
   
 /*  /*
  * BSD and System V systems offer special library calls that do   * BSD and System V systems offer special library calls that do
  * block moves and fills, so if possible we take advantage of them   * block moves and fills, so if possible we take advantage of them
Line 104 
Line 124 
 #ifdef  FASTWAY  #ifdef  FASTWAY
 #define DES_KEY(buf) \  #define DES_KEY(buf) \
         if (des_setkey(buf)) \          if (des_setkey(buf)) \
                 err("des_setkey", 0);                  err(1, "des_setkey");
 #define DES_XFORM(buf) \  #define DES_XFORM(buf) \
         if (des_cipher(buf, buf, 0L, (inverse ? -1 : 1))) \          if (des_cipher(buf, buf, 0L, (inverse ? -1 : 1))) \
                 err("des_cipher", 0);                  err(1, "des_cipher");
 #else  #else
 #define DES_KEY(buf)    {                                               \  #define DES_KEY(buf)    {                                               \
                                 char bits1[64]; /* bits of key */       \                                  char bits1[64]; /* bits of key */       \
                                 expand(buf, bits1);                     \                                  expand(buf, bits1);                     \
                                 if (setkey(bits1))                      \                                  if (setkey(bits1))                      \
                                         err("setkey", 0);               \                                          err(1, "setkey");               \
                         }                          }
 #define DES_XFORM(buf)  {                                               \  #define DES_XFORM(buf)  {                                               \
                                 char bits1[64]; /* bits of message */   \                                  char bits1[64]; /* bits of message */   \
                                 expand(buf, bits1);                     \                                  expand(buf, bits1);                     \
                                 if (encrypt(bits1, inverse))            \                                  if (encrypt(bits1, inverse))            \
                                         err("encrypt", 0);              \                                          err(1, "encrypt");              \
                                 compress(bits1, buf);                   \                                  compress(bits1, buf);                   \
                         }                          }
 #endif  #endif
Line 135 
Line 155 
 /*  /*
  * some things to make references easier   * some things to make references easier
  */   */
 typedef char Desbuf[8];  
 #define CHAR(x,i)       (x[i])  #define CHAR(x,i)       (x[i])
 #define UCHAR(x,i)      (x[i])  #define UCHAR(x,i)      (x[i])
 #define BUFFER(x)       (x)  #define BUFFER(x)       (x)
Line 164 
Line 183 
 int fbbits = -1;                        /* number of feedback bits */  int fbbits = -1;                        /* number of feedback bits */
 int pflag;                              /* 1 to preserve parity bits */  int pflag;                              /* 1 to preserve parity bits */
   
   
   int
 main(ac, av)  main(ac, av)
         int ac;                         /* arg count */          int ac;                         /* arg count */
         char **av;                      /* arg vector */          char **av;                      /* arg vector */
Line 335 
Line 356 
 }  }
   
 /*  /*
  * print a warning message and, possibly, terminate  
  */  
 err(n, s)  
         int n;                  /* offending block number */  
         char *s;                /* the message */  
 {  
         if (n > 0)  
                 (void)fprintf(stderr, "bdes (block %d): ", n);  
         else  
                 (void)fprintf(stderr, "bdes: ");  
         (void)fprintf(stderr, "%s\n", s ? s : strerror(errno));  
         exit(1);  
 }  
   
 /*  
  * map a hex character to an integer   * map a hex character to an integer
  */   */
   int
 tobinhex(c, radix)  tobinhex(c, radix)
         char c;                 /* char to be converted */          char c;                 /* char to be converted */
         int radix;              /* base (2 to 16) */          int radix;              /* base (2 to 16) */
Line 383 
Line 390 
 /*  /*
  * convert the key to a bit pattern   * convert the key to a bit pattern
  */   */
   void
 cvtkey(obuf, ibuf)  cvtkey(obuf, ibuf)
         char *obuf;                     /* bit pattern */          char *obuf;                     /* bit pattern */
         char *ibuf;                     /* the key itself */          char *ibuf;                     /* the key itself */
Line 451 
Line 459 
  * 2. must be a valid decimal number   * 2. must be a valid decimal number
  * 3. must be a multiple of mult   * 3. must be a multiple of mult
  */   */
   int
 setbits(s, mult)  setbits(s, mult)
         char *s;                        /* the ASCII string */          char *s;                        /* the ASCII string */
         int mult;                       /* what it must be a multiple of */          int mult;                       /* what it must be a multiple of */
Line 493 
Line 502 
  * systems set the parity (high) bit of each character to 0, and the   * systems set the parity (high) bit of each character to 0, and the
  * DES ignores the low order bit of each character.   * DES ignores the low order bit of each character.
  */   */
   void
 makekey(buf)  makekey(buf)
         Desbuf buf;                             /* key block */          Desbuf buf;                             /* key block */
 {  {
Line 521 
Line 531 
 /*  /*
  * This encrypts using the Electronic Code Book mode of DES   * This encrypts using the Electronic Code Book mode of DES
  */   */
   void
 ecbenc()  ecbenc()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 549 
Line 560 
 /*  /*
  * This decrypts using the Electronic Code Book mode of DES   * This decrypts using the Electronic Code Book mode of DES
  */   */
   void
 ecbdec()  ecbdec()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 580 
Line 592 
 /*  /*
  * This encrypts using the Cipher Block Chaining mode of DES   * This encrypts using the Cipher Block Chaining mode of DES
  */   */
   void
 cbcenc()  cbcenc()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 613 
Line 626 
 /*  /*
  * This decrypts using the Cipher Block Chaining mode of DES   * This decrypts using the Cipher Block Chaining mode of DES
  */   */
   void
 cbcdec()  cbcdec()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 649 
Line 663 
 /*  /*
  * This authenticates using the Cipher Block Chaining mode of DES   * This authenticates using the Cipher Block Chaining mode of DES
  */   */
   void
 cbcauth()  cbcauth()
 {  {
         register int n, j;              /* number of bytes actually read */          register int n, j;              /* number of bytes actually read */
Line 693 
Line 708 
 /*  /*
  * This encrypts using the Cipher FeedBack mode of DES   * This encrypts using the Cipher FeedBack mode of DES
  */   */
   void
 cfbenc()  cfbenc()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 734 
Line 750 
 /*  /*
  * This decrypts using the Cipher Block Chaining mode of DES   * This decrypts using the Cipher Block Chaining mode of DES
  */   */
   void
 cfbdec()  cfbdec()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 779 
Line 796 
 /*  /*
  * This encrypts using the alternative Cipher FeedBack mode of DES   * This encrypts using the alternative Cipher FeedBack mode of DES
  */   */
   void
 cfbaenc()  cfbaenc()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 824 
Line 842 
 /*  /*
  * This decrypts using the alternative Cipher Block Chaining mode of DES   * This decrypts using the alternative Cipher Block Chaining mode of DES
  */   */
   void
 cfbadec()  cfbadec()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 870 
Line 889 
 /*  /*
  * This encrypts using the Output FeedBack mode of DES   * This encrypts using the Output FeedBack mode of DES
  */   */
   void
 ofbenc()  ofbenc()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 915 
Line 935 
 /*  /*
  * This decrypts using the Output Block Chaining mode of DES   * This decrypts using the Output Block Chaining mode of DES
  */   */
   void
 ofbdec()  ofbdec()
 {  {
         register int n;         /* number of bytes actually read */          register int n;         /* number of bytes actually read */
Line 963 
Line 984 
 /*  /*
  * This authenticates using the Cipher FeedBack mode of DES   * This authenticates using the Cipher FeedBack mode of DES
  */   */
   void
 cfbauth()  cfbauth()
 {  {
         register int n, j;      /* number of bytes actually read */          register int n, j;      /* number of bytes actually read */
Line 1045 
Line 1067 
 /*  /*
  * message about usage   * message about usage
  */   */
   void
 usage()  usage()
 {  {
         (void)fprintf(stderr, "%s\n",          (void)fprintf(stderr, "%s\n",

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5