1 /******************************************************************
2 ** Header File for the Reference Implementation of Twister
4 ** Author: Ewan Fleischmann <ewan.fleischmann@uni-weimar.de> 2008
6 ** This algorithm and source code is released into the public domain.
8 *******************************************************************/
10 #ifndef TWISTER_REF_H_
11 #define TWISTER_REF_H_
15 #define MIN(a,b) ((a)>(b)?(b):(a))
16 /* state matrix has size of 8x8 BYTES i.e. 8 rows and 8 columns*/
17 #define NUMROWSCOLUMNS 8
18 #define STATESIZE NUMROWSCOLUMNS * NUMROWSCOLUMNS
20 /* blocksize in BITS, i.e. size of an input message block for a compression function call*/
23 /* unit64 def for ANSIC/GNUC <-> MSVC */
27 typedef unsigned __int64 uint64_t;
30 /* multiplication in F_256 */
31 #define MULT(a,b) (multab[a-1][b])
33 /* NIST requirements definitions */
34 typedef unsigned char BitSequence;
35 typedef uint64_t DataLength;
36 typedef enum {SUCCESS=0, FAIL=1, BAD_HASHBITLEN=2 } HashReturn;
37 typedef enum {FULL = 0, NOT_FULL = 1 } INTERMEDIATE_RESULT;
40 /* statematrix[Y][X] */
41 unsigned char hs_State[NUMROWSCOLUMNS][NUMROWSCOLUMNS];
43 /* matrix for checksum */
44 unsigned char hs_Checksum[NUMROWSCOLUMNS][NUMROWSCOLUMNS];
46 /* Processed message bits */
47 DataLength hs_ProcessedMsgLen;
49 /* Unprocessed message block */
50 BitSequence hs_Data[STATESIZE];
52 /* size of data hs_Data, in bits*/
53 uint64_t hs_DataBitLen;
55 /* Twist counter, prevents slide attacks, counts the number of twist operations */
58 /* output hash bit length, in bits */
59 uint64_t hs_HashBitLen;
64 /******************************************************************/
65 /************************* N I S T A P I ***********************/
66 /******************************************************************/
68 /* Initiate Twister */
69 HashReturn Init(hashState *state, int hashbitlen);
71 /* Process the supplied data */
72 HashReturn Update(hashState *state, const BitSequence *data,
73 DataLength databitlen);
75 /* Perform any post processing and output filtering */
76 HashReturn Final(hashState *state, BitSequence *hashval);
78 /* Hash the supplied data and provie the resulting hash value */
79 HashReturn Hash(int hashbitlen, const BitSequence *data,
80 DataLength databitlen, BitSequence *hashval);
83 /* only for testing */
84 INTERMEDIATE_RESULT fill_intermediate_state( hashState *state, const BitSequence *data, DataLength *databitlen, DataLength *processed );
85 void twist( hashState *state, uint64_t *data );
86 void twist_mini_round( hashState *state );
87 void checksum( hashState *state, int col );
90 #endif /* TWISTER_REF_H_ */