use const for some des inputs and reduce unnecessary casts
authorKen Raeburn <raeburn@mit.edu>
Tue, 10 Apr 2001 07:40:02 +0000 (07:40 +0000)
committerKen Raeburn <raeburn@mit.edu>
Tue, 10 Apr 2001 07:40:02 +0000 (07:40 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13166 dc483132-0cff-0310-8789-dd5450dbe970

src/include/kerberosIV/ChangeLog
src/include/kerberosIV/des.h
src/lib/des425/ChangeLog
src/lib/des425/cksum.c
src/lib/des425/des.c
src/lib/des425/enc_dec.c
src/lib/des425/pcbc_encrypt.c
src/lib/des425/quad_cksum.c
src/lib/des425/str_to_key.c
src/lib/des425/t_pcbc.c
src/lib/des425/util.c

index aef698dbbd7e64d09229d473788ca930161fb7f2..b9bd0d7515d317d8432e88c1d41b9d637178de08 100644 (file)
@@ -1,5 +1,8 @@
 2001-04-10  Ken Raeburn  <raeburn@mit.edu>
 
+       * des.h (des_pcbc_encrypt, des_quad_cksum, des_cbc_cksum,
+       des_cbc_encrypt, des_ecb_encrypt): Use const for some input args.
+
        * krb.h (krb_get_admhst, krb_get_krbhst, krb_get_lrealm): Don't
        use "index" as argument name.
 
index 67eca8ee601eff29b311b6f3d4c436322e8725a8..529b33c8225e935e779e34b4c71198d7ad5ea59b 100644 (file)
@@ -135,25 +135,29 @@ KRB5_DLLIMP int KRB5_CALLCONV des_key_sched (C_Block, Key_schedule);
 
 KRB5_DLLIMP int KRB5_CALLCONV
 des_pcbc_encrypt (C_Block FAR *in, C_Block FAR *out, long length,
-                 Key_schedule schedule, C_Block FAR *ivec, int encrypt);
+                 const des_key_schedule schedule, C_Block FAR *ivec,
+                 int encrypt);
 
 KRB5_DLLIMP unsigned long KRB5_CALLCONV
-des_quad_cksum (unsigned char FAR *in, unsigned KRB4_32 FAR *out,
+des_quad_cksum (const unsigned char FAR *in, unsigned KRB4_32 FAR *out,
                long length, int out_count, C_Block FAR *seed);
 
-KRB5_DLLIMP int KRB5_CALLCONV des_string_to_key (char FAR *, C_Block);
+KRB5_DLLIMP int KRB5_CALLCONV des_string_to_key (const char FAR *, C_Block);
 
 /* new */
 #ifdef KRB5_GENERAL__
+/* Why are we using krb5 types as part of this API?  */
 KRB5_DLLIMP void KRB5_CALLCONV
-des_cbc_cksum(krb5_octet *, krb5_octet *, unsigned long,
-             des_key_schedule, krb5_octet *);
+des_cbc_cksum(const krb5_octet *, krb5_octet *, unsigned long,
+             const des_key_schedule, const krb5_octet *);
 int des_cbc_encrypt(krb5_octet *, krb5_octet *, unsigned long,
-                   des_key_schedule, krb5_octet *, int);
+                   const des_key_schedule, const krb5_octet *, int);
 krb5_error_code des_read_password(des_cblock *, char *, int);
 #endif
+/* The unsigned long pointers are indicative of the desired alignment;
+   the values there aren't really treated as long values.  */
 KRB5_DLLIMP int KRB5_CALLCONV des_ecb_encrypt(unsigned long *, unsigned long *,
-                                             des_key_schedule, int);
+                                             const des_key_schedule, int);
 void des_fixup_key_parity(des_cblock);
 int des_check_key_parity(des_cblock);
 KRB5_DLLIMP int KRB5_CALLCONV des_new_random_key(des_cblock);
index 412dc648433430991b1983c5316dc6b6fb2f7b6a..58722e848d528d5300ae1da98b9dc496a9acce1f 100644 (file)
@@ -1,5 +1,20 @@
 2001-04-10  Ken Raeburn  <raeburn@mit.edu>
 
+       * cksum.c (des_cbc_cksum): Arguments IN, KEY, and IV now const.
+       * des.c (des_ecb_encrypt): Change type of arg "schedule" to
+       const des_key_schedule and drop register decl.  Make local
+       variable "iv" const.
+       * enc_dec.c (des_cbc_encrypt): Arguments KEY and IV now const.
+       * pcbc_encrypt.c (des_pcbc_encrypt): Argument SCHEDULE now const.
+       Drop some unnecessary casts.
+       * quad_cksum.c (vaxtohl, vaxtohs): Cast to pointer to const.
+       (des_quad_cksum): Argument IN now points to const.
+       * str_to_key.c (des_string_to_key): String argument now const.
+       Delete local declaration of des_cbc_cksum.  Delete or fix some
+       casts.
+       * t_pcbc.c (main): Pass address of ivec to des_pcbc_encrypt.
+       * util.c (des_cblock_print_file): Delete unnecessary cast.
+
        * Makefile.in (STLIBOBJS, OBJS, SRCS): Delete references to
        k4_glue.c etc.
        (clean): Remove t_quad and t_pcbc object files and test programs.
