Update hashing library (#384)

This commit is contained in:
Karol Szuster
2016-08-22 11:21:46 +02:00
committed by Vincent Herbet
parent e24b9548d4
commit ea43a61094
12 changed files with 200 additions and 154 deletions

View File

@@ -1,6 +1,6 @@
// //////////////////////////////////////////////////////////
// keccak.cpp
// Copyright (c) 2014 Stephan Brumme. All rights reserved.
// Copyright (c) 2014,2015 Stephan Brumme. All rights reserved.
// see http://create.stephan-brumme.com/disclaimer.html
//
@@ -18,10 +18,10 @@ Keccak::Keccak(Bits bits)
/// same as reset()
void Keccak::changeBits(Bits bits)
{
m_blockSize = (200 - 2 * (bits / 8));
m_bits = bits;
m_blockSize = (200 - 2 * (bits / 8));
m_bits = bits;
reset();
reset();
}
/// restart
@@ -225,11 +225,11 @@ void Keccak::processBuffer()
// add a "1" byte
m_buffer[offset++] = 1;
// fill with zeros
while (offset < blockSize - 1)
while (offset < blockSize)
m_buffer[offset++] = 0;
// and add a single set bit
m_buffer[blockSize - 1] = 0x80;
m_buffer[blockSize - 1] |= 0x80;
processBlock(m_buffer);
}
@@ -257,8 +257,21 @@ const char* Keccak::getHash()
result[written++] = dec2hex[oneByte >> 4];
result[written++] = dec2hex[oneByte & 15];
}
// Keccak224's last entry in m_hash provides only 32 bits instead of 64 bits
unsigned int remainder = m_bits - hashLength * 64;
unsigned int processed = 0;
while (processed < remainder)
{
// convert a byte to hex
unsigned char oneByte = (unsigned char) (m_hash[hashLength] >> processed);
result[written++] = dec2hex[oneByte >> 4];
result[written++] = dec2hex[oneByte & 15];
processed += 8;
}
result[written] = 0;
return (const char *)result;
return const_cast<const char *>(result);
}