Cleanup SHA512::Transform code

The extra code paths added at GH #689 were no longer needed after GH #691
pull/696/head
Jeffrey Walton 2018-07-21 10:28:48 -04:00
parent f1192fd044
commit 4aafb0e6a3
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 15 additions and 39 deletions

38
sha.cpp
View File

@ -16,11 +16,12 @@
// SHA{N}::HashMultipleBlocks (class), and the function calls SHA{N}_HashMultipleBlocks // SHA{N}::HashMultipleBlocks (class), and the function calls SHA{N}_HashMultipleBlocks
// (free standing) or SHA{N}_HashBlock (free standing) as a fallback. // (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, // An added wrinkle is hardware is little endian, C++ is big endian, and callers use
// so SHA{N}_HashMultipleBlock accepts a ByteOrder for the incoming data arrangement. Hardware // big endian, so SHA{N}_HashMultipleBlock accepts a ByteOrder for the incoming data
// based SHA{N}_HashMultipleBlock can often perform the endian swap much easier by setting // arrangement. Hardware based SHA{N}_HashMultipleBlock can often perform the endian
// an EPI mask. Endian swap incurs no penalty on Intel SHA, and 4-instruction penaly on ARM SHA. // swap much easier by setting an EPI mask. Endian swap incurs no penalty on Intel SHA,
// Under C++ the full software based swap penalty is incurred due to use of ReverseBytes(). // 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. // 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 g(i) T[(6-i)&7]
#define h(i) T[(7-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 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))) #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 */ /* Copy context->state[] to working vars */
std::memcpy(T, state, sizeof(T)); std::memcpy(T, state, sizeof(T));
/* Solaris/Sparc64 crash */
std::memcpy(D, data, sizeof(D));
/* 80 operations, partially loop unrolled */ /* 80 operations, partially loop unrolled */
for (unsigned int j=0; j<80; j+=16) for (unsigned int j=0; j<80; j+=16)
{ {
@ -1202,10 +1200,6 @@ void SHA512_HashBlock_CXX(word64 *state, const word64 *data)
R(12); R(13); R(14); R(15); R(12); R(13); R(14); R(15);
} }
/* Solaris 11/Sparc64 crash */
if (IsAligned<word64>(state) == true)
{
/* Add the working vars back into context.state[] */
state[0] += a(0); state[0] += a(0);
state[1] += b(0); state[1] += b(0);
state[2] += c(0); state[2] += c(0);
@ -1214,24 +1208,6 @@ void SHA512_HashBlock_CXX(word64 *state, const word64 *data)
state[5] += f(0); state[5] += f(0);
state[6] += g(0); state[6] += g(0);
state[7] += h(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]));
}
} }
ANONYMOUS_NAMESPACE_END ANONYMOUS_NAMESPACE_END