diff options
author | Adam Langley <agl@chromium.org> | 2014-08-27 00:38:19 +0400 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2014-08-27 02:07:14 +0400 |
commit | 98ad22ec7ae21bdf5d5509049504b3632bfdbf93 (patch) | |
tree | 1453c2890352be2f312b2880ca1917ed4545806f /crypto/modes | |
parent | 58f90951eb8d4393925d3155a69be49236816f82 (diff) |
Fix "integer constant is too large for 'long' type" errors.
(Based on Piotr Sikora's change:
https://boringssl-review.googlesource.com/#/c/1361)
Change-Id: I7b62b81f4e4ef3064eee1b39334dc2e50d17f163
Reviewed-on: https://boringssl-review.googlesource.com/1641
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/modes')
-rw-r--r-- | crypto/modes/gcm.c | 37 | ||||
-rw-r--r-- | crypto/modes/internal.h | 9 |
2 files changed, 21 insertions, 25 deletions
diff --git a/crypto/modes/gcm.c b/crypto/modes/gcm.c index 065c4578..96139a87 100644 --- a/crypto/modes/gcm.c +++ b/crypto/modes/gcm.c @@ -54,6 +54,7 @@ #include <openssl/cpu.h> #include "internal.h" +#include "../internal.h" #if !defined(OPENSSL_NO_ASM) && \ @@ -70,17 +71,17 @@ #endif #define PACK(s) ((size_t)(s) << (sizeof(size_t) * 8 - 16)) -#define REDUCE1BIT(V) \ - do { \ - if (sizeof(size_t) == 8) { \ - uint64_t T = U64(0xe100000000000000) & (0 - (V.lo & 1)); \ - V.lo = (V.hi << 63) | (V.lo >> 1); \ - V.hi = (V.hi >> 1) ^ T; \ - } else { \ - uint32_t T = 0xe1000000U & (0 - (uint32_t)(V.lo & 1)); \ - V.lo = (V.hi << 63) | (V.lo >> 1); \ - V.hi = (V.hi >> 1) ^ ((uint64_t)T << 32); \ - } \ +#define REDUCE1BIT(V) \ + do { \ + if (sizeof(size_t) == 8) { \ + uint64_t T = OPENSSL_U64(0xe100000000000000) & (0 - (V.lo & 1)); \ + V.lo = (V.hi << 63) | (V.lo >> 1); \ + V.hi = (V.hi >> 1) ^ T; \ + } else { \ + uint32_t T = 0xe1000000U & (0 - (uint32_t)(V.lo & 1)); \ + V.lo = (V.hi << 63) | (V.lo >> 1); \ + V.hi = (V.hi >> 1) ^ ((uint64_t)T << 32); \ + } \ } while (0) @@ -542,7 +543,7 @@ int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const uint8_t *aad, size_t len) { } alen += len; - if (alen > (U64(1) << 61) || (sizeof(len) == 8 && alen < len)) { + if (alen > (OPENSSL_U64(1) << 61) || (sizeof(len) == 8 && alen < len)) { return 0; } ctx->len.u[0] = alen; @@ -608,7 +609,8 @@ int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const unsigned char *in, #endif mlen += len; - if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) { + if (mlen > ((OPENSSL_U64(1) << 36) - 32) || + (sizeof(len) == 8 && mlen < len)) { return 0; } ctx->len.u[1] = mlen; @@ -767,7 +769,8 @@ int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const unsigned char *in, #endif mlen += len; - if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) { + if (mlen > ((OPENSSL_U64(1) << 36) - 32) || + (sizeof(len) == 8 && mlen < len)) { return 0; } ctx->len.u[1] = mlen; @@ -932,7 +935,8 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, const uint8_t *in, #endif mlen += len; - if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) { + if (mlen > ((OPENSSL_U64(1) << 36) - 32) || + (sizeof(len) == 8 && mlen < len)) { return 0; } ctx->len.u[1] = mlen; @@ -1041,7 +1045,8 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, const uint8_t *in, #endif mlen += len; - if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len)) { + if (mlen > ((OPENSSL_U64(1) << 36) - 32) || + (sizeof(len) == 8 && mlen < len)) { return 0; } ctx->len.u[1] = mlen; diff --git a/crypto/modes/internal.h b/crypto/modes/internal.h index 4659eab5..9662e0dd 100644 --- a/crypto/modes/internal.h +++ b/crypto/modes/internal.h @@ -185,15 +185,6 @@ struct ccm128_context { void *key; }; -#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) -#define U64(C) C##UI64 -#elif defined(__arch64__) -#define U64(C) C##UL -#else -#define U64(C) C##ULL -#endif - - #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) /* crypto_gcm_clmul_enabled returns one if the CLMUL implementation of GCM is * used. */ |