Whitespace cleanup

pull/301/head
Jeffrey Walton 2016-09-22 10:35:57 -04:00
parent d5aff4e4f8
commit dcbb0c55d9
2 changed files with 52 additions and 54 deletions

View File

@ -48,8 +48,8 @@ static void KeccakF1600(word64 *state)
word64 Esa, Ese, Esi, Eso, Esu; word64 Esa, Ese, Esi, Eso, Esu;
//copyFromState(A, state) //copyFromState(A, state)
typedef BlockGetAndPut<word64, LittleEndian, true, true> Block; typedef BlockGetAndPut<word64, LittleEndian, true, true> Block;
Block::Get(state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu); Block::Get(state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu);
for( unsigned int round = 0; round < 24; round += 2 ) for( unsigned int round = 0; round < 24; round += 2 )
{ {
@ -245,47 +245,46 @@ static void KeccakF1600(word64 *state)
} }
//copyToState(state, A) //copyToState(state, A)
Block::Put(NULL, state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu); Block::Put(NULL, state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu);
} }
} }
void Keccak::Update(const byte *input, size_t length) void Keccak::Update(const byte *input, size_t length)
{ {
CRYPTOPP_ASSERT((input && length) || !(input || length)); CRYPTOPP_ASSERT((input && length) || !(input || length));
if (!length) if (!length) { return; }
return;
size_t spaceLeft; size_t spaceLeft;
while (length >= (spaceLeft = r() - m_counter)) while (length >= (spaceLeft = r() - m_counter))
{ {
if (spaceLeft) if (spaceLeft)
xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft); xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft);
KeccakF1600(m_state); KeccakF1600(m_state);
input += spaceLeft; input += spaceLeft;
length -= spaceLeft; length -= spaceLeft;
m_counter = 0; m_counter = 0;
} }
if (length) if (length)
xorbuf(m_state.BytePtr() + m_counter, input, length); xorbuf(m_state.BytePtr() + m_counter, input, length);
m_counter += (unsigned int)length; m_counter += (unsigned int)length;
} }
void Keccak::Restart() void Keccak::Restart()
{ {
memset(m_state, 0, m_state.SizeInBytes()); memset(m_state, 0, m_state.SizeInBytes());
m_counter = 0; m_counter = 0;
} }
void Keccak::TruncatedFinal(byte *hash, size_t size) void Keccak::TruncatedFinal(byte *hash, size_t size)
{ {
ThrowIfInvalidTruncatedSize(size); ThrowIfInvalidTruncatedSize(size);
m_state.BytePtr()[m_counter] ^= 1; m_state.BytePtr()[m_counter] ^= 1;
m_state.BytePtr()[r()-1] ^= 0x80; m_state.BytePtr()[r()-1] ^= 0x80;
KeccakF1600(m_state); KeccakF1600(m_state);
memcpy(hash, m_state, size); memcpy(hash, m_state, size);
Restart(); Restart();
} }
NAMESPACE_END NAMESPACE_END

View File

@ -48,8 +48,8 @@ static void KeccakF1600(word64 *state)
word64 Esa, Ese, Esi, Eso, Esu; word64 Esa, Ese, Esi, Eso, Esu;
//copyFromState(A, state) //copyFromState(A, state)
typedef BlockGetAndPut<word64, LittleEndian, true, true> Block; typedef BlockGetAndPut<word64, LittleEndian, true, true> Block;
Block::Get(state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu); Block::Get(state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu);
for( unsigned int round = 0; round < 24; round += 2 ) for( unsigned int round = 0; round < 24; round += 2 )
{ {
@ -245,47 +245,46 @@ static void KeccakF1600(word64 *state)
} }
//copyToState(state, A) //copyToState(state, A)
Block::Put(NULL, state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu); Block::Put(NULL, state)(Aba)(Abe)(Abi)(Abo)(Abu)(Aga)(Age)(Agi)(Ago)(Agu)(Aka)(Ake)(Aki)(Ako)(Aku)(Ama)(Ame)(Ami)(Amo)(Amu)(Asa)(Ase)(Asi)(Aso)(Asu);
} }
} }
void SHA3::Update(const byte *input, size_t length) void SHA3::Update(const byte *input, size_t length)
{ {
CRYPTOPP_ASSERT((input && length) || !(input || length)); CRYPTOPP_ASSERT((input && length) || !(input || length));
if (!length) if (!length) { return; }
return;
size_t spaceLeft; size_t spaceLeft;
while (length >= (spaceLeft = r() - m_counter)) while (length >= (spaceLeft = r() - m_counter))
{ {
if (spaceLeft) if (spaceLeft)
xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft); xorbuf(m_state.BytePtr() + m_counter, input, spaceLeft);
KeccakF1600(m_state); KeccakF1600(m_state);
input += spaceLeft; input += spaceLeft;
length -= spaceLeft; length -= spaceLeft;
m_counter = 0; m_counter = 0;
} }
if (length) if (length)
xorbuf(m_state.BytePtr() + m_counter, input, length); xorbuf(m_state.BytePtr() + m_counter, input, length);
m_counter += (unsigned int)length; m_counter += (unsigned int)length;
} }
void SHA3::Restart() void SHA3::Restart()
{ {
memset(m_state, 0, m_state.SizeInBytes()); memset(m_state, 0, m_state.SizeInBytes());
m_counter = 0; m_counter = 0;
} }
void SHA3::TruncatedFinal(byte *hash, size_t size) void SHA3::TruncatedFinal(byte *hash, size_t size)
{ {
ThrowIfInvalidTruncatedSize(size); ThrowIfInvalidTruncatedSize(size);
m_state.BytePtr()[m_counter] ^= 0x06; m_state.BytePtr()[m_counter] ^= 0x06;
m_state.BytePtr()[r()-1] ^= 0x80; m_state.BytePtr()[r()-1] ^= 0x80;
KeccakF1600(m_state); KeccakF1600(m_state);
memcpy(hash, m_state, size); memcpy(hash, m_state, size);
Restart(); Restart();
} }
NAMESPACE_END NAMESPACE_END