1 /* main-shabal-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
25 #include "serial-tools.h"
31 #include "hfal_shabal.h"
33 #include "nessie_hash_test.h"
34 #include "performance_test.h"
40 char* algo_name = "Shabal";
42 /*****************************************************************************
43 * additional validation-functions *
44 *****************************************************************************/
45 void testrun_stdtest_shabal192(void* msg, uint16_t size_b){
48 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (192 bits):"));
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);
57 void testrun_stdtest_shabal224(void* msg, uint16_t size_b){
60 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (224 bits):"));
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);
69 void testrun_stdtest_shabal256(void* msg, uint16_t size_b){
72 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (256 bits):"));
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);
81 void testrun_stdtest_shabal384(void* msg, uint16_t size_b){
84 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (384 bits):"));
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);
93 void testrun_stdtest_shabal512(void* msg, uint16_t size_b){
96 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Shabal (512 bits):"));
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);
105 void testrun_stdtest_shabal(void){
107 char* mb= "abcdefghijklmnopqrstuvwxyz-"
109 "ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
111 "abcdefghijklmnopqrstuvwxyz";
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);
126 void testshort(void){
129 testrun_stdtest_shabal192(ma, 64*8);
132 void shabal_ctx_dump(shabal_ctx_t* ctx){
135 cli_putstr_P(PSTR("\r\n=== shabal ctx dump ===\r\n size = "));
136 i=sizeof(shabal_ctx_t);
140 cli_putc('0'+(i/10)%10);
142 cli_putstr_P(PSTR("\r\n a = "));
143 cli_hexdump_block(ctx->a, 12*4, 5, 4*8);
144 cli_putstr_P(PSTR("\r\n b_buffer = "));
145 cli_hexdump_block(ctx->b_buffer, 12*4, 5, 4*8);
146 cli_putstr_P(PSTR("\r\n c_buffer = "));
147 cli_hexdump_block(ctx->c_buffer, 12*4, 5, 4*8);
148 if(ctx->b == &(ctx->b_buffer[0]))
149 cli_putstr_P(PSTR("\r\nb --> b_buffer"));
150 if(ctx->b == &(ctx->c_buffer[0]))
151 cli_putstr_P(PSTR("\r\nb --> c_buffer"));
152 if(ctx->c == &(ctx->b_buffer[0]))
153 cli_putstr_P(PSTR("\r\nc --> b_buffer"));
154 if(ctx->c == &(ctx->c_buffer[0]))
155 cli_putstr_P(PSTR("\r\nc --> c_buffer"));
156 cli_putstr_P(PSTR("\r\n b = "));
157 cli_hexdump(&(ctx->b), 2);
159 cli_putstr_P(PSTR("\r\n b (should) = "));
161 cli_putstr_P(PSTR("\r\n c = "));
162 cli_hexdump(&(ctx->c), 2);
164 cli_putstr_P(PSTR("\r\n c (should) = "));
169 void testinit_192(void){
171 shabal192_init(&ctx);
172 shabal_ctx_dump(&ctx);
175 void testinit_224(void){
177 shabal224_init(&ctx);
178 shabal_ctx_dump(&ctx);
181 void testinit_256(void){
183 shabal256_init(&ctx);
184 shabal_ctx_dump(&ctx);
187 void testinit_384(void){
189 shabal384_init(&ctx);
190 shabal_ctx_dump(&ctx);
193 void testinit_512(void){
195 shabal512_init(&ctx);
196 shabal_ctx_dump(&ctx);
206 void performance_shabal(void){
219 shabal192_init(&ctx);
221 cli_putstr_P(PSTR("\r\n\tctx-gen time (192): "));
222 ultoa((unsigned long)t, str, 10);
226 shabal224_init(&ctx);
228 cli_putstr_P(PSTR("\r\n\tctx-gen time (224): "));
229 ultoa((unsigned long)t, str, 10);
233 shabal256_init(&ctx);
235 cli_putstr_P(PSTR("\r\n\tctx-gen time (256): "));
236 ultoa((unsigned long)t, str, 10);
240 shabal384_init(&ctx);
242 cli_putstr_P(PSTR("\r\n\tctx-gen time (384): "));
243 ultoa((unsigned long)t, str, 10);
247 shabal512_init(&ctx);
249 cli_putstr_P(PSTR("\r\n\tctx-gen time (512): "));
250 ultoa((unsigned long)t, str, 10);
254 shabal_nextBlock(&ctx, data);
256 cli_putstr_P(PSTR("\r\n\tone-block time: "));
257 ultoa((unsigned long)t, str, 10);
262 shabal_lastBlock(&ctx, data, 0);
264 cli_putstr_P(PSTR("\r\n\tlast block time: "));
265 ultoa((unsigned long)t, str, 10);
269 shabal192_ctx2hash(hash, &ctx);
271 cli_putstr_P(PSTR("\r\n\tctx2hash time (192): "));
272 ultoa((unsigned long)t, str, 10);
276 shabal224_ctx2hash(hash, &ctx);
278 cli_putstr_P(PSTR("\r\n\tctx2hash time (224): "));
279 ultoa((unsigned long)t, str, 10);
283 shabal256_ctx2hash(hash, &ctx);
285 cli_putstr_P(PSTR("\r\n\tctx2hash time (256): "));
286 ultoa((unsigned long)t, str, 10);
290 shabal384_ctx2hash(hash, &ctx);
292 cli_putstr_P(PSTR("\r\n\tctx2hash time (384): "));
293 ultoa((unsigned long)t, str, 10);
297 shabal512_ctx2hash(hash, &ctx);
299 cli_putstr_P(PSTR("\r\n\tctx2hash time (512): "));
300 ultoa((unsigned long)t, str, 10);
303 cli_putstr_P(PSTR("\r\n"));
307 void testrun_nessie_shabal(void){
308 nessie_hash_ctx.hashsize_b = 192;
309 nessie_hash_ctx.blocksize_B = 512/8;
310 nessie_hash_ctx.ctx_size_B = sizeof(shabal_ctx_t);
311 nessie_hash_ctx.name = "Shabal-192";
312 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal192_init;
313 nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)shabal_nextBlock;
314 nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)shabal_lastBlock;
315 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal192_ctx2hash;
319 nessie_hash_ctx.hashsize_b = 224;
320 nessie_hash_ctx.name = "Shabal-224";
321 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal224_init;
322 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal224_ctx2hash;
326 nessie_hash_ctx.hashsize_b = 256;
327 nessie_hash_ctx.name = "Shabal-256";
328 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal256_init;
329 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal256_ctx2hash;
333 nessie_hash_ctx.hashsize_b = 384;
334 nessie_hash_ctx.name = "Shabal-384";
335 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal384_init;
336 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal384_ctx2hash;
340 nessie_hash_ctx.hashsize_b = 512;
341 nessie_hash_ctx.name = "Shabal-512";
342 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)shabal512_init;
343 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)shabal512_ctx2hash;
349 /*****************************************************************************
351 *****************************************************************************/
353 const hfdesc_t* algolist[] PROGMEM = {
354 (hfdesc_t*)&shabal192_desc,
355 (hfdesc_t*)&shabal224_desc,
356 (hfdesc_t*)&shabal256_desc,
357 (hfdesc_t*)&shabal384_desc,
358 (hfdesc_t*)&shabal512_desc,
362 const char nessie_str[] PROGMEM = "nessie";
363 const char test_str[] PROGMEM = "test";
364 const char testinit192_str[] PROGMEM = "testinit192";
365 const char testinit_str[] PROGMEM = "testinit";
366 const char testshort_str[] PROGMEM = "short";
367 const char ztest_str[] PROGMEM = "zerotest";
368 const char performance_str[] PROGMEM = "performance";
369 const char echo_str[] PROGMEM = "echo";
370 const char shavs_list_str[] PROGMEM = "shavs_list";
371 const char shavs_set_str[] PROGMEM = "shavs_set";
372 const char shavs_test1_str[] PROGMEM = "shavs_test1";
374 cmdlist_entry_t cmdlist[] PROGMEM = {
375 { nessie_str, NULL, testrun_nessie_shabal},
376 { test_str, NULL, testrun_stdtest_shabal},
377 { testinit192_str, NULL, testinit_192},
378 { testinit_str, NULL, testinit},
379 { testshort_str, NULL, testshort},
380 { performance_str, NULL, performance_shabal},
381 { shavs_list_str, NULL, shavs_listalgos},
382 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
383 { shavs_test1_str, NULL, shavs_test1},
384 { echo_str, (void*)1, (void_fpt)echo_ctrl},
393 shavs_algolist=(hfdesc_t**)algolist;
394 shavs_algo=(hfdesc_t*)&shabal256_desc;
396 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
397 cli_putstr(algo_name);
398 cli_putstr_P(PSTR("; "));
399 cli_putstr(__DATE__);
400 cli_putstr_P(PSTR(" "));
401 cli_putstr(__TIME__);
402 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
404 cmd_interface(cmdlist);