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
This commit is contained in:
Jeffrey Walton 2020-01-08 20:12:15 -05:00
parent f619ad4b69
commit 46d6135356

View File

@ -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]);