mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibCrypto: Correctly pad blocks with FinalBlockSize < size < BlockSize
This fixes #2488
This commit is contained in:
parent
a3f51089d2
commit
63cc2f58ea
2 changed files with 30 additions and 3 deletions
|
@ -115,17 +115,26 @@ SHA1::DigestType SHA1::peek()
|
|||
__builtin_memcpy(data, m_data_buffer, m_data_length);
|
||||
__builtin_memcpy(state, m_state, 20);
|
||||
|
||||
if (BlockSize == m_data_length) {
|
||||
transform(m_data_buffer);
|
||||
m_bit_length += BlockSize * 8;
|
||||
m_data_length = 0;
|
||||
i = 0;
|
||||
}
|
||||
|
||||
if (m_data_length < FinalBlockDataSize) {
|
||||
m_data_buffer[i++] = 0x80;
|
||||
while (i < FinalBlockDataSize)
|
||||
m_data_buffer[i++] = 0x00;
|
||||
|
||||
} else {
|
||||
// First, complete a block with some padding.
|
||||
m_data_buffer[i++] = 0x80;
|
||||
while (i < BlockSize)
|
||||
m_data_buffer[i++] = 0x00;
|
||||
|
||||
transform(m_data_buffer);
|
||||
|
||||
// Then start another block with BlockSize - 8 bytes of zeros
|
||||
__builtin_memset(m_data_buffer, 0, FinalBlockDataSize);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue