summaryrefslogtreecommitdiff
path: root/blake2.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2020-01-08 20:12:15 -0500
committerJeffrey Walton <noloader@gmail.com>2020-01-08 20:12:15 -0500
commit46d61353560bed79a7df3589b2480c087f17e7b1 (patch)
tree9546bf63b57ee5983d6d27b724728cbbc8ae9438 /blake2.cpp
parentf619ad4b69eb3c90537dbb54dc2c8a074fb362bb (diff)
downloadcryptopp-git-46d61353560bed79a7df3589b2480c087f17e7b1.tar.gz
Fix BLAKE2 using default Salt and Personalization (GH #921)
We are going to keep the bug report open until we get some official test vectors. We will probably have to modify one of the Blake team's test programs since they did not publish test vectors using salt or personalization
Diffstat (limited to 'blake2.cpp')
-rw-r--r--blake2.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/blake2.cpp b/blake2.cpp
index 4bf09a26..c0664ad8 100644
--- a/blake2.cpp
+++ b/blake2.cpp
@@ -494,15 +494,13 @@ void BLAKE2s::Restart(const BLAKE2s_ParameterBlock& block, const word32 counter[
// We take a parameter block as a parameter to allow customized state.
// Avoid the copy of the parameter block when we are passing our own block.
- if (block.data() == m_block.data())
- m_block.Reset(m_digestSize, m_keyLength);
- else
- {
+ if (block.data() != m_block.data()) {
std::memcpy(m_block.data(), block.data(), m_block.size());
- m_block.m_data[BLAKE2s_ParameterBlock::DigestOff] = (byte)m_digestSize;
- m_block.m_data[BLAKE2s_ParameterBlock::KeyOff] = (byte)m_keyLength;
}
+ m_block.m_data[BLAKE2s_ParameterBlock::DigestOff] = (byte)m_digestSize;
+ m_block.m_data[BLAKE2s_ParameterBlock::KeyOff] = (byte)m_keyLength;
+
const word32* iv = BLAKE2S_IV;
PutBlock<word32, LittleEndian, true> put(m_block.data(), m_state.h());
put(iv[0])(iv[1])(iv[2])(iv[3])(iv[4])(iv[5])(iv[6])(iv[7]);
@@ -527,15 +525,13 @@ void BLAKE2b::Restart(const BLAKE2b_ParameterBlock& block, const word64 counter[
// We take a parameter block as a parameter to allow customized state.
// Avoid the copy of the parameter block when we are passing our own block.
- if (block.data() == m_block.data())
- m_block.Reset(m_digestSize, m_keyLength);
- else
- {
+ if (block.data() != m_block.data()) {
std::memcpy(m_block.data(), block.data(), m_block.size());
- m_block.m_data[BLAKE2b_ParameterBlock::DigestOff] = (byte)m_digestSize;
- m_block.m_data[BLAKE2b_ParameterBlock::KeyOff] = (byte)m_keyLength;
}
+ m_block.m_data[BLAKE2b_ParameterBlock::DigestOff] = (byte)m_digestSize;
+ m_block.m_data[BLAKE2b_ParameterBlock::KeyOff] = (byte)m_keyLength;
+
const word64* iv = BLAKE2B_IV;
PutBlock<word64, LittleEndian, true> put(m_block.data(), m_state.h());
put(iv[0])(iv[1])(iv[2])(iv[3])(iv[4])(iv[5])(iv[6])(iv[7]);