Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/bdes Make this build in a WARNS'ified environment.



details:   https://anonhg.NetBSD.org/src/rev/b420097ad02b
branches:  trunk
changeset: 488009:b420097ad02b
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jun 16 17:16:33 2000 +0000

description:
Make this build in a WARNS'ified environment.

diffstat:

 usr.bin/bdes/bdes.c |  185 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 112 insertions(+), 73 deletions(-)

diffs (truncated from 504 to 300 lines):

diff -r d10cdad7d81a -r b420097ad02b usr.bin/bdes/bdes.c
--- a/usr.bin/bdes/bdes.c       Fri Jun 16 17:15:54 2000 +0000
+++ b/usr.bin/bdes/bdes.c       Fri Jun 16 17:16:33 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdes.c,v 1.1.1.1 2000/06/16 16:50:39 thorpej Exp $     */
+/*     $NetBSD: bdes.c,v 1.2 2000/06/16 17:16:33 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,17 +40,17 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1991, 1993\n\
-       The Regents of the University of California.  All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n");
 #endif /* not lint */
 
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)bdes.c     8.1 (Berkeley) 6/6/93";
 #else
-static char rcsid[] = "$NetBSD: bdes.c,v 1.1.1.1 2000/06/16 16:50:39 thorpej Exp $";
+__RCSID("$NetBSD: bdes.c,v 1.2 2000/06/16 17:16:33 thorpej Exp $");
 #endif
 #endif /* not lint */
 
@@ -103,22 +103,22 @@
 #ifdef FASTWAY
 #define        DES_KEY(buf) \
        if (des_setkey(buf)) \
-               err("des_setkey", 0);
+               bdes_err(0, "des_setkey");
 #define        DES_XFORM(buf) \
        if (des_cipher(buf, buf, 0L, (inverse ? -1 : 1))) \
-               err("des_cipher", 0);
+               bdes_err(0, "des_cipher");
 #else
 #define        DES_KEY(buf)    {                                               \
                                char bits1[64]; /* bits of key */       \
                                expand(buf, bits1);                     \
                                if (setkey(bits1))                      \
-                                       err("setkey", 0);               \
+                                       bdes_err(0, "setkey");          \
                        }
 #define        DES_XFORM(buf)  {                                               \
                                char bits1[64]; /* bits of message */   \
                                expand(buf, bits1);                     \
                                if (encrypt(bits1, inverse))            \
-                                       err("encrypt", 0);              \
+                                       bdes_err(0, "encrypt");         \
                                compress(bits1, buf);                   \
                        }
 #endif
@@ -129,7 +129,7 @@
 #define        READ(buf, n)    fread(buf, sizeof(char), n, stdin)
 #define WRITE(buf,n)                                           \
                if (fwrite(buf, sizeof(char), n, stdout) != n)  \
-                       err(bn, NULL);
+                       bdes_err(bn, NULL);
 
 /*
  * some things to make references easier
@@ -163,12 +163,30 @@
 int fbbits = -1;                       /* number of feedback bits */
 int pflag;                             /* 1 to preserve parity bits */
 
