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