more cleanup - add const, reduce casting
authorKen Raeburn <raeburn@mit.edu>
Tue, 10 Apr 2001 08:31:43 +0000 (08:31 +0000)
committerKen Raeburn <raeburn@mit.edu>
Tue, 10 Apr 2001 08:31:43 +0000 (08:31 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13169 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/crypto/des/ChangeLog
src/lib/crypto/des/d3_cbc.c
src/lib/crypto/des/d3_kysched.c
src/lib/crypto/des/des_int.h
src/lib/crypto/des/f_cbc.c
src/lib/crypto/des/f_cksum.c
src/lib/crypto/des/f_sched.c
src/lib/crypto/des/weak_key.c

index c157d4811ff2b46ce39221cf2c6506a882e9f6b3..af3bd971f25029d0c9239594ebf2290a85dae1f5 100644 (file)
@@ -1,12 +1,23 @@
 2001-04-10  Ken Raeburn  <raeburn@mit.edu>
 
        * f_cksum.c (mit_des_cbc_cksum): Use const for input, key
-       schedule, and initial vector.
+       schedule, and initial vector.  Get rid of casts when possible.
        * f_cbc.c (mit_des_cbc_encrypt): Likewise.
-       * des_int.h (mit_des_cbc_cksum, mit_des_cbc_encrypt): Update
-       decls.
+       * f_sched.c (make_key_sched): Likewise.
+       * d3_cbc.c (mit_des3_cbc_encrypt): Likewise.
+       * d3_kysched.c (mit_des3_key_sched): Don't create new variables to
+       point to components of key and schedule, just index into the
+       argument variables.
+       * des_int.h (mit_des_cbc_cksum, mit_des_cbc_encrypt,
+       mit_des3_cbc_encrypt): Update decls.
        (mit_des_string_to_key_int): New decl.
 
+       * weak_key.c (mit_des_is_weak_key): Get rid of some unneeded
+       casts.
+
+       * des_int.h (make_key_sched): Define a macro to rename with
+       mit_des_ prefix.
+
        * des_int.h (des_cblock, des_key_schedule): Duplicate definitions
        here and in kerberosIV/des.h, using macro
        KRB5INT_DES_TYPES_DEFINED to avoid duplication.
index 0204b719bd866ca63304f425e6403c6a65e2f7ac..84d0af39adb1e58affc52fac17558e1c454d4e27 100644 (file)
@@ -32,21 +32,22 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt)
        const mit_des_cblock FAR *in;
        mit_des_cblock FAR *out;
        unsigned long length;
-       mit_des_key_schedule ks1, ks2, ks3;
-       mit_des_cblock ivec;
+       const mit_des_key_schedule ks1, ks2, ks3;
+       const mit_des_cblock ivec;
        int encrypt;
 {
     register unsigned DES_INT32 left, right;
     register unsigned DES_INT32 temp;
-    register unsigned DES_INT32 *kp1, *kp2, *kp3;
-    register unsigned char *ip, *op;
+    const unsigned DES_INT32 *kp1, *kp2, *kp3;
+    const unsigned char *ip;
+    unsigned char *op;
 
     /*
      * Get key pointer here.  This won't need to be reinitialized
      */
-    kp1 = (unsigned DES_INT32 *)ks1;
-    kp2 = (unsigned DES_INT32 *)ks2;
-    kp3 = (unsigned DES_INT32 *)ks3;
+    kp1 = (const unsigned DES_INT32 *)ks1;
+    kp2 = (const unsigned DES_INT32 *)ks2;
+    kp3 = (const unsigned DES_INT32 *)ks3;
 
     /*
      * Deal with encryption and decryption separately.
@@ -56,7 +57,7 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt)
         * Initialize left and right with the contents of the initial
         * vector.
         */
-       ip = (unsigned char *)ivec;
+       ip = ivec;
        GET_HALF_BLOCK(left, ip);
        GET_HALF_BLOCK(right, ip);
 
@@ -64,8 +65,8 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt)
         * Suitably initialized, now work the length down 8 bytes
         * at a time.
         */
