From 4aafb0e6a3c307809983007aaa01c84565122649 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sat, 21 Jul 2018 10:28:48 -0400 Subject: Cleanup SHA512::Transform code The extra code paths added at GH #689 were no longer needed after GH #691 --- sha.cpp | 54 +++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) (limited to 'sha.cpp') diff --git a/sha.cpp b/sha.cpp index aeaf95b0..951d7705 100644 --- a/sha.cpp +++ b/sha.cpp @@ -16,11 +16,12 @@ // SHA{N}::HashMultipleBlocks (class), and the function calls SHA{N}_HashMultipleBlocks // (free standing) or SHA{N}_HashBlock (free standing) as a fallback. // -// An added wrinkle is hardware is little endian, C++ is big endian, and callers use big endian, -// so SHA{N}_HashMultipleBlock accepts a ByteOrder for the incoming data arrangement. Hardware -// based SHA{N}_HashMultipleBlock can often perform the endian swap much easier by setting -// an EPI mask. Endian swap incurs no penalty on Intel SHA, and 4-instruction penaly on ARM SHA. -// Under C++ the full software based swap penalty is incurred due to use of ReverseBytes(). +// An added wrinkle is hardware is little endian, C++ is big endian, and callers use +// big endian, so SHA{N}_HashMultipleBlock accepts a ByteOrder for the incoming data +// arrangement. Hardware based SHA{N}_HashMultipleBlock can often perform the endian +// swap much easier by setting an EPI mask. Endian swap incurs no penalty on Intel SHA, +// and 4-instruction penaly on ARM SHA. Under C++ the full software based swap penalty +// is incurred due to use of ReverseBytes(). // // The rework also removed the hacked-in pointers to implementations. @@ -1166,7 +1167,7 @@ ANONYMOUS_NAMESPACE_BEGIN #define g(i) T[(6-i)&7] #define h(i) T[(7-i)&7] -#define blk0(i) (W[i]=D[i]) +#define blk0(i) (W[i]=data[i]) #define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])) #define Ch(x,y,z) (z^(x&(y^z))) @@ -1190,9 +1191,6 @@ void SHA512_HashBlock_CXX(word64 *state, const word64 *data) /* Copy context->state[] to working vars */ std::memcpy(T, state, sizeof(T)); - /* Solaris/Sparc64 crash */ - std::memcpy(D, data, sizeof(D)); - /* 80 operations, partially loop unrolled */ for (unsigned int j=0; j<80; j+=16) { @@ -1202,36 +1200,14 @@ void SHA512_HashBlock_CXX(word64 *state, const word64 *data) R(12); R(13); R(14); R(15); } - /* Solaris 11/Sparc64 crash */ - if (IsAligned(state) == true) - { - /* Add the working vars back into context.state[] */ - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); - } - else - { - /* Reuse W[] */ - std::memcpy(W, state, 8 * sizeof(W[0])); - - /* Add the working vars back into context.state[] */ - W[0] += a(0); - W[1] += b(0); - W[2] += c(0); - W[3] += d(0); - W[4] += e(0); - W[5] += f(0); - W[6] += g(0); - W[7] += h(0); - - std::memcpy(state, W, 8 * sizeof(W[0])); - } + state[0] += a(0); + state[1] += b(0); + state[2] += c(0); + state[3] += d(0); + state[4] += e(0); + state[5] += f(0); + state[6] += g(0); + state[7] += h(0); } ANONYMOUS_NAMESPACE_END -- cgit v1.2.1