summaryrefslogtreecommitdiff
path: root/iterhash.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-07-20 20:12:54 -0400
committerJeffrey Walton <noloader@gmail.com>2018-07-20 20:12:54 -0400
commit414c5c543860947bc43dd1cc523ea62704fdcc99 (patch)
tree03d8fd21581728a677330fcded9a665d26e3fd77 /iterhash.cpp
parent0c0b68a4a28bdcbcf9239b45242d1c3e06788ccc (diff)
downloadcryptopp-git-414c5c543860947bc43dd1cc523ea62704fdcc99.tar.gz
Fix Tiger crash on Sparc (GH #690)
Man, Sparc does not mess around with unaligned buffers. Without -xmemalign=4i the hardware wants 8-byte aligned word64's so it can use the high performance 64-bit move or add. Since we do not use -xmemalign we get the default behavior of either -xmemalgin=8i or -xmemalgin=8s. It shoul dnot matter to us since we removed unaligned data access at GH #682.
Diffstat (limited to 'iterhash.cpp')
-rw-r--r--iterhash.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/iterhash.cpp b/iterhash.cpp
index e9974ced..da34dcb2 100644
--- a/iterhash.cpp
+++ b/iterhash.cpp
@@ -33,7 +33,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
if (num+length >= blockSize)
{
if (input)
- {memcpy(data+num, input, blockSize-num);}
+ {std::memcpy(data+num, input, blockSize-num);}
HashBlock(dataBuf);
input += (blockSize-num);
@@ -44,7 +44,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
else
{
if (input && length)
- {memcpy(data+num, input, length);}
+ {std::memcpy(data+num, input, length);}
return;
}
}
@@ -69,7 +69,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
do
{ // copy input first if it's not aligned correctly
if (input)
- { memcpy(data, input, blockSize); }
+ { std::memcpy(data, input, blockSize); }
HashBlock(dataBuf);
input+=blockSize;
@@ -79,7 +79,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
}
if (input && data != input)
- memcpy(data, input, length);
+ std::memcpy(data, input, length);
}
template <class T, class BASE> byte * IteratedHashBase<T, BASE>::CreateUpdateSpace(size_t &size)
@@ -92,19 +92,22 @@ template <class T, class BASE> byte * IteratedHashBase<T, BASE>::CreateUpdateSpa
template <class T, class BASE> size_t IteratedHashBase<T, BASE>::HashMultipleBlocks(const T *input, size_t length)
{
- unsigned int blockSize = this->BlockSize();
+ const unsigned int blockSize = this->BlockSize();
bool noReverse = NativeByteOrderIs(this->GetByteOrder());
T* dataBuf = this->DataBuf();
// IteratedHashBase Update calls this with an aligned input,
// but HashBlock may call it with an unaligned buffer.
+ // Alignment checks due to Issues 690/
do
{
if (noReverse)
{
if (IsAligned<word64>(input))
+ {
this->HashEndianCorrectedBlock(input);
+ }
else
{
std::memcpy(dataBuf, input, this->BlockSize());
@@ -113,8 +116,17 @@ template <class T, class BASE> size_t IteratedHashBase<T, BASE>::HashMultipleBlo
}
else
{
- ByteReverse(dataBuf, input, this->BlockSize());
- this->HashEndianCorrectedBlock(dataBuf);
+ if (IsAligned<word64>(input))
+ {
+ ByteReverse(dataBuf, input, this->BlockSize());
+ this->HashEndianCorrectedBlock(dataBuf);
+ }
+ else
+ {
+ std::memcpy(dataBuf, input, this->BlockSize());
+ ByteReverse(dataBuf, dataBuf, this->BlockSize());
+ this->HashEndianCorrectedBlock(dataBuf);
+ }
}
input += blockSize/sizeof(T);