From 47acc494715086078622fb9499ecc9beac9b4bee Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Thu, 16 Jul 2020 17:59:29 -0700 Subject: [PATCH] Fixed bug --- src/crypto/randomx/panthera/sha256.c | 32 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/crypto/randomx/panthera/sha256.c b/src/crypto/randomx/panthera/sha256.c index 41cedbc2..eb302f1c 100644 --- a/src/crypto/randomx/panthera/sha256.c +++ b/src/crypto/randomx/panthera/sha256.c @@ -34,7 +34,13 @@ #include "sha256.h" -#if defined(__ICC) || defined(_MSC_VER) +#if defined(_MSC_VER) +#define static_restrict(n) +#elif +#define static_restrict(n) static restrict n +#endif + +#ifdef __ICC /* Miscompile with icc 14.0.0 (at least), so don't use restrict there */ #define restrict #elif __STDC_VERSION__ >= 199901L @@ -132,9 +138,9 @@ static const uint32_t Krnd[64] = { * the 512-bit input block to produce a new state. */ static void -SHA256_Transform(uint32_t state[static restrict 8], - const uint8_t block[static restrict 64], - uint32_t W[static restrict 64], uint32_t S[static restrict 8]) +SHA256_Transform(uint32_t state[static_restrict(8)], + const uint8_t block[static_restrict(64)], + uint32_t W[static_restrict(64)], uint32_t S[static_restrict(8)]) { int i; @@ -203,7 +209,7 @@ static const uint8_t PAD[64] = { /* Add padding and terminating bit-count. */ static void -SHA256_Pad(SHA256_CTX * ctx, uint32_t tmp32[static restrict 72]) +SHA256_Pad(SHA256_CTX * ctx, uint32_t tmp32[static_restrict(72)]) { size_t r; @@ -257,7 +263,7 @@ SHA256_Init(SHA256_CTX * ctx) */ static void _SHA256_Update(SHA256_CTX * ctx, const void * in, size_t len, - uint32_t tmp32[static restrict 72]) + uint32_t tmp32[static_restrict(72)]) { uint32_t r; const uint8_t * src = in; @@ -315,7 +321,7 @@ SHA256_Update(SHA256_CTX * ctx, const void * in, size_t len) */ static void _SHA256_Final(uint8_t digest[32], SHA256_CTX * ctx, - uint32_t tmp32[static restrict 72]) + uint32_t tmp32[static_restrict(72)]) { /* Add padding. */ @@ -367,8 +373,8 @@ SHA256_Buf(const void * in, size_t len, uint8_t digest[32]) */ static void _HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen, - uint32_t tmp32[static restrict 72], uint8_t pad[static restrict 64], - uint8_t khash[static restrict 32]) + uint32_t tmp32[static_restrict(72)], uint8_t pad[static_restrict(64)], + uint8_t khash[static_restrict(32)]) { const uint8_t * K = _K; size_t i; @@ -420,7 +426,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) */ static void _HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len, - uint32_t tmp32[static restrict 72]) + uint32_t tmp32[static_restrict(72)]) { /* Feed data to the inner SHA256 operation. */ @@ -447,7 +453,7 @@ HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len) */ static void _HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX * ctx, - uint32_t tmp32[static restrict 72], uint8_t ihash[static restrict 32]) + uint32_t tmp32[static_restrict(72)], uint8_t ihash[static_restrict(32)]) { /* Finish the inner SHA256 operation. */ @@ -500,8 +506,8 @@ HMAC_SHA256_Buf(const void * K, size_t Klen, const void * in, size_t len, /* Add padding and terminating bit-count, but don't invoke Transform yet. */ static int -SHA256_Pad_Almost(SHA256_CTX * ctx, uint8_t len[static restrict 8], - uint32_t tmp32[static restrict 72]) +SHA256_Pad_Almost(SHA256_CTX * ctx, uint8_t len[static_restrict(8)], + uint32_t tmp32[static_restrict(72)]) { uint32_t r;