]> git.cryptolib.org Git - avr-crypto-lib.git/blob - twister/twister_ref.h
adjusting test system uart reference
[avr-crypto-lib.git] / twister / twister_ref.h
1 /******************************************************************
2  ** Header File for the Reference Implementation of Twister
3  **
4  ** Author: Ewan Fleischmann <ewan.fleischmann@uni-weimar.de> 2008
5  **
6  ** This algorithm and source code is released into the public domain.
7  **
8  *******************************************************************/
9
10 #ifndef TWISTER_REF_H_
11 #define TWISTER_REF_H_
12
13 #define DEBUG
14
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
19
20 /* blocksize in BITS, i.e. size of an input message block for a compression function call*/
21 #define BLOCKSIZE 512
22
23 /* unit64 def for ANSIC/GNUC <-> MSVC */
24 #ifdef __GNUC__
25 #include <stdint.h>
26 #else
27 typedef unsigned __int64 uint64_t;
28 #endif
29
30 /* multiplication in F_256 */
31 #define MULT(a,b) (multab[a-1][b])
32
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;
38
39 typedef struct {
40   /* statematrix[Y][X] */ 
41   unsigned char hs_State[NUMROWSCOLUMNS][NUMROWSCOLUMNS];
42
43   /* matrix for checksum */ 
44   unsigned char hs_Checksum[NUMROWSCOLUMNS][NUMROWSCOLUMNS];
45
46   /* Processed message bits */
47   DataLength hs_ProcessedMsgLen;
48
49   /* Unprocessed message block */
50   BitSequence hs_Data[STATESIZE];    
51
52   /* size of data hs_Data, in bits*/
53   uint64_t hs_DataBitLen;
54
55   /* Twist counter, prevents slide attacks, counts the number of twist operations */
56   uint64_t hs_Counter;
57
58   /* output hash bit length, in bits */
59   uint64_t hs_HashBitLen;
60
61 } hashState;
62
63
64 /******************************************************************/
65 /************************* N I S T    A P I ***********************/
66 /******************************************************************/
67
68 /* Initiate Twister */
69 HashReturn Init(hashState *state, int hashbitlen);
70
71 /* Process the supplied data */
72 HashReturn Update(hashState *state, const BitSequence *data, 
73                   DataLength databitlen);
74
75 /* Perform any post processing and output filtering */
76 HashReturn Final(hashState *state, BitSequence *hashval);
77
78 /* Hash the supplied data and provie the resulting hash value */
79 HashReturn Hash(int hashbitlen, const BitSequence *data,
80                 DataLength databitlen, BitSequence *hashval); 
81
82
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 );
88
89
90 #endif /* TWISTER_REF_H_ */