summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blake2.cpp4
-rw-r--r--iterhash.cpp37
-rw-r--r--keccak.cpp5
-rw-r--r--sha3.cpp5
-rw-r--r--tiger.cpp1
-rw-r--r--whrlpool.cpp4
6 files changed, 35 insertions, 21 deletions
diff --git a/blake2.cpp b/blake2.cpp
index 0500e7a0..e858f8c7 100644
--- a/blake2.cpp
+++ b/blake2.cpp
@@ -356,6 +356,9 @@ void BLAKE2_Base<W, T_64bit>::Restart(const BLAKE2_ParameterBlock<T_64bit>& bloc
template <class W, bool T_64bit>
void BLAKE2_Base<W, T_64bit>::Update(const byte *input, size_t length)
{
+ CRYPTOPP_ASSERT(input != NULLPTR);
+ if (length == 0) { return; }
+
State& state = *m_state.data();
if (state.length + length > BLOCKSIZE)
{
@@ -390,6 +393,7 @@ void BLAKE2_Base<W, T_64bit>::Update(const byte *input, size_t length)
template <class W, bool T_64bit>
void BLAKE2_Base<W, T_64bit>::TruncatedFinal(byte *hash, size_t size)
{
+ CRYPTOPP_ASSERT(hash != NULLPTR);
this->ThrowIfInvalidTruncatedSize(size);
// Set last block unconditionally
diff --git a/iterhash.cpp b/iterhash.cpp
index 33a697a5..91e00af8 100644
--- a/iterhash.cpp
+++ b/iterhash.cpp
@@ -10,14 +10,16 @@
NAMESPACE_BEGIN(CryptoPP)
-template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte *input, size_t len)
+template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte *input, size_t length)
{
- CRYPTOPP_ASSERT((input && len) || !(input || len));
+ CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0));
+ if (length == 0) { return; }
+
HashWordType oldCountLo = m_countLo, oldCountHi = m_countHi;
- if ((m_countLo = oldCountLo + HashWordType(len)) < oldCountLo)
+ if ((m_countLo = oldCountLo + HashWordType(length)) < oldCountLo)
m_countHi++; // carry from low to high
- m_countHi += (HashWordType)SafeRightShift<8*sizeof(HashWordType)>(len);
- if (m_countHi < oldCountHi || SafeRightShift<2*8*sizeof(HashWordType)>(len) != 0)
+ m_countHi += (HashWordType)SafeRightShift<8*sizeof(HashWordType)>(length);
+ if (m_countHi < oldCountHi || SafeRightShift<2*8*sizeof(HashWordType)>(length) != 0)
throw HashInputTooLong(this->AlgorithmName());
const unsigned int blockSize = this->BlockSize();
@@ -29,36 +31,36 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
if (num != 0) // process left over data
{
- if (num+len >= blockSize)
+ if (num+length >= blockSize)
{
if (data && input) {memcpy(data+num, input, blockSize-num);}
HashBlock(dataBuf);
input += (blockSize-num);
- len -= (blockSize-num);
+ length -= (blockSize-num);
num = 0;
// drop through and do the rest
}
else
{
- if (data && input && len) {memcpy(data+num, input, len);}
+ if (data && input && length) {memcpy(data+num, input, length);}
return;
}
}
// now process the input data in blocks of blockSize bytes and save the leftovers to m_data
- if (len >= blockSize)
+ if (length >= blockSize)
{
if (input == data)
{
- CRYPTOPP_ASSERT(len == blockSize);
+ CRYPTOPP_ASSERT(length == blockSize);
HashBlock(dataBuf);
return;
}
else if (IsAligned<T>(input))
{
- size_t leftOver = HashMultipleBlocks((T *)(void*)input, len);
- input += (len - leftOver);
- len = leftOver;
+ size_t leftOver = HashMultipleBlocks((T *)(void*)input, length);
+ input += (length - leftOver);
+ length = leftOver;
}
else
do
@@ -66,12 +68,12 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Update(const byte
if (data && input) memcpy(data, input, blockSize);
HashBlock(dataBuf);
input+=blockSize;
- len-=blockSize;
- } while (len >= blockSize);
+ length-=blockSize;
+ } while (length >= blockSize);
}
- if (data && input && len && data != input)
- memcpy(data, input, len);
+ if (data && input && data != input)
+ memcpy(data, input, length);
}
template <class T, class BASE> byte * IteratedHashBase<T, BASE>::CreateUpdateSpace(size_t &size)
@@ -129,6 +131,7 @@ template <class T, class BASE> void IteratedHashBase<T, BASE>::Restart()
template <class T, class BASE> void IteratedHashBase<T, BASE>::TruncatedFinal(byte *digest, size_t size)
{
+ CRYPTOPP_ASSERT(digest != NULLPTR);
this->ThrowIfInvalidTruncatedSize(size);
T* dataBuf = this->DataBuf();
diff --git a/keccak.cpp b/keccak.cpp
index cc1771cf..3450dd6a 100644
--- a/keccak.cpp
+++ b/keccak.cpp
@@ -251,8 +251,8 @@ static void KeccakF1600(word64 *state)
void Keccak::Update(const byte *input, size_t length)
{
- CRYPTOPP_ASSERT((input && length) || !(input || length));
- if (!length) { return; }
+ CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0));
+ if (length == 0) { return; }
size_t spaceLeft;
while (length >= (spaceLeft = r() - m_counter))
@@ -278,6 +278,7 @@ void Keccak::Restart()
void Keccak::TruncatedFinal(byte *hash, size_t size)
{
+ CRYPTOPP_ASSERT(hash != NULLPTR);
ThrowIfInvalidTruncatedSize(size);
m_state.BytePtr()[m_counter] ^= 1;
diff --git a/sha3.cpp b/sha3.cpp
index ec3b04e3..51e01117 100644
--- a/sha3.cpp
+++ b/sha3.cpp
@@ -251,8 +251,8 @@ static void KeccakF1600(word64 *state)
void SHA3::Update(const byte *input, size_t length)
{
- CRYPTOPP_ASSERT((input && length) || !(input || length));
- if (!length) { return; }
+ CRYPTOPP_ASSERT(!(input == NULLPTR && length != 0));
+ if (length == 0) { return; }
size_t spaceLeft;
while (length >= (spaceLeft = r() - m_counter))
@@ -278,6 +278,7 @@ void SHA3::Restart()
void SHA3::TruncatedFinal(byte *hash, size_t size)
{
+ CRYPTOPP_ASSERT(hash != NULLPTR);
ThrowIfInvalidTruncatedSize(size);
m_state.BytePtr()[m_counter] ^= 0x06;
diff --git a/tiger.cpp b/tiger.cpp
index 3365b981..a4a1f291 100644
--- a/tiger.cpp
+++ b/tiger.cpp
@@ -25,6 +25,7 @@ void Tiger::InitState(HashWordType *state)
void Tiger::TruncatedFinal(byte *hash, size_t size)
{
+ CRYPTOPP_ASSERT(hash != NULLPTR);
ThrowIfInvalidTruncatedSize(size);
PadLastBlock(56, 0x01);
diff --git a/whrlpool.cpp b/whrlpool.cpp
index e0e401cc..3986e225 100644
--- a/whrlpool.cpp
+++ b/whrlpool.cpp
@@ -96,6 +96,7 @@ void Whirlpool::InitState(HashWordType *state)
void Whirlpool::TruncatedFinal(byte *hash, size_t size)
{
+ CRYPTOPP_ASSERT(hash != NULLPTR);
ThrowIfInvalidTruncatedSize(size);
PadLastBlock(32);
@@ -407,6 +408,9 @@ const word64 Whirlpool_C[4*256+R] = {
// Whirlpool basic transformation. Transforms state based on block.
void Whirlpool::Transform(word64 *digest, const word64 *block)
{
+ CRYPTOPP_ASSERT(digest != NULLPTR);
+ CRYPTOPP_ASSERT(block != NULLPTR);
+
#if CRYPTOPP_SSE2_ASM_AVAILABLE
if (HasSSE2())
{