Allow compile-time specification that small code space is desired
authorKen Raeburn <raeburn@mit.edu>
Wed, 13 Apr 2005 20:38:36 +0000 (20:38 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 13 Apr 2005 20:38:36 +0000 (20:38 +0000)
* 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

src/lib/crypto/des/ChangeLog
src/lib/crypto/des/d3_cbc.c
src/lib/crypto/des/f_cbc.c
src/lib/crypto/des/f_cksum.c
src/lib/crypto/des/f_tables.h

index 04306190908217226d327ed587a541b1870eabec..48a7cc36c622fe3637efaa7881462469404ecfaa 100644 (file)
@@ -1,3 +1,22 @@
+2005-04-13  Ken Raeburn  <raeburn@mit.edu>
+
+       * 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  <raeburn@mit.edu>
 
        * Makefile.in (verify, t_afss2k): Link test programs against
index 3ff1c1186ac5a9d60769c9b9b5cd5a6a97d85d5d..37c32c76f937787317f61cb3a6de43fb08c5a5d4 100644 (file)
@@ -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;
index 3dfb99724af8757a49f5da9ab5a1b73239644f01..24996e489617a7feda0703952ae6a5589e91da02 100644 (file)
@@ -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
index 0e9ebf3f4c0ab9a38931d819a79ee84e7891342f..1b9e9a02b51c11fbad883874957ff39921fa8ac0 100644 (file)
@@ -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;
index 5d49fc6d96dc8a04c17cb34750249593a5bf5756..3ea3461594036e3c51764af532a5d81077c5c9a8 100644 (file)
@@ -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.