summaryrefslogtreecommitdiff
path: root/iterhash.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-07-20 18:56:41 -0400
committerJeffrey Walton <noloader@gmail.com>2018-07-20 18:56:41 -0400
commit0c0b68a4a28bdcbcf9239b45242d1c3e06788ccc (patch)
tree22f329a533083061b4d622220d05d2c96ca60182 /iterhash.h
parent365e65c2eba53f8d446df293c60eef6debcf3d02 (diff)
downloadcryptopp-git-0c0b68a4a28bdcbcf9239b45242d1c3e06788ccc.tar.gz
Align input buffer in HashMultipleBlocks
IteratedHashBase::Update aligns the buffer, but IteratedHashBase::HashBlock does not. It was causing a fair number of asserts to fire when the code was instrumented with alignment checks. Linux benchmarks shows the code does not run materially slower on i686 or x86_64.
Diffstat (limited to 'iterhash.h')
-rw-r--r--iterhash.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/iterhash.h b/iterhash.h
index 45142f85..06b5f0aa 100644
--- a/iterhash.h
+++ b/iterhash.h
@@ -95,8 +95,10 @@ public:
virtual std::string AlgorithmProvider() const { return "C++"; }
protected:
- inline T GetBitCountHi() const {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
- inline T GetBitCountLo() const {return m_countLo << 3;}
+ inline T GetBitCountHi() const
+ {return (m_countLo >> (8*sizeof(T)-3)) + (m_countHi << 3);}
+ inline T GetBitCountLo() const
+ {return m_countLo << 3;}
void PadLastBlock(unsigned int lastBlockSize, byte padFirst=0x80);
virtual void Init() =0;
@@ -104,7 +106,8 @@ protected:
virtual ByteOrder GetByteOrder() const =0;
virtual void HashEndianCorrectedBlock(const HashWordType *data) =0;
virtual size_t HashMultipleBlocks(const T *input, size_t length);
- void HashBlock(const HashWordType *input) {HashMultipleBlocks(input, this->BlockSize());}
+ void HashBlock(const HashWordType *input)
+ {HashMultipleBlocks(input, this->BlockSize());}
virtual T* DataBuf() =0;
virtual T* StateBuf() =0;
@@ -151,6 +154,11 @@ public:
/// \details CorrectEndianess() calls ConditionalByteReverse() using <tt>T_Endianness</tt>.
inline void CorrectEndianess(HashWordType *out, const HashWordType *in, size_t byteCount)
{
+ CRYPTOPP_ASSERT(in != NULLPTR);
+ CRYPTOPP_ASSERT(out != NULLPTR);
+ CRYPTOPP_ASSERT(IsAligned<T_HashWordType>(in));
+ CRYPTOPP_ASSERT(IsAligned<T_HashWordType>(out));
+
ConditionalByteReverse(T_Endianness::ToEnum(), out, in, byteCount);
}