/* The eXtended Keccak Code Package (XKCP) https://github.com/XKCP/XKCP The Keccak-p permutations, designed by Guido Bertoni, Joan Daemen, Michaƫl Peeters and Gilles Van Assche. Implementation by Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to the Keccak Team website: https://keccak.team/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ --- This file implements Keccak-p[200] in a SnP-compatible way. Please refer to SnP-documentation.h for more details. This implementation comes with KeccakP-200-SnP.h in the same folder. Please refer to LowLevel.build for the exact list of other files it must be combined with. */ #include #include #include #include "KeccakP-200-SnP.h" /* #define DIVISION_INSTRUCTION /* comment if no division instruction or more compact when not using division */ #define UNROLL_CHILOOP /* comment if more compact using for loop */ typedef uint_fast8_t tSmallUInt; typedef uint8_t tKeccakLane; #define ROL8(a, offset) (uint8_t)((((uint8_t)a) << (offset&7)) ^ (((uint8_t)a) >> (8-(offset&7)))) const uint8_t KeccakP200_RotationConstants[25] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 }; const uint8_t KeccakP200_PiLane[25] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 }; #if defined(DIVISION_INSTRUCTION) #define MOD5(argValue) ((argValue) % 5) #else const uint8_t KeccakP200_Mod5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; #define MOD5(argValue) KeccakP200_Mod5[argValue] #endif const uint8_t KeccakF200_RoundConstants[] = { 0x01, 0x82, 0x8a, 0x00, 0x8b, 0x01, 0x81, 0x09, 0x8a, 0x88, 0x09, 0x0a, 0x8b, 0x8b, 0x89, 0x03, 0x02, 0x80 }; /* ---------------------------------------------------------------- */ void KeccakP200_Initialize(void *argState) { memset( argState, 0, 25 * sizeof(tKeccakLane) ); } /* ---------------------------------------------------------------- */ void KeccakP200_AddByte(void *argState, unsigned char byte, unsigned int offset) { ((tKeccakLane*)argState)[offset] ^= byte; } /* ---------------------------------------------------------------- */ void KeccakP200_AddBytes(void *argState, const unsigned char *data, unsigned int offset, unsigned int length) { tSmallUInt i; tKeccakLane * state = (tKeccakLane*)argState + offset; for(i=0; i