diff options
Diffstat (limited to 'src/lib/hash/sha3/sha3.cpp')
-rw-r--r-- | src/lib/hash/sha3/sha3.cpp | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/lib/hash/sha3/sha3.cpp b/src/lib/hash/sha3/sha3.cpp index 2361d7d5b..f1c769e6b 100644 --- a/src/lib/hash/sha3/sha3.cpp +++ b/src/lib/hash/sha3/sha3.cpp @@ -12,9 +12,9 @@ namespace Botan { //static -void SHA_3::permute(u64bit A[25]) +void SHA_3::permute(uint64_t A[25]) { - static const u64bit RC[24] = { + static const uint64_t RC[24] = { 0x0000000000000001, 0x0000000000008082, 0x800000000000808A, 0x8000000080008000, 0x000000000000808B, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008A, @@ -27,43 +27,43 @@ void SHA_3::permute(u64bit A[25]) for(size_t i = 0; i != 24; ++i) { - const u64bit C0 = A[0] ^ A[5] ^ A[10] ^ A[15] ^ A[20]; - const u64bit C1 = A[1] ^ A[6] ^ A[11] ^ A[16] ^ A[21]; - const u64bit C2 = A[2] ^ A[7] ^ A[12] ^ A[17] ^ A[22]; - const u64bit C3 = A[3] ^ A[8] ^ A[13] ^ A[18] ^ A[23]; - const u64bit C4 = A[4] ^ A[9] ^ A[14] ^ A[19] ^ A[24]; - - const u64bit D0 = rotate_left(C0, 1) ^ C3; - const u64bit D1 = rotate_left(C1, 1) ^ C4; - const u64bit D2 = rotate_left(C2, 1) ^ C0; - const u64bit D3 = rotate_left(C3, 1) ^ C1; - const u64bit D4 = rotate_left(C4, 1) ^ C2; - - const u64bit B00 = A[ 0] ^ D1; - const u64bit B10 = rotate_left(A[ 1] ^ D2, 1); - 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 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); + const uint64_t C0 = A[0] ^ A[5] ^ A[10] ^ A[15] ^ A[20]; + const uint64_t C1 = A[1] ^ A[6] ^ A[11] ^ A[16] ^ A[21]; + const uint64_t C2 = A[2] ^ A[7] ^ A[12] ^ A[17] ^ A[22]; + const uint64_t C3 = A[3] ^ A[8] ^ A[13] ^ A[18] ^ A[23]; + const uint64_t C4 = A[4] ^ A[9] ^ A[14] ^ A[19] ^ A[24]; + + const uint64_t D0 = rotate_left(C0, 1) ^ C3; + const uint64_t D1 = rotate_left(C1, 1) ^ C4; + const uint64_t D2 = rotate_left(C2, 1) ^ C0; + const uint64_t D3 = rotate_left(C3, 1) ^ C1; + const uint64_t D4 = rotate_left(C4, 1) ^ C2; + + const uint64_t B00 = A[ 0] ^ D1; + const uint64_t B10 = rotate_left(A[ 1] ^ D2, 1); + const uint64_t B20 = rotate_left(A[ 2] ^ D3, 62); + const uint64_t B05 = rotate_left(A[ 3] ^ D4, 28); + const uint64_t B15 = rotate_left(A[ 4] ^ D0, 27); + const uint64_t B16 = rotate_left(A[ 5] ^ D1, 36); + const uint64_t B01 = rotate_left(A[ 6] ^ D2, 44); + const uint64_t B11 = rotate_left(A[ 7] ^ D3, 6); + const uint64_t B21 = rotate_left(A[ 8] ^ D4, 55); + const uint64_t B06 = rotate_left(A[ 9] ^ D0, 20); + const uint64_t B07 = rotate_left(A[10] ^ D1, 3); + const uint64_t B17 = rotate_left(A[11] ^ D2, 10); + const uint64_t B02 = rotate_left(A[12] ^ D3, 43); + const uint64_t B12 = rotate_left(A[13] ^ D4, 25); + const uint64_t B22 = rotate_left(A[14] ^ D0, 39); + const uint64_t B23 = rotate_left(A[15] ^ D1, 41); + const uint64_t B08 = rotate_left(A[16] ^ D2, 45); + const uint64_t B18 = rotate_left(A[17] ^ D3, 15); + const uint64_t B03 = rotate_left(A[18] ^ D4, 21); + const uint64_t B13 = rotate_left(A[19] ^ D0, 8); + const uint64_t B14 = rotate_left(A[20] ^ D1, 18); + const uint64_t B24 = rotate_left(A[21] ^ D2, 2); + const uint64_t B09 = rotate_left(A[22] ^ D3, 61); + const uint64_t B19 = rotate_left(A[23] ^ D4, 56); + const uint64_t B04 = rotate_left(A[24] ^ D0, 14); A[ 0] = B00 ^ (~B01 & B02); A[ 1] = B01 ^ (~B02 & B03); @@ -128,7 +128,7 @@ void SHA_3::clear() //static size_t SHA_3::absorb(size_t bitrate, secure_vector<uint64_t>& S, size_t S_pos, - const byte input[], size_t length) + const uint8_t input[], size_t length) { while(length > 0) { @@ -138,7 +138,7 @@ size_t SHA_3::absorb(size_t bitrate, while(to_take && S_pos % 8) { - S[S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (S_pos % 8)); + S[S_pos / 8] ^= static_cast<uint64_t>(input[0]) << (8 * (S_pos % 8)); ++S_pos; ++input; @@ -147,7 +147,7 @@ size_t SHA_3::absorb(size_t bitrate, while(to_take && to_take % 8 == 0) { - S[S_pos / 8] ^= load_le<u64bit>(input, 0); + S[S_pos / 8] ^= load_le<uint64_t>(input, 0); S_pos += 8; input += 8; to_take -= 8; @@ -155,7 +155,7 @@ size_t SHA_3::absorb(size_t bitrate, while(to_take) { - S[S_pos / 8] ^= static_cast<u64bit>(input[0]) << (8 * (S_pos % 8)); + S[S_pos / 8] ^= static_cast<uint64_t>(input[0]) << (8 * (S_pos % 8)); ++S_pos; ++input; @@ -175,7 +175,7 @@ size_t SHA_3::absorb(size_t bitrate, //static void SHA_3::expand(size_t bitrate, secure_vector<uint64_t>& S, - byte output[], size_t output_length) + uint8_t output[], size_t output_length) { BOTAN_ARG_CHECK(bitrate % 8 == 0); @@ -200,14 +200,14 @@ void SHA_3::expand(size_t bitrate, } } -void SHA_3::add_data(const byte input[], size_t length) +void SHA_3::add_data(const uint8_t input[], size_t length) { m_S_pos = SHA_3::absorb(m_bitrate, m_S, m_S_pos, input, length); } -void SHA_3::final_result(byte output[]) +void SHA_3::final_result(uint8_t output[]) { - std::vector<byte> padding(m_bitrate / 8 - m_S_pos); + std::vector<uint8_t> padding(m_bitrate / 8 - m_S_pos); padding[0] = 0x06; padding[padding.size()-1] |= 0x80; |