Use UINT64_C instead of OPENSSL_U64.
stdint.h already has macros for this. The spec says that, in C++,
__STDC_CONSTANT_MACROS is needed, so define it for bytestring_test.cc.
Chromium seems to use these macros without trouble, so I'm assuming we
can rely on them.
Change-Id: I56d178689b44d22c6379911bbb93d3b01dd832a3
Reviewed-on: https://boringssl-review.googlesource.com/6510
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc
index f25c186..99f8bd1 100644
--- a/crypto/bytestring/bytestring_test.cc
+++ b/crypto/bytestring/bytestring_test.cc
@@ -12,6 +12,10 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+#if !defined(__STDC_CONSTANT_MACROS)
+#define __STDC_CONSTANT_MACROS
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -22,7 +26,6 @@
#include <openssl/bytestring.h>
#include "internal.h"
-#include "../internal.h"
#include "../test/scoped_types.h"
@@ -627,9 +630,9 @@
{127, "\x02\x01\x7f", 3},
{128, "\x02\x02\x00\x80", 4},
{0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7},
- {OPENSSL_U64(0x0102030405060708),
+ {UINT64_C(0x0102030405060708),
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
- {OPENSSL_U64(0xffffffffffffffff),
+ {UINT64_C(0xffffffffffffffff),
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
};
diff --git a/crypto/cipher/e_aes.c b/crypto/cipher/e_aes.c
index b46fed4..e5104b4 100644
--- a/crypto/cipher/e_aes.c
+++ b/crypto/cipher/e_aes.c
@@ -1652,7 +1652,7 @@
if (in_len + aes_ctx->tag_len < in_len ||
/* This input is so large it would overflow the 32-bit block counter. */
- in_len_64 >= (OPENSSL_U64(1) << 32) * AES_BLOCK_SIZE) {
+ in_len_64 >= (UINT64_C(1) << 32) * AES_BLOCK_SIZE) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
diff --git a/crypto/internal.h b/crypto/internal.h
index 713659d..ede8c27 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -168,18 +168,6 @@
#endif
-#if defined(_MSC_VER)
-#define OPENSSL_U64(x) x##UI64
-#else
-
-#if defined(OPENSSL_64_BIT)
-#define OPENSSL_U64(x) x##UL
-#else
-#define OPENSSL_U64(x) x##ULL
-#endif
-
-#endif /* defined(_MSC_VER) */
-
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || defined(OPENSSL_ARM) || \
defined(OPENSSL_AARCH64)
/* OPENSSL_cpuid_setup initializes OPENSSL_ia32cap_P. */
diff --git a/crypto/modes/gcm.c b/crypto/modes/gcm.c
index 8aac741..65451a6 100644
--- a/crypto/modes/gcm.c
+++ b/crypto/modes/gcm.c
@@ -55,7 +55,6 @@
#include <openssl/cpu.h>
#include "internal.h"
-#include "../internal.h"
#if !defined(OPENSSL_NO_ASM) && \
@@ -76,7 +75,7 @@
#define REDUCE1BIT(V) \
do { \
if (sizeof(size_t) == 8) { \
- uint64_t T = OPENSSL_U64(0xe100000000000000) & (0 - (V.lo & 1)); \
+ uint64_t T = UINT64_C(0xe100000000000000) & (0 - (V.lo & 1)); \
V.lo = (V.hi << 63) | (V.lo >> 1); \
V.hi = (V.hi >> 1) ^ T; \
} else { \
@@ -586,7 +585,7 @@
}
alen += len;
- if (alen > (OPENSSL_U64(1) << 61) || (sizeof(len) == 8 && alen < len)) {
+ if (alen > (UINT64_C(1) << 61) || (sizeof(len) == 8 && alen < len)) {
return 0;
}
ctx->len.u[0] = alen;
@@ -653,7 +652,7 @@
#endif
mlen += len;
- if (mlen > ((OPENSSL_U64(1) << 36) - 32) ||
+ if (mlen > ((UINT64_C(1) << 36) - 32) ||
(sizeof(len) == 8 && mlen < len)) {
return 0;
}
@@ -813,7 +812,7 @@
#endif
mlen += len;
- if (mlen > ((OPENSSL_U64(1) << 36) - 32) ||
+ if (mlen > ((UINT64_C(1) << 36) - 32) ||
(sizeof(len) == 8 && mlen < len)) {
return 0;
}
@@ -978,7 +977,7 @@
#endif
mlen += len;
- if (mlen > ((OPENSSL_U64(1) << 36) - 32) ||
+ if (mlen > ((UINT64_C(1) << 36) - 32) ||
(sizeof(len) == 8 && mlen < len)) {
return 0;
}
@@ -1087,7 +1086,7 @@
#endif
mlen += len;
- if (mlen > ((OPENSSL_U64(1) << 36) - 32) ||
+ if (mlen > ((UINT64_C(1) << 36) - 32) ||
(sizeof(len) == 8 && mlen < len)) {
return 0;
}
diff --git a/crypto/sha/sha512.c b/crypto/sha/sha512.c
index beb0f8c..6300f69 100644
--- a/crypto/sha/sha512.c
+++ b/crypto/sha/sha512.c
@@ -60,8 +60,6 @@
#include <openssl/mem.h>
-#include "../internal.h"
-
/* IMPLEMENTATION NOTES.
*
@@ -87,14 +85,14 @@
#endif
int SHA384_Init(SHA512_CTX *sha) {
- sha->h[0] = OPENSSL_U64(0xcbbb9d5dc1059ed8);
- sha->h[1] = OPENSSL_U64(0x629a292a367cd507);
- sha->h[2] = OPENSSL_U64(0x9159015a3070dd17);
- sha->h[3] = OPENSSL_U64(0x152fecd8f70e5939);
- sha->h[4] = OPENSSL_U64(0x67332667ffc00b31);
- sha->h[5] = OPENSSL_U64(0x8eb44a8768581511);
- sha->h[6] = OPENSSL_U64(0xdb0c2e0d64f98fa7);
- sha->h[7] = OPENSSL_U64(0x47b5481dbefa4fa4);
+ sha->h[0] = UINT64_C(0xcbbb9d5dc1059ed8);
+ sha->h[1] = UINT64_C(0x629a292a367cd507);
+ sha->h[2] = UINT64_C(0x9159015a3070dd17);
+ sha->h[3] = UINT64_C(0x152fecd8f70e5939);
+ sha->h[4] = UINT64_C(0x67332667ffc00b31);
+ sha->h[5] = UINT64_C(0x8eb44a8768581511);
+ sha->h[6] = UINT64_C(0xdb0c2e0d64f98fa7);
+ sha->h[7] = UINT64_C(0x47b5481dbefa4fa4);
sha->Nl = 0;
sha->Nh = 0;
@@ -105,14 +103,14 @@
int SHA512_Init(SHA512_CTX *sha) {
- sha->h[0] = OPENSSL_U64(0x6a09e667f3bcc908);
- sha->h[1] = OPENSSL_U64(0xbb67ae8584caa73b);
- sha->h[2] = OPENSSL_U64(0x3c6ef372fe94f82b);
- sha->h[3] = OPENSSL_U64(0xa54ff53a5f1d36f1);
- sha->h[4] = OPENSSL_U64(0x510e527fade682d1);
- sha->h[5] = OPENSSL_U64(0x9b05688c2b3e6c1f);
- sha->h[6] = OPENSSL_U64(0x1f83d9abfb41bd6b);
- sha->h[7] = OPENSSL_U64(0x5be0cd19137e2179);
+ sha->h[0] = UINT64_C(0x6a09e667f3bcc908);
+ sha->h[1] = UINT64_C(0xbb67ae8584caa73b);
+ sha->h[2] = UINT64_C(0x3c6ef372fe94f82b);
+ sha->h[3] = UINT64_C(0xa54ff53a5f1d36f1);
+ sha->h[4] = UINT64_C(0x510e527fade682d1);
+ sha->h[5] = UINT64_C(0x9b05688c2b3e6c1f);
+ sha->h[6] = UINT64_C(0x1f83d9abfb41bd6b);
+ sha->h[7] = UINT64_C(0x5be0cd19137e2179);
sha->Nl = 0;
sha->Nh = 0;
@@ -185,7 +183,7 @@
return 1;
}
- l = (c->Nl + (((uint64_t)len) << 3)) & OPENSSL_U64(0xffffffffffffffff);
+ l = (c->Nl + (((uint64_t)len) << 3)) & UINT64_C(0xffffffffffffffff);
if (l < c->Nl) {
c->Nh++;
}