From: John Gilmore Date: Tue, 28 Mar 1995 23:42:20 +0000 (+0000) Subject: Bring in portability fixes from Cygnus K4 release X-Git-Tag: krb5-1.0-beta5~432 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=40192fcec11733256786840895c56d46d65cd268;p=krb5.git Bring in portability fixes from Cygnus K4 release * f_cbc.c, f_cksum.c, f_pcbc.c: Replace individual casts with simpler solution. * f_tables.h: Insert debugging code, and circumvention for MPW compiler bug. * key_sched.c: Remove ancient (microvax??!) comments, and dup prototype. * verify.c: Small hack for MS-Windows scrolling. Fix spelling. "register x" -> "register int x". git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5288 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index 0a4fcd6d6..4d99e7de5 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,3 +1,16 @@ +Tue Mar 28 15:09:43 1995 John Gilmore (gnu at toad.com) + + Bring in portability fixes from Cygnus K4 release. + + * f_cbc.c, f_cksum.c, f_pcbc.c: Replace individual casts with + simpler solution. + * f_tables.h: Insert debugging code, and circumvention for MPW + compiler bug. + * key_sched.c: Remove ancient (microvax??!) comments, and dup + prototype. + * verify.c: Small hack for MS-Windows scrolling. Fix spelling. + "register x" -> "register int x". + Thu Mar 16 21:16:24 1995 John Gilmore (gnu at toad.com) * Makefile.in (LDFLAGS): Remove, conflicts with pre.in. diff --git a/src/lib/crypto/des/f_cbc.c b/src/lib/crypto/des/f_cbc.c index b7e4d0231..8b93174db 100644 --- a/src/lib/crypto/des/f_cbc.c +++ b/src/lib/crypto/des/f_cbc.c @@ -80,14 +80,14 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt) * forward. Otherwise we have to fart around. */ if (length >= 8) { - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 24; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 16; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 8; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)); - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 24; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 16; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 8; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)); + left ^= ((*ip++) & FF_UINT32) << 24; + left ^= ((*ip++) & FF_UINT32) << 16; + left ^= ((*ip++) & FF_UINT32) << 8; + left ^= (*ip++) & FF_UINT32; + right ^= ((*ip++) & FF_UINT32) << 24; + right ^= ((*ip++) & FF_UINT32) << 16; + right ^= ((*ip++) & FF_UINT32) << 8; + right ^= (*ip++) & FF_UINT32; length -= 8; } else { /* @@ -98,19 +98,19 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt) ip += (int) length; switch(length) { case 7: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + right ^= (*(--ip) & FF_UINT32) << 8; case 6: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + right ^= (*(--ip) & FF_UINT32) << 16; case 5: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + right ^= (*(--ip) & FF_UINT32) << 24; case 4: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)); + left ^= *(--ip) & FF_UINT32; case 3: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + left ^= (*(--ip) & FF_UINT32) << 8; case 2: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + left ^= (*(--ip) & FF_UINT32) << 16; case 1: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + left ^= (*(--ip) & FF_UINT32) << 24; break; } length = 0; diff --git a/src/lib/crypto/des/f_cksum.c b/src/lib/crypto/des/f_cksum.c index 2514a0f9e..05c94c537 100644 --- a/src/lib/crypto/des/f_cksum.c +++ b/src/lib/crypto/des/f_cksum.c @@ -63,14 +63,14 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec) * forward. Otherwise we have to fart around. */ if (len >= 8) { - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 24; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 16; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 8; - left ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)); - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 24; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 16; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)) << 8; - right ^= ((unsigned KRB_INT32) ((*ip++) & 0xff)); + left ^= ((*ip++) & FF_UINT32) << 24; + left ^= ((*ip++) & FF_UINT32) << 16; + left ^= ((*ip++) & FF_UINT32) << 8; + left ^= (*ip++) & FF_UINT32; + right ^= ((*ip++) & FF_UINT32) << 24; + right ^= ((*ip++) & FF_UINT32) << 16; + right ^= ((*ip++) & FF_UINT32) << 8; + right ^= (*ip++) & FF_UINT32; len -= 8; } else { /* @@ -81,19 +81,19 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec) ip += (int) len; switch(len) { case 7: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + right ^= (*(--ip) & FF_UINT32) << 8; case 6: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + right ^= (*(--ip) & FF_UINT32) << 16; case 5: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + right ^= (*(--ip) & FF_UINT32) << 24; case 4: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)); + left ^= *(--ip) & FF_UINT32; case 3: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + left ^= (*(--ip) & FF_UINT32) << 8; case 2: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + left ^= (*(--ip) & FF_UINT32) << 16; case 1: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + left ^= (*(--ip) & FF_UINT32) << 24; break; } len = 0; diff --git a/src/lib/crypto/des/f_pcbc.c b/src/lib/crypto/des/f_pcbc.c index d547da7da..efc2ce213 100644 --- a/src/lib/crypto/des/f_pcbc.c +++ b/src/lib/crypto/des/f_pcbc.c @@ -79,21 +79,21 @@ mit_des_pcbc_encrypt(in, out, length, schedule, ivec, encrypt) ip += (int) length; switch(length) { case 8: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)); + right ^= *(--ip) & FF_UINT32; case 7: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + right ^= (*(--ip) & FF_UINT32) << 8; case 6: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + right ^= (*(--ip) & FF_UINT32) << 16; case 5: - right ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + right ^= (*(--ip) & FF_UINT32) << 24; case 4: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)); + left ^= *(--ip) & FF_UINT32; case 3: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 8; + left ^= (*(--ip) & FF_UINT32) << 8; case 2: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 16; + left ^= (*(--ip) & FF_UINT32) << 16; case 1: - left ^= ((unsigned KRB_INT32) (*(--ip) & 0xff)) << 24; + left ^= (*(--ip) & FF_UINT32) << 24; break; } length = 0; diff --git a/src/lib/crypto/des/f_tables.h b/src/lib/crypto/des/f_tables.h index 29e186056..92ee871af 100644 --- a/src/lib/crypto/des/f_tables.h +++ b/src/lib/crypto/des/f_tables.h @@ -35,6 +35,12 @@ extern const unsigned KRB_INT32 des_SP_table[8][64]; #define FP des_FP_table #define SP des_SP_table +#ifdef DEBUG +#define DEB(foofraw) printf foofraw +#else +#define DEB(foofraw) /* nothing */ +#endif + /* * Code to do a DES round using the tables. Note that the E expansion * is easy to compute algorithmically, especially if done out-of-order. @@ -115,11 +121,16 @@ extern const unsigned KRB_INT32 des_SP_table[8][64]; * * The follow macros compute the set of bits used to index the * table for produce the left and right permuted result. + * + * The inserted cast to unsigned KRB_INT32 circumvents a bug in + * the Macintosh MPW 3.2 C compiler which loses the unsignedness and + * propagates the high-order bit in the shift. */ #define DES_IP_LEFT_BITS(left, right) \ ((((left) & 0x55555555) << 1) | ((right) & 0x55555555)) #define DES_IP_RIGHT_BITS(left, right) \ - (((left) & 0xaaaaaaaa) | (((right) & 0xaaaaaaaa) >> 1)) + (((left) & 0xaaaaaaaa) | \ + ( ( (unsigned KRB_INT32) ((right) & 0xaaaaaaaa) ) >> 1)) /* * The following macro does an in-place initial permutation given @@ -141,16 +152,20 @@ extern const unsigned KRB_INT32 des_SP_table[8][64]; | (IP[((temp) >> 8) & 0xff] << 2) \ | (IP[(temp) & 0xff] << 3) - /* * Now the final permutation stuff. The same comments apply to * this as to the initial permutation, except that we use different * bits and shifts. + * + * The inserted cast to unsigned KRB_INT32 circumvents a bug in + * the Macintosh MPW 3.2 C compiler which loses the unsignedness and + * propagates the high-order bit in the shift. */ #define DES_FP_LEFT_BITS(left, right) \ ((((left) & 0x0f0f0f0f) << 4) | ((right) & 0x0f0f0f0f)) #define DES_FP_RIGHT_BITS(left, right) \ - (((left) & 0xf0f0f0f0) | (((right) & 0xf0f0f0f0) >> 4)) + (((left) & 0xf0f0f0f0) | \ + ( ( (unsigned KRB_INT32) ((right) & 0xf0f0f0f0) ) >> 4)) /* @@ -185,17 +200,27 @@ extern const unsigned KRB_INT32 des_SP_table[8][64]; * * You can probably do better than these by rewriting for particular * situations. These aren't bad, though. + * + * The DEB macros enable debugging when this code breaks (typically + * when a buggy compiler breaks it), by printing the intermediate values + * at each stage of the encryption, so that by comparing the output to + * a known good machine, the location of the first error can be found. */ #define DES_DO_ENCRYPT(left, right, temp, kp) \ do { \ register int i; \ + DEB (("do_encrypt %8lX %8lX \n", left, right)); \ DES_INITIAL_PERM((left), (right), (temp)); \ + DEB ((" after IP %8lX %8lX\n", left, right)); \ for (i = 0; i < 8; i++) { \ DES_SP_ENCRYPT_ROUND((left), (right), (temp), (kp)); \ + DEB ((" round %2d %8lX %8lX \n", i*2, left, right)); \ DES_SP_ENCRYPT_ROUND((right), (left), (temp), (kp)); \ + DEB ((" round %2d %8lX %8lX \n", 1+i*2, left, right)); \ } \ DES_FINAL_PERM((left), (right), (temp)); \ (kp) -= (2 * 16); \ + DEB ((" after FP %8lX %8lX \n", left, right)); \ } while (0) #define DES_DO_DECRYPT(left, right, temp, kp) \ @@ -223,7 +248,11 @@ extern const unsigned KRB_INT32 des_SP_table[8][64]; #define PUT_HALF_BLOCK(lr, op) \ *(op)++ = (unsigned char) (((lr) >> 24) & 0xff); \ *(op)++ = (unsigned char) (((lr) >> 16) & 0xff); \ - *(op)++ = (unsigned char) (((lr) >> 8) & 0xff); \ - *(op)++ = (unsigned char) ((lr) & 0xff) + *(op)++ = (unsigned char) (((lr) >> 8) & 0xff); \ + *(op)++ = (unsigned char) ( (lr) & 0xff) + +/* Shorthand that we'll need in several places, for creating values that + really can hold 32 bits regardless of the prevailing int size. */ +#define FF_UINT32 ((unsigned KRB_INT32) 0xFF) #endif /* __DES_TABLES_H__ */ diff --git a/src/lib/crypto/des/key_sched.c b/src/lib/crypto/des/key_sched.c index 19ddbb78c..58e5d6d0d 100644 --- a/src/lib/crypto/des/key_sched.c +++ b/src/lib/crypto/des/key_sched.c @@ -32,24 +32,15 @@ * Watch out for the subscripts -- most effectively start at 1 instead * of at zero. Maybe some bugs in that area. * - * DON'T change the data types for arrays and such, or it will either - * break or run slower. This was optimized for Uvax2. - * * In case the user wants to cache the computed key schedule, it is * passed as an arg. Also implies that caller has explicit control * over zeroing both the key schedule and the key. * - * All registers labeled imply Vax using the Ultrix or 4.2bsd compiler. - * * Originally written 6/85 by Steve Miller, MIT Project Athena. */ #include "k5-int.h" #include "des_int.h" -#include - -int INTERFACE -make_key_sched PROTOTYPE((mit_des_cblock, mit_des_key_schedule)); int INTERFACE mit_des_key_sched(k,schedule) @@ -67,4 +58,3 @@ mit_des_key_sched(k,schedule) /* if key was good, return 0 */ return 0; } - diff --git a/src/lib/crypto/des/verify.c b/src/lib/crypto/des/verify.c index 6fe6214ef..376dff6b1 100644 --- a/src/lib/crypto/des/verify.c +++ b/src/lib/crypto/des/verify.c @@ -110,6 +110,10 @@ main(argc,argv) void do_encrypt(); void do_decrypt(); +#ifdef WINDOWS + /* Set screen window buffer to infinite size -- MS default is tiny. */ + _wsetscreenbuf (fileno (stdout), _WINBUFINF); +#endif progname=argv[0]; /* salt away invoking program */ while (--argc > 0 && (*++argv)[0] == '-') @@ -236,7 +240,7 @@ main(argc,argv) exit(-1); } else - printf("verify: ECB encription is correct\n\n"); + printf("verify: ECB encryption is correct\n\n"); } /* ECB mode */ @@ -264,7 +268,7 @@ main(argc,argv) exit(-1); } else - printf("verify: ECB encription is correct\n\n"); + printf("verify: ECB encryption is correct\n\n"); } /* CBC mode */ @@ -310,7 +314,7 @@ main(argc,argv) exit(-1); } else - printf("verify: CBC encription is correct\n\n"); + printf("verify: CBC encryption is correct\n\n"); printf("EXAMPLE CBC checksum"); printf("\tkey = 0123456789abcdef\tiv = 1234567890abcdef\n"); @@ -342,7 +346,7 @@ void flip(array) char *array; { - register old,new,i,j; + register int old,new,i,j; /* flips the bit order within each byte from 0 lsb to 0 msb */ for (i = 0; i<=7; i++) { old = *array; @@ -415,4 +419,3 @@ mit_des_is_weak_key(key) { return 0; /* fake it out for testing */ } -