From: Ken Raeburn Date: Wed, 13 Apr 2005 20:38:36 +0000 (+0000) Subject: Allow compile-time specification that small code space is desired X-Git-Tag: ms-bug-test-20060525~285 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=681fa0f938f9a1b6639a72c76c45ea09e8fcd17e;p=krb5.git Allow compile-time specification that small code space is desired * d3_cbc.c (krb5int_des3_cbc_encrypt, krb5int_des3_cbc_decrypt): Don't declare left and right variables as registers. * f_cksum.c (mit_des_cbc_cksum): Likewise. * f_cbc.c (krb5int_des_cbc_encrypt, krb5int_des_cbc_decrypt): Likewise. (krb5int_des_cbc_encrypt): For full blocks, use GET_HALF_BLOCK to read and then xor, instead of processing each byte individually. (krb5int_des_do_encrypt_2, krb5int_des_do_decrypt_2) [CONFIG_SMALL]: New functions, wrapping large macros with the DES inner loops. * f_tables.h (DES_DO_ENCRYPT_1, DES_DO_DECRYPT_1): Renamed from non-_1 names. (krb5int_des_do_encrypt_2, krb5int_des_do_decrypt_2): Declare if CONFIG_SMALL is defined. (DES_DO_ENCRYPT, DES_DO_DECRYPT): Expand to _1 macros or _2 function calls depending on whether CONFIG_SMALL is defined. With CONFIG_SMALL defined, on x86/gcc/glibc, this drops about 5K (25%) of the code/table space. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17183 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index 043061909..48a7cc36c 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,3 +1,22 @@ +2005-04-13 Ken Raeburn + + * d3_cbc.c (krb5int_des3_cbc_encrypt, krb5int_des3_cbc_decrypt): + Don't declare left and right variables as registers. + * f_cksum.c (mit_des_cbc_cksum): Likewise. + * f_cbc.c (krb5int_des_cbc_encrypt, krb5int_des_cbc_decrypt): + Likewise. + (krb5int_des_cbc_encrypt): For full blocks, use GET_HALF_BLOCK to + read and then xor, instead of processing each byte individually. + (krb5int_des_do_encrypt_2, krb5int_des_do_decrypt_2) + [CONFIG_SMALL]: New functions, wrapping large macros with the DES + inner loops. + * f_tables.h (DES_DO_ENCRYPT_1, DES_DO_DECRYPT_1): Renamed from + non-_1 names. + (krb5int_des_do_encrypt_2, krb5int_des_do_decrypt_2): Declare if + CONFIG_SMALL is defined. + (DES_DO_ENCRYPT, DES_DO_DECRYPT): Expand to _1 macros or _2 + function calls depending on whether CONFIG_SMALL is defined. + 2004-05-13 Ken Raeburn * Makefile.in (verify, t_afss2k): Link test programs against diff --git a/src/lib/crypto/des/d3_cbc.c b/src/lib/crypto/des/d3_cbc.c index 3ff1c1186..37c32c76f 100644 --- a/src/lib/crypto/des/d3_cbc.c +++ b/src/lib/crypto/des/d3_cbc.c @@ -51,7 +51,7 @@ krb5int_des3_cbc_encrypt(const mit_des_cblock *in, const mit_des_key_schedule ks3, const mit_des_cblock ivec) { - register unsigned DES_INT32 left, right; + unsigned DES_INT32 left, right; const unsigned DES_INT32 *kp1, *kp2, *kp3; const unsigned char *ip; unsigned char *op; @@ -137,7 +137,7 @@ krb5int_des3_cbc_decrypt(const mit_des_cblock *in, const mit_des_key_schedule ks3, const mit_des_cblock ivec) { - register unsigned DES_INT32 left, right; + unsigned DES_INT32 left, right; const unsigned DES_INT32 *kp1, *kp2, *kp3; const unsigned char *ip; unsigned char *op; diff --git a/src/lib/crypto/des/f_cbc.c b/src/lib/crypto/des/f_cbc.c index 3dfb99724..24996e489 100644 --- a/src/lib/crypto/des/f_cbc.c +++ b/src/lib/crypto/des/f_cbc.c @@ -61,7 +61,7 @@ krb5int_des_cbc_encrypt(const mit_des_cblock *in, const mit_des_key_schedule schedule, const mit_des_cblock ivec) { - register unsigned DES_INT32 left, right; + unsigned DES_INT32 left, right; const unsigned DES_INT32 *kp; const unsigned char *ip; unsigned char *op; @@ -92,14 +92,11 @@ krb5int_des_cbc_encrypt(const mit_des_cblock *in, * forward. Otherwise we have to fart around. */ if (length >= 8) { - 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; + unsigned DES_INT32 temp; + GET_HALF_BLOCK(temp, ip); + left ^= temp; + GET_HALF_BLOCK(temp, ip); + right ^= temp; length -= 8; } else { /* @@ -148,7 +145,7 @@ krb5int_des_cbc_decrypt(const mit_des_cblock *in, const mit_des_key_schedule schedule, const mit_des_cblock ivec) { - register unsigned DES_INT32 left, right; + unsigned DES_INT32 left, right; const unsigned DES_INT32 *kp; const unsigned char *ip; unsigned char *op; @@ -240,3 +237,19 @@ krb5int_des_cbc_decrypt(const mit_des_cblock *in, } } } + +#ifdef CONFIG_SMALL +void krb5int_des_do_encrypt_2 (unsigned DES_INT32 *left, + unsigned DES_INT32 *right, + const unsigned DES_INT32 *kp) +{ + DES_DO_ENCRYPT_1 (*left, *right, kp); +} + +void krb5int_des_do_decrypt_2 (unsigned DES_INT32 *left, + unsigned DES_INT32 *right, + const unsigned DES_INT32 *kp) +{ + DES_DO_DECRYPT_1 (*left, *right, kp); +} +#endif diff --git a/src/lib/crypto/des/f_cksum.c b/src/lib/crypto/des/f_cksum.c index 0e9ebf3f4..1b9e9a02b 100644 --- a/src/lib/crypto/des/f_cksum.c +++ b/src/lib/crypto/des/f_cksum.c @@ -33,7 +33,7 @@ mit_des_cbc_cksum(const krb5_octet *in, krb5_octet *out, unsigned long length, const mit_des_key_schedule schedule, const krb5_octet *ivec) { - register unsigned DES_INT32 left, right; + unsigned DES_INT32 left, right; const unsigned DES_INT32 *kp; const unsigned char *ip; unsigned char *op; diff --git a/src/lib/crypto/des/f_tables.h b/src/lib/crypto/des/f_tables.h index 5d49fc6d9..3ea346159 100644 --- a/src/lib/crypto/des/f_tables.h +++ b/src/lib/crypto/des/f_tables.h @@ -200,7 +200,7 @@ extern const unsigned DES_INT32 des_SP_table[8][64]; * 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, kp) \ +#define DES_DO_ENCRYPT_1(left, right, kp) \ do { \ register int i; \ register unsigned DES_INT32 temp1; \ @@ -218,7 +218,7 @@ extern const unsigned DES_INT32 des_SP_table[8][64]; DEB ((" after FP %8lX %8lX \n", left, right)); \ } while (0) -#define DES_DO_DECRYPT(left, right, kp) \ +#define DES_DO_DECRYPT_1(left, right, kp) \ do { \ register int i; \ register unsigned DES_INT32 temp2; \ @@ -231,6 +231,20 @@ extern const unsigned DES_INT32 des_SP_table[8][64]; DES_FINAL_PERM((left), (right), (temp2)); \ } while (0) +#ifdef CONFIG_SMALL +extern void krb5int_des_do_encrypt_2(unsigned DES_INT32 *l, + unsigned DES_INT32 *r, + const unsigned DES_INT32 *k); +extern void krb5int_des_do_decrypt_2(unsigned DES_INT32 *l, + unsigned DES_INT32 *r, + const unsigned DES_INT32 *k); +#define DES_DO_ENCRYPT(L,R,K) krb5int_des_do_encrypt_2(&(L), &(R), (K)) +#define DES_DO_DECRYPT(L,R,K) krb5int_des_do_decrypt_2(&(L), &(R), (K)) +#else +#define DES_DO_ENCRYPT DES_DO_ENCRYPT_1 +#define DES_DO_DECRYPT DES_DO_DECRYPT_1 +#endif + /* * These are handy dandy utility thingies for straightening out bytes. * Included here because they're used a couple of places.