]> git.cryptolib.org Git - avr-crypto-lib.git/blob - grain_h_lutgen.c
insereated GPLv3 stub
[avr-crypto-lib.git] / grain_h_lutgen.c
1 /**
2  * 
3  * author: Daniel Otte
4  * email:  daniel.otte@rub.de
5  * license: GPLv3
6  *
7  * this program generate a lookuptable for the h-function in grain 
8  */
9
10 #include <stdint.h>
11 #include <stdio.h>
12
13 #define X(i) ((x)>>((i)))
14 uint8_t h(uint8_t x){
15         uint8_t h;
16         
17         h = (X(1)) ^ (X(4)) ^ 
18             (X(0)&X(3)) ^ (X(2)&X(3)) ^ (X(3)&X(4)) ^ 
19             (X(0)&X(1)&X(2)) ^ (X(0)&X(2)&X(3)) ^ (X(0)&X(2)&X(4)) ^ 
20             (X(1)&X(2)&X(4)) ^ (X(2)&X(3)&X(4)) ;
21         
22         return h&1;
23 }
24
25 int main(void){
26         uint8_t i; 
27         uint32_t lut;
28         puts(
29         "/* \n"
30         " * author: Daniel Otte \n"
31         " * email:  daniel.otte@rub.de  \n"
32         " * license: GPLv3 \n"
33         " *  \n"
34         " * this program generate a lookuptable for the h-function in grain  \n"
35         " *  \n"
36         " */ \n");
37         puts("/* \n"
38              " * x0 x1 x2 x3 x4 - h");
39         
40         for(i=0; i<0x20; ++i){
41                 printf(" *  %c  %c  %c  %c  %c - %c\n",
42                         (i&0x01)?'1':'0',
43                         (i&0x02)?'1':'0',
44                         (i&0x04)?'1':'0',
45                         (i&0x08)?'1':'0',
46                         (i&0x10)?'1':'0',
47                         (h(i))?'1':'0' );
48                         lut >>=1;
49                         lut |= h(i)?0x80000000:0x00000000;
50                         if(i%4==3){     
51                                 puts(" * --");
52                         }
53         }
54         puts(" */\n");
55         printf(" uint8_t lut[4]= {0x%2.2X, 0x%2.2X, 0x%2.2X, 0x%2.2X} \n",
56                 lut&0xFF, (lut>>8)&0xFF, (lut>>16)&0xFF, (lut>>24)&0xFF);
57                 
58         return 0; 
59 }
60