-       ip = (unsigned char *)in;
-       op = (unsigned char *)out;
+       ip = *in;
+       op = *out;
        while (length > 0) {
            /*
             * Get more input, xor it in.  If the length is
@@ -130,15 +131,15 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt)
        /*
         * Prime the old cipher with ivec.
         */
-       ip = (unsigned char *)ivec;
+       ip = ivec;
        GET_HALF_BLOCK(ocipherl, ip);
        GET_HALF_BLOCK(ocipherr, ip);
 
        /*
         * Now do this in earnest until we run out of length.
         */
-       ip = (unsigned char *)in;
-       op = (unsigned char *)out;
+       ip = *in;
+       op = *out;
        for (;;) {              /* check done inside loop */
            /*
             * Read a block from the input into left and
index efd91c44b20c925dcbf53dd2e23903f504c38e81..6d9c2769796793556f23b81f6be3a626ff1dd4b8 100644 (file)
 #include "des_int.h"
 
 int
-mit_des3_key_sched(key,key_sched)
-    mit_des3_cblock key;
-    mit_des3_key_schedule key_sched;
+mit_des3_key_sched(k,schedule)
+    mit_des3_cblock k;
+    mit_des3_key_schedule schedule;
 {
-    mit_des_cblock *k = (mit_des_cblock *)key;
-    mit_des_key_schedule *schedule = (mit_des_key_schedule *)key_sched;
-    
     make_key_sched(k[0],schedule[0]);
     make_key_sched(k[1],schedule[1]);
     make_key_sched(k[2],schedule[2]);
index 01d840d0d3e80b9f3fef5e3d93ce11561e8dcc0b..8ff40ecd63f742ffb7c44b4ceca82a114f8ae614 100644 (file)
@@ -217,6 +217,7 @@ krb5_error_code mit_des_combine_subkeys
 int mit_des_pcbc_encrypt ();
 
 /* f_sched.c */
+#define make_key_sched mit_des_make_key_sched
 int make_key_sched (mit_des_cblock, mit_des_key_schedule);
 
 
@@ -248,13 +249,13 @@ extern int mit_des3_ecb_encrypt
 /* d3_cbc.c */
 extern int mit_des3_cbc_encrypt
        (const mit_des_cblock FAR *in,
-                  mit_des_cblock FAR *out,
-                  unsigned long length,
-                  mit_des_key_schedule ks1,
-                  mit_des_key_schedule ks2,
-                  mit_des_key_schedule ks3,
-                  mit_des_cblock ivec,
-                  int encrypt);
+        mit_des_cblock FAR *out,
+        unsigned long length,
+        const mit_des_key_schedule ks1,
+        const mit_des_key_schedule ks2,
+        const mit_des_key_schedule ks3,
+        const mit_des_cblock ivec,
+        int encrypt);
 
 /* d3_procky.c */
 extern krb5_error_code mit_des3_process_key
index fdc12501692e9de33fe5519549aa202ee8781a25..b6443328c466a03d462c06fa6684a90b99dab098 100644 (file)
@@ -64,7 +64,7 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt)
                 * Initialize left and right with the contents of the initial
                 * vector.
                 */
-               ip = (const unsigned char *)ivec;
+               ip = ivec;
                GET_HALF_BLOCK(left, ip);
                GET_HALF_BLOCK(right, ip);
 
@@ -72,8 +72,8 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt)
                 * Suitably initialized, now work the length down 8 bytes
                 * at a time.
                 */
-               ip = (unsigned char *)in;
-               op = (unsigned char *)out;
+               ip = *in;
+               op = *out;
                while (length > 0) {
                        /*
                         * Get more input, xor it in.  If the length is
@@ -143,15 +143,15 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt)
                /*
                 * Prime the old cipher with ivec.
                 */
-               ip = (const unsigned char *)ivec;
+               ip = ivec;
                GET_HALF_BLOCK(ocipherl, ip);
                GET_HALF_BLOCK(ocipherr, ip);
 
                /*
                 * Now do this in earnest until we run out of length.
                 */
-               ip = (unsigned char *)in;
-               op = (unsigned char *)out;
+               ip = *in;
+               op = *out;
                for (;;) {              /* check done inside loop */
                        /*
                         * Read a block from the input into left and
index 4fe97112387c9c7caf4f50e463e83a37247a6dc2..0cfadc1124181e56ff2a3fbd800107e8008e32bc 100644 (file)
@@ -47,7 +47,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec)
         * Initialize left and right with the contents of the initial
         * vector.
         */
-       ip = (const unsigned char *)ivec;
+       ip = ivec;
        GET_HALF_BLOCK(left, ip);
        GET_HALF_BLOCK(right, ip);
 
@@ -55,7 +55,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec)
         * Suitably initialized, now work the length down 8 bytes
         * at a time.
         */
-       ip = (const unsigned char *)in;
+       ip = in;
        len = length;
        while (len > 0) {
                /*
@@ -111,7 +111,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec)
         * Done.  Left and right have the checksum.  Put it into
         * the output.
         */
-       op = (unsigned char *)out;
+       op = out;
        PUT_HALF_BLOCK(left, op);
        PUT_HALF_BLOCK(right, op);
 
index eeea4f8b55195656eec114f8bd6f04f328cb434a..6dbde1fcd49ed5463d4e019d059e5df9e8563cf7 100644 (file)
@@ -230,13 +230,13 @@ make_key_sched(key, schedule)
                /*
                 * Need a pointer for the keys and a temporary DES_INT32
                 */
-               register unsigned char *k;
+               const unsigned char *k;
                register unsigned DES_INT32 tmp;
 
                /*
                 * Fetch the key into something we can work with
                 */
-               k = (unsigned char *)key;
+               k = key;
 
                /*
                 * The first permutted choice gives us the 28 bits for C0 and
index 293c25e2276defb308180c247b75ff99b08ab29e..4408d8a9691438ba4382c8bdce26dcf2981eefb1 100644 (file)
@@ -78,7 +78,7 @@ mit_des_is_weak_key(key)
     const mit_des_cblock *weak_p = weak;
 
     for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
-       if (!memcmp((char *)weak_p++,(char *)key,sizeof(mit_des_cblock)))
+       if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
            return 1;
     }