[or-cvs] r11537: Clean up some macros in aes.c (in tor/trunk: . src/common)

nickm at seul.org nickm at seul.org
Thu Sep 20 17:28:08 UTC 2007


Author: nickm
Date: 2007-09-20 13:28:07 -0400 (Thu, 20 Sep 2007)
New Revision: 11537

Modified:
   tor/trunk/
   tor/trunk/src/common/aes.c
Log:
 r14532 at Kushana:  nickm | 2007-09-20 13:25:38 -0400
 Clean up some macros in aes.c



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14532] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/src/common/aes.c
===================================================================
--- tor/trunk/src/common/aes.c	2007-09-20 17:07:45 UTC (rev 11536)
+++ tor/trunk/src/common/aes.c	2007-09-20 17:28:07 UTC (rev 11537)
@@ -141,6 +141,7 @@
 #endif
 
 #if !defined(WORDS_BIGENDIAN) || defined(USE_RIJNDAEL_COUNTER_OPTIMIZATION)
+#define USING_COUNTER_VARS
   /** These four values, together, implement a 128-bit counter, with
    * counter0 as the low-order word and counter3 as the high-order word. */
   u32 counter3;
@@ -150,6 +151,7 @@
 #endif
 
 #ifndef USE_RIJNDAEL_COUNTER_OPTIMIZATION
+#define USING_COUNTER_BUFS
   union {
     /** The counter, in big-endian order, as bytes. */
     u8 buf[16];
@@ -165,7 +167,7 @@
   u8 pos;
 };
 
-#if defined(WORDS_BIGENDIAN) && !defined(USE_RIJNDAEL_COUNTER_OPTIMIZIZATION)
+#if !defined(USING_COUNTER_VARS)
 #define COUNTER(c, n) ((c)->ctr_buf.buf32[3-(n)])
 #else
 #define COUNTER(c, n) ((c)->counter ## n)
@@ -237,11 +239,13 @@
   cipher->nr = rijndaelKeySetupEnc(cipher->rk, (const unsigned char*)key,
                                    key_bits);
 #endif
-  COUNTER(cipher, 0) = 0;
-  COUNTER(cipher, 1) = 0;
-  COUNTER(cipher, 2) = 0;
-  COUNTER(cipher, 3) = 0;
-#ifndef USE_RIJNDAEL_COUNTER_OPTIMIZATION
+#ifdef USING_COUNTER_VARS
+  cipher->counter0 = 0;
+  cipher->counter1 = 0;
+  cipher->counter2 = 0;
+  cipher->counter3 = 0;
+#endif
+#ifdef USING_COUNTER_BUFS
   memset(cipher->ctr_buf.buf, 0, sizeof(cipher->ctr_buf.buf));
 #endif
 
@@ -262,12 +266,12 @@
   tor_free(cipher);
 }
 
-#if defined(USE_RIJNDAEL_COUNTER_OPTIMIZATION) || defined(WORDS_BIGENDIAN)
-#define UPDATE_CTR_BUF(c, n)
-#else
+#if defined(USING_COUNTER_VARS) && defined(USING_COUNTER_BUFS)
 #define UPDATE_CTR_BUF(c, n) STMT_BEGIN                 \
   (c)->ctr_buf.buf32[3-(n)] = htonl((c)->counter ## n); \
   STMT_END
+#else
+#define UPDATE_CTR_BUF(c, n)
 #endif
 
 /** Encrypt <b>len</b> bytes from <b>input</b>, storing the result in
@@ -334,10 +338,12 @@
 void
 aes_set_iv(aes_cnt_cipher_t *cipher, const char *iv)
 {
+#ifdef USING_COUNTER_VARS
   cipher->counter3 = ntohl(get_uint32(iv));
   cipher->counter2 = ntohl(get_uint32(iv+4));
   cipher->counter1 = ntohl(get_uint32(iv+8));
   cipher->counter0 = ntohl(get_uint32(iv+12));
+#endif
   cipher->pos = 0;
 #ifndef USE_RIJNDAEL_COUNTER_OPTIMIZATION
   memcpy(cipher->ctr_buf.buf, iv, 16);



More information about the tor-commits mailing list