]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-shabal-test.c
+Shabal
[avr-crypto-lib.git] / test_src / main-shabal-test.c
1 /* main-shabal-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  * shabal test-suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "shabal.h"
30 #include "cli.h"
31 #include "hfal_shabal.h"
32 #include "shavs.h"
33 #include "nessie_hash_test.h"
34 #include "performance_test.h"
35
36 #include <stdint.h>
37 #include <string.h>
38 #include <stdlib.h>
39
40 char* algo_name = "Shabal";
41
42 /*****************************************************************************
43  *  additional validation-functions                                                                                      *
44  *****************************************************************************/
45 void testrun_stdtest_shabal192(void* msg, uint16_t size_b){
46         uint8_t hash[192/8];
47                 
48         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (192 bits):"));
49
50         cli_putstr_P(PSTR("\r\nmessage:"));
51         cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
52         shabal192(hash, msg, size_b);
53         cli_putstr_P(PSTR("\r\nhash:"));
54         cli_hexdump_block(hash, 192/8, 4, 16);
55 }
56
57 void testrun_stdtest_shabal224(void* msg, uint16_t size_b){
58         uint8_t hash[224/8];
59                 
60         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (224 bits):"));
61
62         cli_putstr_P(PSTR("\r\nmessage:"));
63         cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
64         shabal224(hash, msg, size_b);
65         cli_putstr_P(PSTR("\r\nhash:"));
66         cli_hexdump_block(hash, 224/8, 4, 16);
67 }
68
69 void testrun_stdtest_shabal256(void* msg, uint16_t size_b){
70         uint8_t hash[256/8];
71                 
72         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (256 bits):"));
73
74         cli_putstr_P(PSTR("\r\nmessage:"));
75         cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
76         shabal256(hash, msg, size_b);
77         cli_putstr_P(PSTR("\r\nhash:"));
78         cli_hexdump_block(hash, 256/8, 4, 16);
79 }
80
81 void testrun_stdtest_shabal384(void* msg, uint16_t size_b){
82         uint8_t hash[384/8];
83                 
84         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (384 bits):"));
85
86         cli_putstr_P(PSTR("\r\nmessage:"));
87         cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
88         shabal384(hash, msg, size_b);
89         cli_putstr_P(PSTR("\r\nhash:"));
90         cli_hexdump_block(hash, 384/8, 4, 16);
91 }
92
93 void testrun_stdtest_shabal512(void* msg, uint16_t size_b){
94         uint8_t hash[512/8];
95                 
96         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (512 bits):"));
97
98         cli_putstr_P(PSTR("\r\nmessage:"));
99         cli_hexdump_block(msg, (size_b+7)/8, 4, 16);
100         shabal512(hash, msg, size_b);
101         cli_putstr_P(PSTR("\r\nhash:"));
102         cli_hexdump_block(hash, 512/8, 4, 16);
103 }
104
105 void testrun_stdtest_shabal(void){
106         uint8_t ma[64];
107         char*   mb= "abcdefghijklmnopqrstuvwxyz-"
108                     "0123456789-"
109                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
110                 "0123456789-"
111                                 "abcdefghijklmnopqrstuvwxyz";
112
113         memset(ma, 0, 64);
114         testrun_stdtest_shabal192(ma, 64*8);
115         testrun_stdtest_shabal192(mb, strlen(mb)*8);
116         testrun_stdtest_shabal224(ma, 64*8);
117         testrun_stdtest_shabal224(mb, strlen(mb)*8);
118         testrun_stdtest_shabal256(ma, 64*8);
119         testrun_stdtest_shabal256(mb, strlen(mb)*8);
120         testrun_stdtest_shabal384(ma, 64*8);
121         testrun_stdtest_shabal384(mb, strlen(mb)*8);
122         testrun_stdtest_shabal512(ma, 64*8);
123         testrun_stdtest_shabal512(mb, strlen(mb)*8);
124 }
125
126 void performance_shabal(void){
127         uint64_t t;
128         char str[16];
129         uint8_t data[64];
130         uint8_t hash[512/8];
131         shabal_ctx_t ctx;
132         
133         calibrateTimer();
134         print_overhead();
135         
136         memset(data, 0, 64);
137         
138         startTimer(1);
139         shabal192_init(&ctx);
140         t = stopTimer();
141         cli_putstr_P(PSTR("\r\n\tctx-gen time (192): "));
142         ultoa((unsigned long)t, str, 10);
143         cli_putstr(str);
144         
145         startTimer(1);
146         shabal192_init(&ctx);
147         t = stopTimer();
148         cli_putstr_P(PSTR("\r\n\tctx-gen time (224): "));
149         ultoa((unsigned long)t, str, 10);
150         cli_putstr(str);
151         
152         startTimer(1);
153         shabal192_init(&ctx);
154         t = stopTimer();
155         cli_putstr_P(PSTR("\r\n\tctx-gen time (256): "));
156         ultoa((unsigned long)t, str, 10);
157         cli_putstr(str);
158         
159         startTimer(1);
160         shabal192_init(&ctx);
161         t = stopTimer();
162         cli_putstr_P(PSTR("\r\n\tctx-gen time (384): "));
163         ultoa((unsigned long)t, str, 10);
164         cli_putstr(str);
165         
166         startTimer(1);
167         shabal192_init(&ctx);
168         t = stopTimer();
169         cli_putstr_P(PSTR("\r\n\tctx-gen time (512): "));
170         ultoa((unsigned long)t, str, 10);
171         cli_putstr(str);
172                 
173         startTimer(1);
174         shabal_nextBlock(&ctx, data);
175         t = stopTimer();
176         cli_putstr_P(PSTR("\r\n\tone-block time: "));
177         ultoa((unsigned long)t, str, 10);
178         cli_putstr(str);
179         
180         
181         startTimer(1);
182         shabal_lastBlock(&ctx, data, 0);
183         t = stopTimer();
184         cli_putstr_P(PSTR("\r\n\tlast block time: "));
185         ultoa((unsigned long)t, str, 10);
186         cli_putstr(str);
187         
188         startTimer(1);
189         shabal192_ctx2hash(hash, &ctx);
190         t = stopTimer();
191         cli_putstr_P(PSTR("\r\n\tctx2hash time (192): "));
192         ultoa((unsigned long)t, str, 10);
193         cli_putstr(str);
194         
195         startTimer(1);
196         shabal224_ctx2hash(hash, &ctx);
197         t = stopTimer();
198         cli_putstr_P(PSTR("\r\n\tctx2hash time (224): "));
199         ultoa((unsigned long)t, str, 10);
200         cli_putstr(str);
201         
202         startTimer(1);
203         shabal256_ctx2hash(hash, &ctx);
204         t = stopTimer();
205         cli_putstr_P(PSTR("\r\n\tctx2hash time (256): "));
206         ultoa((unsigned long)t, str, 10);
207         cli_putstr(str);
208         
209         startTimer(1);
210         shabal384_ctx2hash(hash, &ctx);
211         t = stopTimer();
212         cli_putstr_P(PSTR("\r\n\tctx2hash time (384): "));
213         ultoa((unsigned long)t, str, 10);
214         cli_putstr(str);
215         
216         startTimer(1);
217         shabal512_ctx2hash(hash, &ctx);
218         t = stopTimer();
219         cli_putstr_P(PSTR("\r\n\tctx2hash time (512): "));
220         ultoa((unsigned long)t, str, 10);
221         cli_putstr(str);
222                 
223         cli_putstr_P(PSTR("\r\n"));
224
225 }
226
227 void testrun_nessie_shabal(void){
228         nessie_hash_ctx.hashsize_b  = 192;
229         nessie_hash_ctx.blocksize_B = 512/8;
230         nessie_hash_ctx.ctx_size_B  = sizeof(shabal_ctx_t);
231         nessie_hash_ctx.name = "Shabal-192";
232         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal192_init;
233         nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)shabal_nextBlock;
234         nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)shabal_lastBlock;
235         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal192_ctx2hash;
236         
237         nessie_hash_run();
238         
239         nessie_hash_ctx.hashsize_b  = 224;
240         nessie_hash_ctx.name = "Shabal-224";
241         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal224_init;
242         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal224_ctx2hash;
243         
244         nessie_hash_run();
245         
246         nessie_hash_ctx.hashsize_b  = 256;
247         nessie_hash_ctx.name = "Shabal-256";
248         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal256_init;
249         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal256_ctx2hash;
250         
251         nessie_hash_run();
252         
253         nessie_hash_ctx.hashsize_b  = 384;
254         nessie_hash_ctx.name = "Shabal-384";
255         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal384_init;
256         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal384_ctx2hash;
257         
258         nessie_hash_run();
259         
260         nessie_hash_ctx.hashsize_b  = 512;
261         nessie_hash_ctx.name = "Shabal-512";
262         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal512_init;
263         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal512_ctx2hash;
264         
265         nessie_hash_run();
266         
267 }
268
269 /*****************************************************************************
270  *  main                                                                                                                                         *
271  *****************************************************************************/
272
273 const hfdesc_t* algolist[] PROGMEM = {
274         (hfdesc_t*)&shabal192_desc,
275         (hfdesc_t*)&shabal224_desc,
276         (hfdesc_t*)&shabal256_desc,
277         (hfdesc_t*)&shabal384_desc,
278         (hfdesc_t*)&shabal512_desc,     
279         NULL
280 };
281
282 const char nessie_str[]      PROGMEM = "nessie";
283 const char test_str[]        PROGMEM = "test";
284 const char ztest_str[]       PROGMEM = "zerotest";
285 const char performance_str[] PROGMEM = "performance";
286 const char echo_str[]        PROGMEM = "echo";
287 const char shavs_list_str[]  PROGMEM = "shavs_list";
288 const char shavs_set_str[]   PROGMEM = "shavs_set";
289 const char shavs_test1_str[] PROGMEM = "shavs_test1";
290
291 cmdlist_entry_t cmdlist[] PROGMEM = {
292         { nessie_str,          NULL, testrun_nessie_shabal},
293         { test_str,            NULL, testrun_stdtest_shabal},
294         { performance_str,     NULL, performance_shabal},
295         { shavs_list_str,      NULL, shavs_listalgos},
296         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
297         { shavs_test1_str,     NULL, shavs_test1},
298         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
299         { NULL,                NULL, NULL}
300 };
301
302 int main (void){
303         DEBUG_INIT();
304         
305         cli_rx = uart_getc;
306         cli_tx = uart_putc;             
307         shavs_algolist=(hfdesc_t**)algolist;
308         shavs_algo=(hfdesc_t*)&shabal256_desc;
309         for(;;){
310                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
311                 cli_putstr(algo_name);
312                 cli_putstr_P(PSTR("; "));
313                 cli_putstr(__DATE__);
314                 cli_putstr_P(PSTR(" "));
315                 cli_putstr(__TIME__);
316                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
317                 
318                 cmd_interface(cmdlist);
319         }
320 }