X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=inline;f=twister_ref.h;fp=twister_ref.h;h=1a5e05a650154905428a2d3c326f73074b814749;hb=288c82e97b3c37666b1c11475b45a956b3e5e8e0;hp=0000000000000000000000000000000000000000;hpb=0076b72ccd398bf7571c5144ba36eda8a24f6c70;p=avr-crypto-lib.git diff --git a/twister_ref.h b/twister_ref.h new file mode 100644 index 0000000..1a5e05a --- /dev/null +++ b/twister_ref.h @@ -0,0 +1,90 @@ +/****************************************************************** + ** Header File for the Reference Implementation of Twister + ** + ** Author: Ewan Fleischmann 2008 + ** + ** This algorithm and source code is released into the public domain. + ** + *******************************************************************/ + +#ifndef TWISTER_REF_H_ +#define TWISTER_REF_H_ + +#define DEBUG + +#define MIN(a,b) ((a)>(b)?(b):(a)) +/* state matrix has size of 8x8 BYTES i.e. 8 rows and 8 columns*/ +#define NUMROWSCOLUMNS 8 +#define STATESIZE NUMROWSCOLUMNS * NUMROWSCOLUMNS + +/* blocksize in BITS, i.e. size of an input message block for a compression function call*/ +#define BLOCKSIZE 512 + +/* unit64 def for ANSIC/GNUC <-> MSVC */ +#ifdef __GNUC__ +#include +#else +typedef unsigned __int64 uint64_t; +#endif + +/* multiplication in F_256 */ +#define MULT(a,b) (multab[a-1][b]) + +/* NIST requirements definitions */ +typedef unsigned char BitSequence; +typedef uint64_t DataLength; +typedef enum {SUCCESS=0, FAIL=1, BAD_HASHBITLEN=2 } HashReturn; +typedef enum {FULL = 0, NOT_FULL = 1 } INTERMEDIATE_RESULT; + +typedef struct { + /* statematrix[Y][X] */ + unsigned char hs_State[NUMROWSCOLUMNS][NUMROWSCOLUMNS]; + + /* matrix for checksum */ + unsigned char hs_Checksum[NUMROWSCOLUMNS][NUMROWSCOLUMNS]; + + /* Processed message bits */ + DataLength hs_ProcessedMsgLen; + + /* Unprocessed message block */ + BitSequence hs_Data[STATESIZE]; + + /* size of data hs_Data, in bits*/ + uint64_t hs_DataBitLen; + + /* Twist counter, prevents slide attacks, counts the number of twist operations */ + uint64_t hs_Counter; + + /* output hash bit length, in bits */ + uint64_t hs_HashBitLen; + +} hashState; + + +/******************************************************************/ +/************************* N I S T A P I ***********************/ +/******************************************************************/ + +/* Initiate Twister */ +HashReturn Init(hashState *state, int hashbitlen); + +/* Process the supplied data */ +HashReturn Update(hashState *state, const BitSequence *data, + DataLength databitlen); + +/* Perform any post processing and output filtering */ +HashReturn Final(hashState *state, BitSequence *hashval); + +/* Hash the supplied data and provie the resulting hash value */ +HashReturn Hash(int hashbitlen, const BitSequence *data, + DataLength databitlen, BitSequence *hashval); + + +/* only for testing */ +INTERMEDIATE_RESULT fill_intermediate_state( hashState *state, const BitSequence *data, DataLength *databitlen, DataLength *processed ); +void twist( hashState *state, uint64_t *data ); +void twist_mini_round( hashState *state ); +void checksum( hashState *state, int col ); + + +#endif /* TWISTER_REF_H_ */