summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-09-20 17:28:07 +0000
committerNick Mathewson <nickm@torproject.org>2007-09-20 17:28:07 +0000
commitf0634bb7ca54bf9d61ce376c821b41a21ccb4726 (patch)
treef1a26b1560a2bfdfc7a7a6bb84d6f6477953e24a
parent262d5ab0a8172ac0cd67adedd210179d59aa2932 (diff)
downloadtor-f0634bb7ca54bf9d61ce376c821b41a21ccb4726.tar.gz
tor-f0634bb7ca54bf9d61ce376c821b41a21ccb4726.zip
r14532@Kushana: nickm | 2007-09-20 13:25:38 -0400
Clean up some macros in aes.c svn:r11537
-rw-r--r--src/common/aes.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/common/aes.c b/src/common/aes.c
index 296947f646..8bb388e141 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -141,6 +141,7 @@ struct aes_cnt_cipher {
#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 @@ struct aes_cnt_cipher {
#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 @@ struct aes_cnt_cipher {
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 @@ aes_set_key(aes_cnt_cipher_t *cipher, const char *key, int key_bits)
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 @@ aes_free_cipher(aes_cnt_cipher_t *cipher)
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 @@ aes_set_counter(aes_cnt_cipher_t *cipher, u64 counter)
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);