index deff03c6569d30f4e0b0fe607a45a88d13982239..9758a054cbf738dedd809086502f177e98b8fd0a 100644 (file)
 
 void
 des_cbc_cksum(in,out,length,key,iv)
-    krb5_octet  *in;           /* >= length bytes of inputtext */
-    krb5_octet  *out;          /* >= length bytes of outputtext */
+    const krb5_octet  *in;             /* >= length bytes of inputtext */
+    krb5_octet  *out;                  /* >= length bytes of outputtext */
     register unsigned long length;     /* in bytes */
-    mit_des_key_schedule key;          /* precomputed key schedule */
-    krb5_octet  *iv;           /* 8 bytes of ivec */
+    const mit_des_key_schedule key;    /* precomputed key schedule */
+    const krb5_octet  *iv;             /* 8 bytes of ivec */
 {
        mit_des_cbc_cksum(in, out, length, key, iv);
 }
index 9dfdce3e3e837dd39040b8dcabe192e3f64100b3..6ba03730d34f7d2065ef7f92e049325f421e9831 100644 (file)
@@ -58,10 +58,10 @@ KRB5_DLLIMP int KRB5_CALLCONV
 des_ecb_encrypt(clear, cipher, schedule, encrypt)
     unsigned long *clear;
     unsigned long *cipher;
