+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.
* 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 {
/*
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;
* 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 {
/*
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;
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;
#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.
*
* 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
| (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))
/*
*
* 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) \
#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__ */
* 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 <stdio.h>
-
-int INTERFACE
-make_key_sched PROTOTYPE((mit_des_cblock, mit_des_key_schedule));
int INTERFACE
mit_des_key_sched(k,schedule)
/* if key was good, return 0 */
return 0;
}
-
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] == '-')
exit(-1);
}
else
- printf("verify: ECB encription is correct\n\n");
+ printf("verify: ECB encryption is correct\n\n");
}
/* ECB mode */
exit(-1);
}
else
- printf("verify: ECB encription is correct\n\n");
+ printf("verify: ECB encryption is correct\n\n");
}
/* CBC mode */
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");
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;
{
return 0; /* fake it out for testing */
}
-