]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-noekeon-test.c
43eb3a90fc5080d481644d5ff7ae179b4078c60c
[avr-crypto-lib.git] / main-noekeon-test.c
1 /*
2  * serpent test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "noekeon.h"
12 #include "nessie_bc_test.h"
13 #include "cli.h"
14 #include "performance_test.h"
15
16 #include <stdint.h>
17 #include <string.h>
18 #include <stdlib.h>
19
20 char* cipher_name = "Noekeon";
21
22 /*****************************************************************************
23  *  additional validation-functions                                                                                      *
24  *****************************************************************************/
25 void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
26         noekeon_init(key, ctx);
27 }
28
29 void testrun_nessie_noekeon_indirect(void){
30         char str[strlen(cipher_name)+10];
31         strcpy(str, cipher_name);
32         strcat(str, "-indirect");
33         
34         nessie_bc_ctx.blocksize_B =  16;
35         nessie_bc_ctx.keysize_b   = 128;
36         nessie_bc_ctx.name        = str;
37         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
38         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
39         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
40         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
41         
42         nessie_bc_run();
43 }
44
45 void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
46         memcpy(ctx, key, 16);
47 }
48
49 void testrun_nessie_noekeon_direct(void){
50         char str[strlen(cipher_name)+10];
51         strcpy(str, cipher_name);
52         strcat(str, "-Direct");
53         
54         nessie_bc_ctx.blocksize_B =  16;
55         nessie_bc_ctx.keysize_b   = 128;
56         nessie_bc_ctx.name        = str;
57         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
58         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
59         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
60         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
61         
62         nessie_bc_run();
63 }
64
65 void testrun_stdtest_rundirect(void* data, void* key){
66         uart_putstr_P(PSTR("\r\n                     "));
67         uart_putstr_P(PSTR("k = "));
68         uart_hexdump(key,16);
69         
70         uart_putstr_P(PSTR("\r\n                     "));
71         uart_putstr_P(PSTR("a = "));
72         uart_hexdump(data,16);
73         
74         noekeon_enc(data, key);
75         uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
76         uart_hexdump(data,16);
77         
78         noekeon_dec(data, key);
79         uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
80         uart_hexdump(data,16);
81         uart_putstr_P(PSTR("\r\n"));
82 }
83
84 void testrun_stdtest_runindirect(void* data, void* key){
85         noekeon_ctx_t ctx;
86         uart_putstr_P(PSTR("\r\n                     "));
87         uart_putstr_P(PSTR("k = "));
88         uart_hexdump(key,16);
89         
90         uart_putstr_P(PSTR("\r\n                     "));
91         uart_putstr_P(PSTR("a = "));
92         uart_hexdump(data,16);
93         noekeon_init(key, &ctx);
94         noekeon_enc(data, &ctx);
95         uart_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
96         uart_hexdump(data,16);
97         
98         noekeon_dec(data, &ctx);
99         uart_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
100         uart_hexdump(data,16);
101         uart_putstr_P(PSTR("\r\n"));
102 }
103
104 void testrun_stdtest_noekeon(void){
105         uint8_t key[16], data[16];
106         uint8_t key3[16];
107         noekeon_ctx_t ctx;
108         
109         uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n"));
110         
111         memset(key,  0, 16);
112         memset(data, 0, 16);
113         testrun_stdtest_runindirect(data, key);
114         
115         memset(key,  0xFF, 16);
116         memset(data, 0xFF, 16);
117         testrun_stdtest_runindirect(data, key);
118         
119         memset(key,  0, 16);
120         memset(data, 0, 16);
121         noekeon_init(key, &ctx);
122         noekeon_enc(data, &ctx);
123         memcpy(key3, data, 16);
124         memset(key,  0xFF, 16);
125         memset(data, 0xFF, 16);
126         noekeon_init(key, &ctx);
127         noekeon_enc(data, &ctx);
128         testrun_stdtest_runindirect(data, key3);
129         
130         
131         uart_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n"));
132         
133         memset(key,  0, 16);
134         memset(data, 0, 16);
135         testrun_stdtest_rundirect(data, key);
136         
137         memset(key,  0xFF, 16);
138         memset(data, 0xFF, 16);
139         testrun_stdtest_rundirect(data, key);
140         
141         memset(key,  0, 16);
142         memset(data, 0, 16);
143         noekeon_enc(data, key);
144         memcpy(key3, data, 16);
145         memset(key,  0xFF, 16);
146         memset(data, 0xFF, 16);
147         noekeon_enc(data, key);
148         testrun_stdtest_rundirect(data, key3);
149         
150 }
151
152 void testrun_performance_noekeon(void){
153         uint16_t i,c;
154         uint64_t t;
155         char str[6];
156         uint8_t key[16], data[16];
157         noekeon_ctx_t ctx;
158         
159         calibrateTimer();
160         getOverhead(&c, &i);
161         uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
162         utoa(c, str, 10);
163         uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
164         uart_putstr(str);
165         utoa(i, str, 10);
166         uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
167         uart_putstr(str);
168         
169         memset(key,  0, 16);
170         memset(data, 0, 16);
171         
172         startTimer(1);
173         noekeon_init(key, &ctx);
174         t = stopTimer();
175         uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
176         uart_hexdump(&t, 8);
177         
178         
179         startTimer(1);
180         noekeon_enc(data, ctx);
181         t = stopTimer();
182         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
183         uart_hexdump(&t, 8);
184         
185         
186         startTimer(1);
187         noekeon_dec(data, ctx);
188         t = stopTimer();
189         uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
190         uart_hexdump(&t, 8);
191         uart_putstr_P(PSTR("\r\n"));
192 }
193 /*****************************************************************************
194  *  main                                                                                                                                         *
195  *****************************************************************************/
196
197 typedef void(*void_fpt)(void);
198
199 int main (void){
200         char  str[20];
201         DEBUG_INIT();
202         uart_putstr("\r\n");
203
204         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
205         uart_putstr(cipher_name);
206         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
207
208         PGM_P    u   = PSTR("nessie\0test\0direct\0indirect\0performance\0");
209         void_fpt v[] = {testrun_nessie_noekeon_direct, 
210                             testrun_stdtest_noekeon,
211                             testrun_nessie_noekeon_direct, 
212                             testrun_nessie_noekeon_indirect,  
213                             testrun_performance_noekeon};
214
215         while(1){ 
216                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
217                 if(execcommand_d0_P(str, u, v)<0){
218                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
219                 }
220                 continue;
221         error:
222                 uart_putstr("ERROR\r\n");
223         }
224         
225 }
226