-    register mit_des_key_schedule schedule; /* r11 */
+    const mit_des_key_schedule schedule;
     int encrypt;               /* 0 ==> decrypt, else encrypt */
 {
-    static des_cblock iv;
+    const static des_cblock iv;
 
     return (mit_des_cbc_encrypt((const des_cblock *) clear,
                                (des_cblock *) cipher,
index f0e0daa50865dca00f832880c88d517f41d1dede..c46341392323453220410e1b17232f8a4d3af5f4 100644 (file)
 
 int
 des_cbc_encrypt(in,out,length,key,iv,encrypt)
-    krb5_octet   *in;          /* >= length bytes of input text */
+    krb5_octet   *in;  /* >= length bytes of input text */
     krb5_octet  *out;          /* >= length bytes of output text */
     register unsigned long length;     /* in bytes */
-    mit_des_key_schedule key;          /* precomputed key schedule */
-    krb5_octet *iv;            /* 8 bytes of ivec */
+    const mit_des_key_schedule key;            /* precomputed key schedule */
+    const krb5_octet *iv;              /* 8 bytes of ivec */
     int encrypt;               /* 0 ==> decrypt, else encrypt */
 {
        return (mit_des_cbc_encrypt((const des_cblock *) in,
index e47817061034e3763705bab7308310444c725e39..d150af51a674d1e0292463f88660200f5f7cf55e 100644 (file)
@@ -27,19 +27,20 @@ des_pcbc_encrypt(in, out, length, schedule, ivec, encrypt)
        des_cblock *in;
        des_cblock *out;
        long length;
-       des_key_schedule schedule;
+       const des_key_schedule schedule;
        des_cblock *ivec;
        int encrypt;
 {
        register unsigned DES_INT32 left, right;
        register unsigned DES_INT32 temp;
-       register unsigned DES_INT32 *kp;
-       register unsigned char *ip, *op;
+       const unsigned DES_INT32 *kp;
+       const unsigned char *ip;
+       unsigned char *op;
 
        /*
         * Copy the key pointer, just once
         */
-       kp = (unsigned DES_INT32 *)schedule;
+       kp = (const unsigned DES_INT32 *)schedule;
 
        /*
         * Deal with encryption and decryption separately.
@@ -57,7 +58,7 @@ des_pcbc_encrypt(in, out, length, schedule, 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);
 
@@ -65,8 +66,8 @@ des_pcbc_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 block of input.  If the length is
@@ -142,15 +143,15 @@ des_pcbc_encrypt(in, out, length, schedule, 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 cdf81c3f7951f8eb738af39718ba28ac16ee2962..213e6a6e28c2290a7dd25603ad6053cc8652741b 100644 (file)
 /* vax byte order is LSB first. This is not performance critical, and
    is far more readable this way. */
 #define four_bytes_vax_to_nets(x) ((((((x[3]<<8)|x[2])<<8)|x[1])<<8)|x[0])
-#define vaxtohl(x) four_bytes_vax_to_nets(((unsigned char *)(x)))
+#define vaxtohl(x) four_bytes_vax_to_nets(((const unsigned char *)(x)))
 #define two_bytes_vax_to_nets(x) ((x[1]<<8)|x[0])
-#define vaxtohs(x) two_bytes_vax_to_nets(((unsigned char *)(x)))
+#define vaxtohs(x) two_bytes_vax_to_nets(((const unsigned char *)(x)))
 
 /* Externals */
 extern char *errmsg();
@@ -129,7 +129,7 @@ extern int des_debug;
 
 KRB5_DLLIMP unsigned long KRB5_CALLCONV
 des_quad_cksum(in,out,length,out_count,c_seed)
-    unsigned char FAR *in;             /* input block */
+    const unsigned char FAR *in;       /* input block */
     unsigned DES_INT32 FAR *out;       /* optional longer output */
     long length;                       /* original length in bytes */
     int out_count;                     /* number of iterations */
@@ -147,14 +147,14 @@ des_quad_cksum(in,out,length,out_count,c_seed)
     register unsigned DES_INT32 z2;
     register unsigned DES_INT32 x;
     register unsigned DES_INT32 x2;
-    register unsigned char *p;
+    const unsigned char *p;
     register DES_INT32 len;
     register int i;
 
     /* use all 8 bytes of seed */
 
     z = vaxtohl(c_seed);
-    z2 = vaxtohl((char *)c_seed+4);
+    z2 = vaxtohl((const char *)c_seed+4);
     if (out == NULL)
        out_count = 1;          /* default */
 
@@ -173,7 +173,7 @@ des_quad_cksum(in,out,length,out_count,c_seed)
                len -= 2;
            }
            else {
-               x = (z + *(unsigned char *)p++);
+               x = (z + *(const unsigned char *)p++);
                len = 0;
            }
            x2 = z2;
index 4489471250101cdd92d02b88d300ba401be755d7..139b10272bd0d7161304991f0af10383910a7d49 100644 (file)
@@ -63,19 +63,18 @@ extern int mit_des_debug;
  */
 KRB5_DLLIMP int KRB5_CALLCONV
 des_string_to_key(str,key)
-    char *str;
+    const char *str;
     register mit_des_cblock key;
 {
-    register char *in_str;
+    const char *in_str;
     register unsigned temp;
     register int j;
-    register long i, length;
+    unsigned long i, length;
     unsigned char *k_p;
     int forward;
     register char *p_char;
     char k_char[64];
     mit_des_key_schedule key_sked;
-    extern void des_cbc_cksum();
 
     in_str = str;
     forward = 1;
@@ -88,7 +87,7 @@ des_string_to_key(str,key)
 #ifdef DEBUG
     if (mit_des_debug)
        fprintf(stdout,
-               "\n\ninput str length = %d  string = %s\nstring = 0x ",
+               "\n\ninput str length = %ld  string = %s\nstring = 0x ",
                length,str);
 #endif
 
@@ -129,10 +128,11 @@ des_string_to_key(str,key)
     des_fixup_key_parity(key);
 
     /* Now one-way encrypt it with the folded key */
-    (void) des_key_sched(key, *(Key_schedule *)&key_sked);
-    (void) des_cbc_cksum((des_cblock *)in_str,key,length,key_sked,key);
+    (void) des_key_sched(key, key_sked);
+    (void) des_cbc_cksum((const unsigned char *) in_str, key, length,
+                        key_sked, key);
     /* erase key_sked */
-    memset((char *)key_sked, 0,sizeof(key_sked));
+    memset(key_sked, 0,sizeof(key_sked));
 
     /* now fix up key parity again */
     des_fixup_key_parity(key);
index c6b63d44dca8604b2c6dbc864841f2c374280fb9..8bd6a08bc34871a634e5a467883e2003d70eec72 100644 (file)
@@ -96,7 +96,7 @@ main(argc,argv)
        des_key_sched (default_key, sked);
        /* This could lose on alignment... */
        des_pcbc_encrypt ((des_cblock *)&tests[i].text, out,
-                         strlen(tests[i].text) + 1, sked, ivec, 1);
+                         strlen(tests[i].text) + 1, sked, &ivec, 1);
        printf ("pcbc_encrypt(\"%s\") = {", tests[i].text);
        jmax = (strlen (tests[i].text) + 8) & ~7U;
        for (j = 0; j < jmax; j++) {
@@ -109,7 +109,7 @@ main(argc,argv)
        printf ("\n}\n");
 
        /* reverse it */
-       des_pcbc_encrypt (out, out2, jmax, sked, ivec, 0);
+       des_pcbc_encrypt (out, out2, jmax, sked, &ivec, 0);
        if (strcmp ((char *)out2, tests[i].text)) {
            printf ("decrypt failed\n");
            wrong = 1;
index 54545fcf0aa5f0373568195c7277a544146cefe0..2c5ef9216cf173ccb06c26354a0037f1f0893f21 100644 (file)
@@ -20,7 +20,7 @@ void des_cblock_print_file(x, fp)
     des_cblock *x;
     FILE *fp;
 {
-    unsigned char *y = (unsigned char *) x;
+    unsigned char *y = *x;
     register int i = 0;
     fprintf(fp," 0x { ");