8 #include <botan/keccak.h>     9 #include <botan/loadstor.h>    10 #include <botan/parsing.h>    11 #include <botan/exceptn.h>    12 #include <botan/rotate.h>    13 #include <botan/internal/xor_buf.h>    19 void keccak_f_1600(
u64bit A[25])
    21    static const u64bit RC[24] = {
    22       0x0000000000000001, 0x0000000000008082, 0x800000000000808A,
    23       0x8000000080008000, 0x000000000000808B, 0x0000000080000001,
    24       0x8000000080008081, 0x8000000000008009, 0x000000000000008A,
    25       0x0000000000000088, 0x0000000080008009, 0x000000008000000A,
    26       0x000000008000808B, 0x800000000000008B, 0x8000000000008089,
    27       0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
    28       0x000000000000800A, 0x800000008000000A, 0x8000000080008081,
    29       0x8000000000008080, 0x0000000080000001, 0x8000000080008008
    32    for(
size_t i = 0; i != 24; ++i)
    34       const u64bit C0 = A[0] ^ A[5] ^ A[10] ^ A[15] ^ A[20];
    35       const u64bit C1 = A[1] ^ A[6] ^ A[11] ^ A[16] ^ A[21];
    36       const u64bit C2 = A[2] ^ A[7] ^ A[12] ^ A[17] ^ A[22];
    37       const u64bit C3 = A[3] ^ A[8] ^ A[13] ^ A[18] ^ A[23];
    38       const u64bit C4 = A[4] ^ A[9] ^ A[14] ^ A[19] ^ A[24];
    46       const u64bit B00 = A[ 0] ^ D1;
    72       A[ 0] = B00 ^ (~B01 & B02);
    73       A[ 1] = B01 ^ (~B02 & B03);
    74       A[ 2] = B02 ^ (~B03 & B04);
    75       A[ 3] = B03 ^ (~B04 & B00);
    76       A[ 4] = B04 ^ (~B00 & B01);
    77       A[ 5] = B05 ^ (~B06 & B07);
    78       A[ 6] = B06 ^ (~B07 & B08);
    79       A[ 7] = B07 ^ (~B08 & B09);
    80       A[ 8] = B08 ^ (~B09 & B05);
    81       A[ 9] = B09 ^ (~B05 & B06);
    82       A[10] = B10 ^ (~B11 & B12);
    83       A[11] = B11 ^ (~B12 & B13);
    84       A[12] = B12 ^ (~B13 & B14);
    85       A[13] = B13 ^ (~B14 & B10);
    86       A[14] = B14 ^ (~B10 & B11);
    87       A[15] = B15 ^ (~B16 & B17);
    88       A[16] = B16 ^ (~B17 & B18);
    89       A[17] = B17 ^ (~B18 & B19);
    90       A[18] = B18 ^ (~B19 & B15);
    91       A[19] = B19 ^ (~B15 & B16);
    92       A[20] = B20 ^ (~B21 & B22);
    93       A[21] = B21 ^ (~B22 & B23);
    94       A[22] = B22 ^ (~B23 & B24);
    95       A[23] = B23 ^ (~B24 & B20);
    96       A[24] = B24 ^ (~B20 & B21);
   105    output_bits(output_bits),
   106    bitrate(1600 - 2*output_bits),
   112    if(output_bits != 224 && output_bits != 256 &&
   113       output_bits != 384 && output_bits != 512)
   120    return "Keccak-1600(" + 
to_string(output_bits) + 
")";
   134 void Keccak_1600::add_data(
const byte input[], 
size_t length)
   141       size_t to_take = 
std::min(length, bitrate / 8 - S_pos);
   145       while(to_take && S_pos % 8)
   147          S[S_pos / 8] ^= 
static_cast<u64bit>(input[0]) << (8 * (S_pos % 8));
   154       while(to_take && to_take % 8 == 0)
   164          S[S_pos / 8] ^= 
static_cast<u64bit>(input[0]) << (8 * (S_pos % 8));
   171       if(S_pos == bitrate / 8)
   173          keccak_f_1600(&S[0]);
   179 void Keccak_1600::final_result(
byte output[])
   184    padding[padding.
size()-1] |= 0x80;
   186    add_data(padding, padding.
size());
   192    for(
size_t i = 0; i != output_bits/8; ++i)
   193       output[i] = 
get_byte(7 - (i % 8), S[i/8]);
 
HashFunction * clone() const
T rotate_left(T input, size_t rot)
std::invalid_argument Invalid_Argument
byte get_byte(size_t byte_num, T input)
unsigned long long u64bit
std::string to_string(u64bit n, size_t min_len)
void zeroise(MemoryRegion< T > &vec)
Keccak_1600(size_t output_bits=512)
u64bit load_le< u64bit >(const byte in[], size_t off)