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