53#define SHA3Blocksize 64
54#define SHA3Digestsize 64
55#define SHA3Index(x,y) (((x) % 5)+5*((y) % 5))
57#define SHA3MaximumRate 1536
58#define SHA3PermutationSize 1600
59#define SHA3RotateLeft(x,offset) ((offset) != 0 ? ((((WizardSizeType) (x)) << \
60 offset) ^ (((WizardSizeType) (x)) >> (64-(offset)))) : (x))
143 (void) memset(sha_info,0,
sizeof(*sha_info));
145 switch (sha_info->
hash)
180 sha_info->
timestamp=time((time_t *) NULL);
211 assert(sha_info != (
SHA3Info *) NULL);
255 for (j=0; j< (64/8); j++)
261 unsigned char *bytes)
271 for (j=0; j < (64/8); j++)
272 bytes[i*(64/8)+j]=(
unsigned char) ((words[i] >> (8*j)) & 0xFF);
296 for (x=0; x < 5; x++)
299 for (y=0; y < 5; y++)
302 for (x=0; x < 5; x++)
304 for (x=0; x < 5; x++)
305 for (y=0; y < 5; y++)
310 for (x=0; x < 5; x++)
311 for (y=0; y < 5; y++)
317 for (x=0; x < 5; x++)
318 for (y=0; y < 5; y++)
320 for (x=0; x < 5; x++)
321 for (y=0; y < 5; y++)
326 for (y=0; y < 5; y++)
328 for (x=0; x < 5; x++)
342 unsigned char *bytes)
358 const unsigned char *message,
const size_t length,
unsigned char *state)
363 for (i=0; i < (ssize_t) length; i++)
364 state[i]^=message[i];
370 switch (sha_info->
rate)
428 sha_info->
message[(sha_info->
rate-1)/8]|=1 << ((sha_info->
rate-1) % 8);
436 unsigned char *output)
449 if ((length % 8) != 0)
451 for (i=0; i < (ssize_t) length; i+=bits)
460 if (bits > (length-i))
491 assert(sha_info != (
SHA3Info *) NULL);
493 clone_info=(*sha_info);
494 (void) memset(digest,0,
sizeof(*digest));
500 for (i=0; i < (ssize_t) sha_info->
digestsize; i++)
626 result=((*byte) & 0x01) != 0;
627 if (((*
byte) & 0x80) != 0)
628 (*
byte)=((*byte) << 1) ^ 0x71;
652 for (j=0; j < 7; j++)
654 offset=(ssize_t) (1 << j)-1;
673 for (i=0; i < 24; i++)
678 sha_info->
rho[
SHA3Index(x,y)]=(
unsigned int) (((i+1)*(i+2)/2) % 64);
686 const unsigned int rate,
const unsigned int capacity)
688 if (rate+capacity != 1600)
690 if ((rate <= 0) || (rate >= 1600) || ((rate % 64) != 0))
702 sha_info->
length=capacity/2;
712 assert(sha_info != (
SHA3Info *) NULL);
714 switch (sha_info->
hash)
777 const unsigned char *message,
const size_t length)
797 for (i=0; i < (ssize_t) length; )
800 (i > (ssize_t) (length-sha_info->
rate)))
802 bits=(
unsigned int) (length-i);
817 mask=(
unsigned char) ((1 <<
byte)-1);
828 blocks=(size_t) ((length-i)/sha_info->
rate);
830 switch (sha_info->
rate)
834 for (j=0; j < (ssize_t) blocks; j++)
843 for (j=0; j < (ssize_t) blocks; j++)
852 for (j=0; j < (ssize_t) blocks; j++)
861 for (j=0; j < (ssize_t) blocks; j++)
870 for (j=0; j < (ssize_t) blocks; j++)
879 for (j=0; j < (ssize_t) blocks; j++)
888 for (j=0; j < (ssize_t) blocks; j++)
897 i+=blocks*sha_info->
rate;
909 assert(sha_info != (
SHA3Info *) NULL);
#define WizardAssert(domain, predicate)
#define ThrowWizardFatalError(domain, error)
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
#define GetWizardModule()
WizardExport void * AcquireWizardMemory(const size_t size)
WizardExport void * RelinquishWizardMemory(void *memory)
WizardExport const StringInfo * GetSHA3Digest(const SHA3Info *sha_info)
static void SHA3InitializeRho(SHA3Info *sha_info)
static WizardBooleanType Squeeze(SHA3Info *sha_info, const size_t length, unsigned char *output)
#define SHA3PermutationSize
#define SHA3RotateLeft(x, offset)
static int LFSR86540(unsigned char *byte)
static void SHA3Permutation(const SHA3Info *sha_info, unsigned char *bytes)
WizardExport WizardBooleanType InitializeSHA3(SHA3Info *sha_info)
static void SHA3PermutationOnWords(const SHA3Info *sha_info, WizardSizeType *state)
static WizardBooleanType Absorb(SHA3Info *sha_info, const unsigned char *message, const size_t length)
static void PadAndSwitchToSqueezingPhase(SHA3Info *sha_info)
static void ConvertWordsToBytes(const WizardSizeType *words, unsigned char *bytes)
static WizardBooleanType InitializeSponge(SHA3Info *sha_info, const unsigned int rate, const unsigned int capacity)
static void SHA3InitializeRoundConstants(SHA3Info *sha_info)
static void AbsorbQueue(SHA3Info *sha_info)
static void SHA3PermutationAfterXor(const SHA3Info *sha_info, const unsigned char *message, const size_t length, unsigned char *state)
WizardExport WizardBooleanType UpdateSHA3(SHA3Info *sha_info, const StringInfo *message)
WizardExport SHA3Info * DestroySHA3Info(SHA3Info *sha_info)
WizardExport unsigned int GetSHA3Blocksize(const SHA3Info *sha_info)
WizardExport SHA3Info * AcquireSHA3Info(const HashType hash)
static void ConvertBytesToWords(const unsigned char *bytes, WizardSizeType *words)
WizardExport WizardBooleanType FinalizeSHA3(SHA3Info *sha_info)
WizardExport unsigned int GetSHA3Digestsize(const SHA3Info *sha_info)
WizardExport size_t GetStringInfoLength(const StringInfo *string_info)
WizardExport StringInfo * AcquireStringInfo(const size_t length)
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
WizardExport StringInfo * DestroyStringInfo(StringInfo *string_info)
unsigned char state[SHA3PermutationSize/8]
unsigned char message[SHA3MaximumRate/8]
WizardBooleanType lsb_first
WizardSizeType rounds[SHA3Rounds]
unsigned int squeeze_bits
unsigned int bits_in_queue
WizardBooleanType squeeze
unsigned int rho[SHA3Lanes]