From 5e77bd449e9d7050d59271db157e3fc8957e23e9 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Tue, 30 Sep 2014 19:47:35 -0400 Subject: [PATCH] Use OPENSSL_64_BIT in rc4.c. This avoids unnecessary differences between LP64 and LLP64. Also MSVC throws overflow warnings in the big-endian 64-bit codepath, so use the preprocessor. Change-Id: I74cef2d631d39f282177e043ed24bc6ecbbcb8fd Reviewed-on: https://boringssl-review.googlesource.com/1860 Reviewed-by: Adam Langley --- crypto/rc4/rc4.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/crypto/rc4/rc4.c b/crypto/rc4/rc4.c index 4fc8b6b4f..00b59c809 100644 --- a/crypto/rc4/rc4.c +++ b/crypto/rc4/rc4.c @@ -56,11 +56,17 @@ #include - #if defined(OPENSSL_NO_ASM) || \ (!defined(OPENSSL_X86_64) && !defined(OPENSSL_X86)) -#define RC4_CHUNK unsigned long +#if defined(OPENSSL_64_BIT) +#define RC4_CHUNK uint64_t +#elif defined(OPENSSL_32_BIT) +#define RC4_CHUNK uint32_t +#else +#error "Unknown word size" +#endif + #define RC4_INT uint32_t @@ -157,12 +163,12 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) { otp |= RC4_STEP << BESHFT(1); otp |= RC4_STEP << BESHFT(2); otp |= RC4_STEP << BESHFT(3); - if (sizeof(RC4_CHUNK) == 8) { - otp |= RC4_STEP << BESHFT(4); - otp |= RC4_STEP << BESHFT(5); - otp |= RC4_STEP << BESHFT(6); - otp |= RC4_STEP << BESHFT(7); - } +#if defined(OPENSSL_64_BIT) + otp |= RC4_STEP << BESHFT(4); + otp |= RC4_STEP << BESHFT(5); + otp |= RC4_STEP << BESHFT(6); + otp |= RC4_STEP << BESHFT(7); +#endif *(RC4_CHUNK *)out = otp ^ ichunk; in += sizeof(RC4_CHUNK); out += sizeof(RC4_CHUNK); @@ -206,12 +212,12 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) { otp |= RC4_STEP << 8; otp |= RC4_STEP << 16; otp |= RC4_STEP << 24; - if (sizeof(RC4_CHUNK) == 8) { - otp |= RC4_STEP << LESHFT(4); - otp |= RC4_STEP << LESHFT(5); - otp |= RC4_STEP << LESHFT(6); - otp |= RC4_STEP << LESHFT(7); - } +#if defined(OPENSSL_64_BIT) + otp |= RC4_STEP << LESHFT(4); + otp |= RC4_STEP << LESHFT(5); + otp |= RC4_STEP << LESHFT(6); + otp |= RC4_STEP << LESHFT(7); +#endif *(RC4_CHUNK *)out = otp ^ ichunk; in += sizeof(RC4_CHUNK); out += sizeof(RC4_CHUNK);