diff options
Diffstat (limited to 'src/lib/hash/keccak/keccak.cpp')
-rw-r--r-- | src/lib/hash/keccak/keccak.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/src/lib/hash/keccak/keccak.cpp b/src/lib/hash/keccak/keccak.cpp index 39d0c822b..44297dcef 100644 --- a/src/lib/hash/keccak/keccak.cpp +++ b/src/lib/hash/keccak/keccak.cpp @@ -41,30 +41,30 @@ void keccak_f_1600(u64bit A[25]) const u64bit D4 = rotate_left(C4, 1) ^ C2; const u64bit B00 = A[ 0] ^ D1; - const u64bit B01 = rotate_left(A[ 6] ^ D2, 44); - const u64bit B02 = rotate_left(A[12] ^ D3, 43); - const u64bit B03 = rotate_left(A[18] ^ D4, 21); - const u64bit B04 = rotate_left(A[24] ^ D0, 14); - const u64bit B05 = rotate_left(A[ 3] ^ D4, 28); - const u64bit B06 = rotate_left(A[ 9] ^ D0, 20); - const u64bit B07 = rotate_left(A[10] ^ D1, 3); - const u64bit B08 = rotate_left(A[16] ^ D2, 45); - const u64bit B09 = rotate_left(A[22] ^ D3, 61); const u64bit B10 = rotate_left(A[ 1] ^ D2, 1); - const u64bit B11 = rotate_left(A[ 7] ^ D3, 6); - const u64bit B12 = rotate_left(A[13] ^ D4, 25); - const u64bit B13 = rotate_left(A[19] ^ D0, 8); - const u64bit B14 = rotate_left(A[20] ^ D1, 18); + const u64bit B20 = rotate_left(A[ 2] ^ D3, 62); + const u64bit B05 = rotate_left(A[ 3] ^ D4, 28); const u64bit B15 = rotate_left(A[ 4] ^ D0, 27); const u64bit B16 = rotate_left(A[ 5] ^ D1, 36); - const u64bit B17 = rotate_left(A[11] ^ D2, 10); - const u64bit B18 = rotate_left(A[17] ^ D3, 15); - const u64bit B19 = rotate_left(A[23] ^ D4, 56); - const u64bit B20 = rotate_left(A[ 2] ^ D3, 62); + const u64bit B01 = rotate_left(A[ 6] ^ D2, 44); + const u64bit B11 = rotate_left(A[ 7] ^ D3, 6); const u64bit B21 = rotate_left(A[ 8] ^ D4, 55); + const u64bit B06 = rotate_left(A[ 9] ^ D0, 20); + const u64bit B07 = rotate_left(A[10] ^ D1, 3); + const u64bit B17 = rotate_left(A[11] ^ D2, 10); + const u64bit B02 = rotate_left(A[12] ^ D3, 43); + const u64bit B12 = rotate_left(A[13] ^ D4, 25); const u64bit B22 = rotate_left(A[14] ^ D0, 39); const u64bit B23 = rotate_left(A[15] ^ D1, 41); + const u64bit B08 = rotate_left(A[16] ^ D2, 45); + const u64bit B18 = rotate_left(A[17] ^ D3, 15); + const u64bit B03 = rotate_left(A[18] ^ D4, 21); + const u64bit B13 = rotate_left(A[19] ^ D0, 8); + const u64bit B14 = rotate_left(A[20] ^ D1, 18); const u64bit B24 = rotate_left(A[21] ^ D2, 2); + const u64bit B09 = rotate_left(A[22] ^ D3, 61); + const u64bit B19 = rotate_left(A[23] ^ D4, 56); + const u64bit B04 = rotate_left(A[24] ^ D0, 14); A[ 0] = B00 ^ (~B01 & B02); A[ 1] = B01 ^ (~B02 & B03); @@ -99,10 +99,10 @@ void keccak_f_1600(u64bit A[25]) } Keccak_1600::Keccak_1600(size_t output_bits) : - output_bits(output_bits), - bitrate(1600 - 2*output_bits), - S(25), - S_pos(0) + m_output_bits(output_bits), + m_bitrate(1600 - 2*output_bits), + m_S(25), + m_S_pos(0) { // We only support the parameters for the SHA-3 proposal @@ -114,18 +114,18 @@ Keccak_1600::Keccak_1600(size_t output_bits) : std::string Keccak_1600::name() const { - return "Keccak-1600(" + std::to_string(output_bits) + ")"; + return "Keccak-1600(" + std::to_string(m_output_bits) + ")"; } HashFunction* Keccak_1600::clone() const { - return new Keccak_1600(output_bits); + return new Keccak_1600(m_output_bits); } void Keccak_1600::clear() { - zeroise(S); - S_pos = 0; + zeroise(m_S); + m_S_pos = 0; } void Keccak_1600::add_data(const byte input[], size_t length) @@ -135,47 +135,47 @@ void Keccak_1600::add_data(const byte input[], size_t length) while(length) { - size_t to_take = std::min(length, bitrate / 8 - S_pos); + size_t to_take = std::min(length, m_bitrate / 8 - m_S_pos); length -= to_take; - while(to_take && S_pos % 8) + while(to_take && m_S_pos % 8) { - S[S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (S_pos % 8)); + m_S[m_S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (m_S_pos % 8)); - ++S_pos; + ++m_S_pos; ++input; --to_take; } while(to_take && to_take % 8 == 0) { - S[S_pos / 8] ^= load_le<u64bit>(input, 0); - S_pos += 8; + m_S[m_S_pos / 8] ^= load_le<u64bit>(input, 0); + m_S_pos += 8; input += 8; to_take -= 8; } while(to_take) { - S[S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (S_pos % 8)); + m_S[m_S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (m_S_pos % 8)); - ++S_pos; + ++m_S_pos; ++input; --to_take; } - if(S_pos == bitrate / 8) + if(m_S_pos == m_bitrate / 8) { - keccak_f_1600(S.data()); - S_pos = 0; + keccak_f_1600(m_S.data()); + m_S_pos = 0; } } } void Keccak_1600::final_result(byte output[]) { - std::vector<byte> padding(bitrate / 8 - S_pos); + std::vector<byte> padding(m_bitrate / 8 - m_S_pos); padding[0] = 0x01; padding[padding.size()-1] |= 0x80; @@ -186,8 +186,8 @@ void Keccak_1600::final_result(byte output[]) * We never have to run the permutation again because we only support * limited output lengths */ - for(size_t i = 0; i != output_bits/8; ++i) - output[i] = get_byte(7 - (i % 8), S[i/8]); + for(size_t i = 0; i != m_output_bits/8; ++i) + output[i] = get_byte(7 - (i % 8), m_S[i/8]); clear(); } |