Fixed bug

This commit is contained in:
MoneroOcean 2020-07-16 17:59:29 -07:00
parent b9a84ef8e1
commit 47acc49471

View file

@ -34,7 +34,13 @@
#include "sha256.h" #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 */ /* Miscompile with icc 14.0.0 (at least), so don't use restrict there */
#define restrict #define restrict
#elif __STDC_VERSION__ >= 199901L #elif __STDC_VERSION__ >= 199901L
@ -132,9 +138,9 @@ static const uint32_t Krnd[64] = {
* the 512-bit input block to produce a new state. * the 512-bit input block to produce a new state.
*/ */
static void static void
SHA256_Transform(uint32_t state[static restrict 8], SHA256_Transform(uint32_t state[static_restrict(8)],
const uint8_t block[static restrict 64], const uint8_t block[static_restrict(64)],
uint32_t W[static restrict 64], uint32_t S[static restrict 8]) uint32_t W[static_restrict(64)], uint32_t S[static_restrict(8)])
{ {
int i; int i;
@ -203,7 +209,7 @@ static const uint8_t PAD[64] = {
/* Add padding and terminating bit-count. */ /* Add padding and terminating bit-count. */
static void 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; size_t r;
@ -257,7 +263,7 @@ SHA256_Init(SHA256_CTX * ctx)
*/ */
static void static void
_SHA256_Update(SHA256_CTX * ctx, const void * in, size_t len, _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; uint32_t r;
const uint8_t * src = in; const uint8_t * src = in;
@ -315,7 +321,7 @@ SHA256_Update(SHA256_CTX * ctx, const void * in, size_t len)
*/ */
static void static void
_SHA256_Final(uint8_t digest[32], SHA256_CTX * ctx, _SHA256_Final(uint8_t digest[32], SHA256_CTX * ctx,
uint32_t tmp32[static restrict 72]) uint32_t tmp32[static_restrict(72)])
{ {
/* Add padding. */ /* Add padding. */
@ -367,8 +373,8 @@ SHA256_Buf(const void * in, size_t len, uint8_t digest[32])
*/ */
static void static void
_HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen, _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], uint32_t tmp32[static_restrict(72)], uint8_t pad[static_restrict(64)],
uint8_t khash[static restrict 32]) uint8_t khash[static_restrict(32)])
{ {
const uint8_t * K = _K; const uint8_t * K = _K;
size_t i; size_t i;
@ -420,7 +426,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
*/ */
static void static void
_HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void * in, size_t len, _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. */ /* 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 static void
_HMAC_SHA256_Final(uint8_t digest[32], HMAC_SHA256_CTX * ctx, _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. */ /* 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. */ /* Add padding and terminating bit-count, but don't invoke Transform yet. */
static int static int
SHA256_Pad_Almost(SHA256_CTX * ctx, uint8_t len[static restrict 8], SHA256_Pad_Almost(SHA256_CTX * ctx, uint8_t len[static_restrict(8)],
uint32_t tmp32[static restrict 72]) uint32_t tmp32[static_restrict(72)])
{ {
uint32_t r; uint32_t r;