Remove use of data from SHA-2 data structures

Only compiled and used with Intel speed-up code
This commit is contained in:
Sean Parkinson
2017-11-16 08:59:21 +10:00
parent 9dd8baecc0
commit 20edc0e961
4 changed files with 24 additions and 24 deletions

View File

@@ -612,7 +612,7 @@ static int InitSha256(wc_Sha256* sha256)
S[i] = sha256->digest[i]; S[i] = sha256->digest[i];
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
W[i] = ((word32*)sha256->data)[i]; W[i] = sha256->buffer[i];
for (i = 16; i < WC_SHA256_BLOCK_SIZE; i++) for (i = 16; i < WC_SHA256_BLOCK_SIZE; i++)
W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16]; W[i] = Gamma1(W[i-2]) + W[i-7] + Gamma0(W[i-15]) + W[i-16];
@@ -702,7 +702,6 @@ static INLINE void AddLength(wc_Sha256* sha256, word32 len)
WC_SHA256_BLOCK_SIZE); WC_SHA256_BLOCK_SIZE);
} }
#endif #endif
sha256->data = local;
ret = XTRANSFORM(sha256); ret = XTRANSFORM(sha256);
if (ret == 0) { if (ret == 0) {
AddLength(sha256, WC_SHA256_BLOCK_SIZE); AddLength(sha256, WC_SHA256_BLOCK_SIZE);
@@ -734,15 +733,16 @@ static INLINE void AddLength(wc_Sha256* sha256, word32 len)
word32 blocksLen = len & ~(WC_SHA256_BLOCK_SIZE-1); word32 blocksLen = len & ~(WC_SHA256_BLOCK_SIZE-1);
AddLength(sha256, blocksLen); AddLength(sha256, blocksLen);
sha256->data = data;
while (len >= WC_SHA256_BLOCK_SIZE) { while (len >= WC_SHA256_BLOCK_SIZE) {
XMEMCPY(local, data, WC_SHA256_BLOCK_SIZE);
data += WC_SHA256_BLOCK_SIZE;
len -= WC_SHA256_BLOCK_SIZE;
/* Byte reversal performed in function if required. */ /* Byte reversal performed in function if required. */
ret = XTRANSFORM(sha256); ret = XTRANSFORM(sha256);
if (ret != 0) if (ret != 0)
break; break;
sha256->data = (data += WC_SHA256_BLOCK_SIZE);
len -= WC_SHA256_BLOCK_SIZE;
} }
} }
#else #else
@@ -750,7 +750,6 @@ static INLINE void AddLength(wc_Sha256* sha256, word32 len)
word32 blocksLen = len & ~(WC_SHA256_BLOCK_SIZE-1); word32 blocksLen = len & ~(WC_SHA256_BLOCK_SIZE-1);
AddLength(sha256, blocksLen); AddLength(sha256, blocksLen);
sha256->data = local;
while (len >= WC_SHA256_BLOCK_SIZE) { while (len >= WC_SHA256_BLOCK_SIZE) {
XMEMCPY(local, data, WC_SHA256_BLOCK_SIZE); XMEMCPY(local, data, WC_SHA256_BLOCK_SIZE);
@@ -789,7 +788,6 @@ static INLINE void AddLength(wc_Sha256* sha256, word32 len)
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
} }
sha256->data = local;
AddLength(sha256, sha256->buffLen); /* before adding pads */ AddLength(sha256, sha256->buffLen); /* before adding pads */
local[sha256->buffLen++] = 0x80; /* add 1 */ local[sha256->buffLen++] = 0x80; /* add 1 */
@@ -1711,7 +1709,7 @@ SHA256_NOINLINE static int Transform_Sha256_AVX1(wc_Sha256* sha256)
"subq $64, %%rsp\n\t" "subq $64, %%rsp\n\t"
"movq 120(%[sha256]), %%rax\n\t" "leaq 32(%[sha256]), %%rax\n\t"
Init_Masks(BYTE_FLIP_MASK, SHUF_00BA, SHUF_DC00) Init_Masks(BYTE_FLIP_MASK, SHUF_00BA, SHUF_DC00)
LOAD_DIGEST() LOAD_DIGEST()
@@ -1840,7 +1838,7 @@ SHA256_NOINLINE static int Transform_Sha256_AVX1_RORX(wc_Sha256* sha256)
"subq $64, %%rsp\n\t" "subq $64, %%rsp\n\t"
Init_Masks(BYTE_FLIP_MASK, SHUF_00BA, SHUF_DC00) Init_Masks(BYTE_FLIP_MASK, SHUF_00BA, SHUF_DC00)
"movq 120(%[sha256]), %%rax\n\t" "leaq 32(%[sha256]), %%rax\n\t"
W_K_from_buff(X0, X1, X2, X3, BYTE_FLIP_MASK) W_K_from_buff(X0, X1, X2, X3, BYTE_FLIP_MASK)
LOAD_DIGEST() LOAD_DIGEST()
@@ -2233,7 +2231,7 @@ SHA256_NOINLINE static int Transform_Sha256_AVX2(wc_Sha256* sha256)
__asm__ __volatile__ ( __asm__ __volatile__ (
"subq $512, %%rsp\n\t" "subq $512, %%rsp\n\t"
"movq 120(%[sha256]), %%rax\n\t" "leaq 32(%[sha256]), %%rax\n\t"
INIT_MASKS_Y(BYTE_FLIP_MASK, SHUF_Y_00BA, SHUF_Y_DC00) INIT_MASKS_Y(BYTE_FLIP_MASK, SHUF_Y_00BA, SHUF_Y_DC00)
LOAD_DIGEST() LOAD_DIGEST()
@@ -2392,7 +2390,7 @@ SHA256_NOINLINE static int Transform_Sha256_AVX2_RORX(wc_Sha256* sha256)
__asm__ __volatile__ ( __asm__ __volatile__ (
"subq $512, %%rsp\n\t" "subq $512, %%rsp\n\t"
"movq 120(%[sha256]), %%rax\n\t" "leaq 32(%[sha256]), %%rax\n\t"
INIT_MASKS_Y(BYTE_FLIP_MASK, SHUF_Y_00BA, SHUF_Y_DC00) INIT_MASKS_Y(BYTE_FLIP_MASK, SHUF_Y_00BA, SHUF_Y_DC00)
LOAD_W_K_LOW(BYTE_FLIP_MASK, rax) LOAD_W_K_LOW(BYTE_FLIP_MASK, rax)

View File

@@ -409,7 +409,7 @@ static const word64 K512[80] = {
W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817) W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817)
}; };
#define blk0(i) (W[i] = ((word64*)sha512->data)[i]) #define blk0(i) (W[i] = sha512->buffer[i])
#define blk2(i) (\ #define blk2(i) (\
W[ i & 15] += \ W[ i & 15] += \
@@ -534,7 +534,6 @@ static INLINE int Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
WC_SHA512_BLOCK_SIZE); WC_SHA512_BLOCK_SIZE);
} }
#endif #endif
sha512->data = local;
ret = Transform_Sha512(sha512); ret = Transform_Sha512(sha512);
if (ret == 0) { if (ret == 0) {
AddLength(sha512, WC_SHA512_BLOCK_SIZE); AddLength(sha512, WC_SHA512_BLOCK_SIZE);
@@ -566,15 +565,16 @@ static INLINE int Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
word32 blocksLen = len & ~(WC_SHA512_BLOCK_SIZE-1); word32 blocksLen = len & ~(WC_SHA512_BLOCK_SIZE-1);
AddLength(sha512, blocksLen); AddLength(sha512, blocksLen);
sha512->data = data;
while (len >= WC_SHA512_BLOCK_SIZE) { while (len >= WC_SHA512_BLOCK_SIZE) {
XMEMCPY(local, data, WC_SHA512_BLOCK_SIZE);
data += WC_SHA512_BLOCK_SIZE;
len -= WC_SHA512_BLOCK_SIZE;
/* Byte reversal performed in function if required. */ /* Byte reversal performed in function if required. */
ret = Transform_Sha512(sha512); ret = Transform_Sha512(sha512);
if (ret != 0) if (ret != 0)
break; break;
sha512->data = (data += WC_SHA512_BLOCK_SIZE);
len -= WC_SHA512_BLOCK_SIZE;
} }
} }
#else #else
@@ -582,7 +582,6 @@ static INLINE int Sha512Update(wc_Sha512* sha512, const byte* data, word32 len)
word32 blocksLen = len & ~(WC_SHA512_BLOCK_SIZE-1); word32 blocksLen = len & ~(WC_SHA512_BLOCK_SIZE-1);
AddLength(sha512, blocksLen); AddLength(sha512, blocksLen);
sha512->data = local;
while (len >= WC_SHA512_BLOCK_SIZE) { while (len >= WC_SHA512_BLOCK_SIZE) {
XMEMCPY(local, data, WC_SHA512_BLOCK_SIZE); XMEMCPY(local, data, WC_SHA512_BLOCK_SIZE);
@@ -636,7 +635,6 @@ static INLINE int Sha512Final(wc_Sha512* sha512)
AddLength(sha512, sha512->buffLen); /* before adding pads */ AddLength(sha512, sha512->buffLen); /* before adding pads */
local[sha512->buffLen++] = 0x80; /* add 1 */ local[sha512->buffLen++] = 0x80; /* add 1 */
sha512->data = local;
/* pad with zeros */ /* pad with zeros */
if (sha512->buffLen > WC_SHA512_PAD_SIZE) { if (sha512->buffLen > WC_SHA512_PAD_SIZE) {
@@ -1344,7 +1342,7 @@ static int Transform_Sha512_AVX1(wc_Sha512* sha512)
/* 16 Ws plus loop counter. */ /* 16 Ws plus loop counter. */
"subq $136, %%rsp\n\t" "subq $136, %%rsp\n\t"
"movq 224(%[sha512]), %%rax\n\t" "leaq 64(%[sha512]), %%rax\n\t"
INIT_MASK(MASK) INIT_MASK(MASK)
LOAD_DIGEST() LOAD_DIGEST()
@@ -1496,7 +1494,7 @@ static int Transform_Sha512_AVX1_RORX(wc_Sha512* sha512)
/* 16 Ws plus loop counter and K512. */ /* 16 Ws plus loop counter and K512. */
"subq $144, %%rsp\n\t" "subq $144, %%rsp\n\t"
"movq 224(%[sha512]), %%rax\n\t" "leaq 64(%[sha512]), %%rax\n\t"
INIT_MASK(MASK) INIT_MASK(MASK)
LOAD_DIGEST() LOAD_DIGEST()
@@ -2192,7 +2190,7 @@ static int Transform_Sha512_AVX2(wc_Sha512* sha512)
/* 16 Ws plus loop counter and K512. */ /* 16 Ws plus loop counter and K512. */
"subq $136, %%rsp\n\t" "subq $136, %%rsp\n\t"
"movq 224(%[sha512]), %%rax\n\t" "leaq 64(%[sha512]), %%rax\n\t"
INIT_MASK(MASK_Y) INIT_MASK(MASK_Y)
LOAD_DIGEST() LOAD_DIGEST()
@@ -2366,7 +2364,7 @@ static int Transform_Sha512_AVX2_RORX(wc_Sha512* sha512)
/* 16 Ws plus loop counter. */ /* 16 Ws plus loop counter. */
"subq $136, %%rsp\n\t" "subq $136, %%rsp\n\t"
"movq 224(%[sha512]), "L2"\n\t" "leaq 64(%[sha512]), "L2"\n\t"
INIT_MASK(MASK_Y) INIT_MASK(MASK_Y)
LOAD_DIGEST() LOAD_DIGEST()

View File

@@ -104,7 +104,9 @@ typedef struct wc_Sha256 {
word32 loLen; /* length in bytes */ word32 loLen; /* length in bytes */
word32 hiLen; /* length in bytes */ word32 hiLen; /* length in bytes */
void* heap; void* heap;
#ifdef USE_INTEL_SPEEDUP
const byte* data; const byte* data;
#endif
#ifdef WOLFSSL_PIC32MZ_HASH #ifdef WOLFSSL_PIC32MZ_HASH
hashUpdCache cache; /* cache for updates */ hashUpdCache cache; /* cache for updates */
#endif #endif

View File

@@ -92,7 +92,9 @@ typedef struct wc_Sha512 {
word64 loLen; /* length in bytes */ word64 loLen; /* length in bytes */
word64 hiLen; /* length in bytes */ word64 hiLen; /* length in bytes */
void* heap; void* heap;
#ifdef USE_INTEL_SPEEDUP
const byte* data; const byte* data;
#endif
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
WC_ASYNC_DEV asyncDev; WC_ASYNC_DEV asyncDev;
#endif /* WOLFSSL_ASYNC_CRYPT */ #endif /* WOLFSSL_ASYNC_CRYPT */