From: Ken Raeburn Date: Thu, 10 Oct 2002 02:58:23 +0000 (+0000) Subject: * string2key.c (mit_des_string_to_key_int): If PRINT_TEST_VECTORS is defined, X-Git-Tag: krb5-1.3-alpha1~332 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=66295b02012d9caf0c8ce9563d76ca1592c7608f;p=krb5.git * string2key.c (mit_des_string_to_key_int): If PRINT_TEST_VECTORS is defined, print some of the intermediate results. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14919 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index d1246b641..dd03be7e0 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,3 +1,8 @@ +2002-10-09 Ken Raeburn + + * string2key.c (mit_des_string_to_key_int): If PRINT_TEST_VECTORS + is defined, print some of the intermediate results. + 2002-09-26 Tom Yu * afsstring2key.c (krb5_afs_crypt): Leak this function out as as diff --git a/src/lib/crypto/des/string2key.c b/src/lib/crypto/des/string2key.c index 74268a18b..6a8eb1906 100644 --- a/src/lib/crypto/des/string2key.c +++ b/src/lib/crypto/des/string2key.c @@ -69,6 +69,8 @@ returns: errors */ +/*#define PRINT_TEST_VECTORS*/ + krb5_error_code mit_des_string_to_key_int (keyblock, data, salt) krb5_keyblock * keyblock; @@ -88,6 +90,11 @@ mit_des_string_to_key_int (keyblock, data, salt) char k_char[64]; mit_des_key_schedule key_sked; +#ifdef PRINT_TEST_VECTORS + unsigned char tmp_array[56]; + unsigned char *t_char; +#endif + #ifndef min #define min(A, B) ((A) < (B) ? (A): (B)) #endif @@ -124,10 +131,13 @@ mit_des_string_to_key_int (keyblock, data, salt) /* convert to des key */ forward = 1; - p_char = k_char; /* init key array for bits */ + p_char = k_char; memset(k_char,0,sizeof(k_char)); +#ifdef PRINT_TEST_VECTORS + t_char = tmp_array; +#endif #if 0 if (mit_des_debug) @@ -148,16 +158,45 @@ mit_des_string_to_key_int (keyblock, data, salt) #endif /* loop through bits within byte, ignore parity */ for (j = 0; j <= 6; j++) { - if (forward) - *p_char++ ^= (int) temp & 01; - else - *--p_char ^= (int) temp & 01; + unsigned int x = temp & 1; + if (forward) { + *p_char++ ^= x; +#ifdef PRINT_TEST_VECTORS + *t_char++ = x; +#endif + } else { + *--p_char ^= x; +#ifdef PRINT_TEST_VECTORS + *--t_char = x; +#endif + } temp = temp >> 1; } /* check and flip direction */ - if ((i%8) == 0) + if ((i%8) == 0) { +#ifdef PRINT_TEST_VECTORS + printf("%-20s ", + forward ? "forward block:" : "reversed block:"); + for (j = 0; j <= 7; j++) { + int k, num = 0; + for (k = 0; k <= 6; k++) + num |= tmp_array[j * 7 + k] << k; + printf(" %02x", num); + } + printf("\n"); + + printf("%-20s ", "xor result:"); + for (j = 0; j <= 7; j++) { + int k, num = 0; + for (k = 0; k <= 6; k++) + num |= k_char[j * 7 + k] << k; + printf(" %02x", num); + } + printf("\n"); +#endif forward = !forward; + } } /* now stuff into the key mit_des_cblock, and force odd parity */ @@ -171,11 +210,30 @@ mit_des_string_to_key_int (keyblock, data, salt) *k_p++ = (unsigned char) temp; } +#ifdef PRINT_TEST_VECTORS + printf("%-20s ", "after fanfolding:"); + for (i = 0; i <= 7; i++) + printf(" %02x", i[(unsigned char *)key]); + printf("\n"); + + printf("%-20s ", "after shifting:"); + for (i = 0; i <= 7; i++) + printf(" %02x", i[(unsigned char *)key]); + printf("\n"); +#endif + /* fix key parity */ mit_des_fixup_key_parity(key); if (mit_des_is_weak_key(key)) ((krb5_octet *)key)[7] ^= 0xf0; +#ifdef PRINT_TEST_VECTORS + printf("after fixing parity and weak keys: {"); + for (i = 0; i <= 7; i++) + printf(" %02x", i[(unsigned char *)key]); + printf(" }\n"); +#endif + /* Now one-way encrypt it with the folded key */ (void) mit_des_key_sched(key, key_sked); (void) mit_des_cbc_cksum(copystr, key, length, key_sked, key);