-main(ac, av)
-       int ac;                         /* arg count */
-       char **av;                      /* arg vector */
+int    setbits(char *, int);
+void   bdes_err(int, const char *);
+int    tobinhex(char, int);
+void   cvtkey(char *, char *);
+void   makekey(Desbuf);
+void   ecbenc(void);
+void   ecbdec(void);
+void   cbcenc(void);
+void   cbcdec(void);
+void   cbcauth(void);
+void   cfbenc(void);
+void   cfbdec(void);
+void   cfbaenc(void);
+void   cfbadec(void);
+void   ofbenc(void);
+void   ofbdec(void);
+void   cfbauth(void);
+void   expand(Desbuf, char *);
+void   compress(char *, Desbuf);
+void   usage(void);
+
+int
+main(int ac, char *av[])
 {
-       extern int optind;              /* option (argument) number */
-       extern char *optarg;            /* argument to option if any */
        register int i;                 /* counter in a for loop */
        register char *p;               /* used to obtain the key */
        Desbuf msgbuf;                  /* I/O buffer */
@@ -208,16 +226,20 @@
                case 'F':               /* use alternative CFB mode */
                        alg = ALG_CFBA;
                        if ((fbbits = setbits(optarg, 7)) > 56 || fbbits == 0)
-                               err(-1, "-F: number must be 1-56 inclusive");
+                               bdes_err(-1,
+                                   "-F: number must be 1-56 inclusive");
                        else if (fbbits == -1)
-                               err(-1, "-F: number must be a multiple of 7");
+                               bdes_err(-1,
+                                   "-F: number must be a multiple of 7");
                        break;
                case 'f':               /* use CFB mode */
                        alg = ALG_CFB;
                        if ((fbbits = setbits(optarg, 8)) > 64 || fbbits == 0)
-                               err(-1, "-f: number must be 1-64 inclusive");
+                               bdes_err(-1,
+                                   "-f: number must be 1-64 inclusive");
                        else if (fbbits == -1)
-                               err(-1, "-f: number must be a multiple of 8");
+                               bdes_err(-1,
+                                   "-f: number must be a multiple of 8");
                        break;
                case 'k':               /* encryption key */
                        kflag = 1;
@@ -226,14 +248,17 @@
                case 'm':               /* number of bits for MACing */
                        mode = MODE_AUTHENTICATE;
                        if ((macbits = setbits(optarg, 1)) > 64)
-                               err(-1, "-m: number must be 0-64 inclusive");
+                               bdes_err(-1,
+                                   "-m: number must be 0-64 inclusive");
                        break;
                case 'o':               /* use OFB mode */
                        alg = ALG_OFB;
                        if ((fbbits = setbits(optarg, 8)) > 64 || fbbits == 0)
-                               err(-1, "-o: number must be 1-64 inclusive");
+                               bdes_err(-1,
+                                   "-o: number must be 1-64 inclusive");
                        else if (fbbits == -1)
-                               err(-1, "-o: number must be a multiple of 8");
+                               bdes_err(-1,
+                                   "-o: number must be a multiple of 8");
                        break;
                case 'p':               /* preserve parity bits */
                        pflag = 1;
@@ -293,7 +318,7 @@
        case ALG_CFBA:
                switch(mode) {
                case MODE_AUTHENTICATE: /* authenticate using CFBA mode */
-                       err(-1, "can't authenticate with CFBA mode");
+                       bdes_err(-1, "can't authenticate with CFBA mode");
                        break;
                case MODE_DECRYPT:      /* decrypt using CFBA mode */
                        cfbadec();
@@ -306,7 +331,7 @@
        case ALG_ECB:
                switch(mode) {
                case MODE_AUTHENTICATE: /* authenticate using ECB mode */
-                       err(-1, "can't authenticate with ECB mode");
+                       bdes_err(-1, "can't authenticate with ECB mode");
                        break;
                case MODE_DECRYPT:      /* decrypt using ECB mode */
                        ecbdec();
@@ -319,7 +344,7 @@
        case ALG_OFB:
                switch(mode) {
                case MODE_AUTHENTICATE: /* authenticate using OFB mode */
-                       err(-1, "can't authenticate with OFB mode");
+                       bdes_err(-1, "can't authenticate with OFB mode");
                        break;
                case MODE_DECRYPT:      /* decrypt using OFB mode */
                        ofbdec();
@@ -336,9 +361,8 @@
 /*
  * print a warning message and, possibly, terminate
  */
-err(n, s)
-       int n;                  /* offending block number */
-       char *s;                /* the message */
+void
+bdes_err(int n, const char *s)
 {
        if (n > 0)
                (void)fprintf(stderr, "bdes (block %d): ", n);
@@ -351,9 +375,8 @@
 /*
  * map a hex character to an integer
  */
-tobinhex(c, radix)
-       char c;                 /* char to be converted */
-       int radix;              /* base (2 to 16) */
+int
+tobinhex(char c, int radix)
 {
        switch(c) {
        case '0':               return(0x0);
@@ -382,9 +405,8 @@
 /*
  * convert the key to a bit pattern
  */
-cvtkey(obuf, ibuf)
-       char *obuf;                     /* bit pattern */
-       char *ibuf;                     /* the key itself */
+void
+cvtkey(char *obuf, char *ibuf)
 {
        register int i, j;              /* counter in a for loop */
        int nbuf[64];                   /* used for hex/key translation */
@@ -407,7 +429,7 @@
                         */
                        for (i = 0; ibuf[i] && i < 16; i++)
                                if ((nbuf[i] = tobinhex(ibuf[i], 16)) == -1)
-                                       err(-1, "bad hex digit in key");
+                                       bdes_err(-1, "bad hex digit in key");
                        while (i < 16)
                                nbuf[i++] = 0;
                        for (i = 0; i < 8; i++)
@@ -427,7 +449,7 @@
                         */
                        for (i = 0; ibuf[i] && i < 16; i++)
                                if ((nbuf[i] = tobinhex(ibuf[i], 2)) == -1)
-                                       err(-1, "bad binary digit in key");
+                                       bdes_err(-1, "bad binary digit in key");
                        while (i < 64)
                                nbuf[i++] = 0;
                        for (i = 0; i < 8; i++)
@@ -450,9 +472,8 @@
  * 2. must be a valid decimal number
  * 3. must be a multiple of mult
  */
-setbits(s, mult)
-       char *s;                        /* the ASCII string */
-       int mult;                       /* what it must be a multiple of */
+int
+setbits(char *s, int mult)
 {
        register char *p;               /* pointer in a for loop */
        register int n = 0;             /* the integer collected */
@@ -469,7 +490,7 @@
                if (isdigit(*p))
                        n = n * 10 + *p - '0';
                else {
-                       err(-1, "bad decimal digit in MAC length");
+                       bdes_err(-1, "bad decimal digit in MAC length");
                }
        }
        /*
@@ -492,8 +513,8 @@
  * systems set the parity (high) bit of each character to 0, and the
  * DES ignores the low order bit of each character.
  */
-makekey(buf)
-       Desbuf buf;                             /* key block */
+void
+makekey(Desbuf buf)
 {
        register int i, j;                      /* counter in a for loop */
        register int par;                       /* parity counter */
@@ -520,7 +541,8 @@
 /*
  * This encrypts using the Electronic Code Book mode of DES
  */
-ecbenc()
+void
+ecbenc(void)
 {
        register int n;         /* number of bytes actually read */
        register int bn;        /* block number */
@@ -548,7 +570,8 @@
 /*
  * This decrypts using the Electronic Code Book mode of DES
  */
-ecbdec()
+void
+ecbdec(void)
 {
        register int n;         /* number of bytes actually read */
        register int c;         /* used to test for EOF */
@@ -566,20 +589,22 @@
                if ((c = getchar()) == EOF) {
                        n = CHAR(msgbuf, 7);
                        if (n < 0 || n > 7)
-                               err(bn, "decryption failed (block corrupted)");
+                               bdes_err(bn,
+                                   "decryption failed (block corrupted)");
                }
                else
                        (void)ungetc(c, stdin);
                WRITE(BUFFER(msgbuf), n);
        }
        if (n > 0)
-               err(bn, "decryption failed (incomplete block)");
+               bdes_err(bn, "decryption failed (incomplete block)");
 }
 
 /*



Home | Main Index | Thread Index | Old Index