]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-mickey128-test.c
fixing some decryption bugs in GCM128
[avr-crypto-lib.git] / test_src / main-mickey128-test.c
1 /*
2  * Mickey128 test-suit
3  * 
4 */
5
6
7 #include "main-test-common.h"
8
9 #include "mickey128.h"
10 #include "scal_mickey128.h"
11 #include "scal-basic.h"
12 #include "scal-nessie.h"
13
14 char *algo_name = "Mickey128";
15
16 /*****************************************************************************
17  *  additional validation-functions                                                                                      *
18  *****************************************************************************/
19
20 void testrun_nessie_mickey128(void){
21         scal_nessie_set_estream(1);
22         scal_nessie_run(&mickey128_desc);
23 }
24
25 void testrun_ref_mickey128(void){
26         uint8_t key[4][16] ={
27                                   { 0x12, 0x34, 0x56, 0x78, 
28                                 0x9a, 0xbc, 0xde, 0xf0, 
29                                 0x01, 0x23, 0x45, 0x67, 
30                                 0x89, 0xab, 0xcd, 0xef},
31                               { 0xf1, 0x1a, 0x56, 0x27, 
32                                 0xce, 0x43, 0xb6, 0x1f, 
33                                 0x89, 0x12, 0x29, 0x94, 
34                                 0x86, 0x09, 0x44, 0x86},
35                               { 0x3b, 0x80, 0xfc, 0x8c, 
36                                 0x47, 0x5f, 0xc2, 0x70, 
37                                 0xfa, 0x26, 0xb4, 0x70, 
38                                 0x64, 0xb3, 0x2d, 0x33},
39                                                   { 0x82, 0xac, 0xb3, 0x8c,
40                                                     0x5d, 0x7a, 0x3c, 0x78,
41                                                         0xd9, 0x8f, 0x15, 0x3c,
42                                                         0xa3, 0xf9, 0xde, 0x7c} };
43         uint8_t iv_1[] = {0x21, 0x43, 0x65, 0x87};
44         uint8_t iv_2[] = {0x9c, 0x53, 0x2f, 0x8a, 
45                           0xc3, 0xea, 0x4b, 0x2e, 
46                           0xa0, 0xf5, 0x96, 0x40, 
47                           0x30, 0x83, 0x77, 0xcc};
48         uint8_t data[16];
49         uint8_t i;
50         mickey128_ctx_t ctx;
51         cli_putstr_P(PSTR("\r\n-=Reference test=-\r\n"));
52         
53         cli_putstr_P(PSTR("Test 1:\r\n key:    "));
54         cli_hexdump(key[0], 16);
55         cli_putstr_P(PSTR("\r\n iv:     "));
56         cli_hexdump(iv_1, 4);
57         mickey128_init(&(key[0][0]), 128, iv_1, 4*8, &ctx);
58         for(i=0; i<16; ++i){
59                 data[i] = mickey128_getbyte(&ctx);
60         }
61         cli_putstr_P(PSTR("\r\n stream: "));
62         cli_hexdump(data, 16);
63         
64         cli_putstr_P(PSTR("\r\n\r\nTest 2:\r\n key:    "));
65         cli_hexdump(key[1], 16);
66         cli_putstr_P(PSTR("\r\n iv:     "));
67         cli_hexdump(iv_2, 16);
68         mickey128_init(key[1], 128, iv_2, 16*8, &ctx);
69         for(i=0; i<16; ++i){
70                 data[i] = mickey128_getbyte(&ctx);
71         }
72         cli_putstr_P(PSTR("\r\n stream: "));
73         cli_hexdump(data, 16);
74         
75         cli_putstr_P(PSTR("\r\n\r\nTest 3:\r\n key:    "));
76         cli_hexdump(key[2], 16);
77         cli_putstr_P(PSTR("\r\n iv:     "));
78         mickey128_init(key[2], 128, NULL, 0, &ctx);
79         for(i=0; i<16; ++i){
80                 data[i] = mickey128_getbyte(&ctx);
81         }
82         cli_putstr_P(PSTR("\r\n stream: "));
83         cli_hexdump(data, 16);
84
85         cli_putstr_P(PSTR("\r\n\r\nIteration test:\r\n key:    "));
86         cli_hexdump(key[3], 16);
87         mickey128_init(key[3], 128, NULL, 0, &ctx);
88         uint16_t j;
89         for(j=0; j<1000; ++j){
90                 for(i=0; i<16; ++i)
91                         key[0][i] = mickey128_getbyte(&ctx);
92                 for(i=0; i<4; ++i)
93                         iv_1[i] = mickey128_getbyte(&ctx);
94                 mickey128_init(key[0], 128, iv_1, 32, &ctx);
95         }
96                 for(i=0; i<16; ++i){
97                 data[i] = mickey128_getbyte(&ctx);
98         }
99         cli_putstr_P(PSTR("\r\n stream: "));
100         cli_hexdump(data, 16);
101         cli_putstr_P(PSTR("\r\n"));
102
103 }
104
105
106
107 /*****************************************************************************
108  *  main                                                                                                                                         *
109  *****************************************************************************/
110
111 const char nessie_str[]      PROGMEM = "nessie";
112 const char test_str[]        PROGMEM = "test";
113 const char performance_str[] PROGMEM = "performance";
114 const char echo_str[]        PROGMEM = "echo";
115
116 const cmdlist_entry_t cmdlist[] PROGMEM = {
117         { nessie_str,      NULL, testrun_nessie_mickey128},
118         { test_str,        NULL, testrun_ref_mickey128},
119         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
120         { NULL,            NULL, NULL}
121 };
122
123 int main (void){
124     main_setup();
125
126     for(;;){
127         welcome_msg(algo_name);
128         cmd_interface(cmdlist);
129         }
130 }