1 /* main-twister256-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"
29 #include "twister-small.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
38 char* algo_name = "TWISTER-256";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
43 void twister256_init_dummy(void* ctx){
44 twister_small_init(ctx, 256);
47 void twister256_ctx2hash_dummy(void* buffer, void* ctx){
48 twister_small_ctx2hash(buffer, ctx, 256);
52 void testrun_nessie_twister256(void){
53 nessie_hash_ctx.hashsize_b = 256;
54 nessie_hash_ctx.blocksize_B = 512/8;
55 nessie_hash_ctx.ctx_size_B = sizeof(twister_state_t);
56 nessie_hash_ctx.name = algo_name;
57 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)twister256_init_dummy;
58 nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)twister_small_nextBlock;
59 nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)twister_small_lastBlock;
60 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)twister256_ctx2hash_dummy;
65 /*****************************************************************************
68 *****************************************************************************/
70 void print_hash(void* hash){
71 cli_hexdump(hash, 256/8);
74 void testrun_twister256(void){
75 twister256_hash_t hash;
81 "abcdefghijklmnopqrstuvwxyz",
82 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
83 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
86 cli_putstr_P(PSTR("\r\n=== TWISTER-256 test suit (MD5 test values) ==="));
88 cli_putstr_P(PSTR("\r\n TWISTER-256 (\""));
90 cli_putstr_P(PSTR("\") = \r\n\t"));
91 twister256(&hash, testv[i], strlen(testv[i])*8);
95 cli_putstr_P(PSTR("\r\n\r\n=== TWISTER-256 test suit (short test values) ==="));
96 uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
97 uint8_t stestl[]= { 0, 1, 2, 3, 4, 5, 6};
99 cli_putstr_P(PSTR("\r\n TWISTER-256 (\""));
100 cli_hexdump(&(stestv[i]), 1);
101 cli_putstr_P(PSTR("\") = \r\n\t"));
102 twister256(&hash, &(stestv[i]), stestl[i]);
106 #ifdef TWISTER_LONGTEST
107 cli_putstr_P(PSTR("\r\n\r\n=== TWISTER-256 test suit (long test) ==="));
108 char* ltest= "abcdefghbcdefghicdefghijdefghijk"
109 "efghijklfghijklmghijklmnhijklmno";
110 twister256_ctx_t ctx;
111 twister256_init(&ctx);
112 cli_putstr_P(PSTR("\r\n TWISTER-256 ( 16777216 x \""));
114 cli_putstr_P(PSTR("\") = \r\n\t"));
115 for(i=0; i<16777216; ++i){
116 twister224_nextBlock(&ctx, ltest);
118 twister256_ctx2hash(hash, &ctx);
124 void testrun_performance_twister256(void){
136 twister_small_init(&ctx, 256);
138 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
139 ultoa((unsigned long)t, str, 10);
144 twister_small_nextBlock(&ctx, data);
146 cli_putstr_P(PSTR("\r\n\tone-block time: "));
147 ultoa((unsigned long)t, str, 10);
152 twister_small_lastBlock(&ctx, data, 0);
154 cli_putstr_P(PSTR("\r\n\tlast block time: "));
155 ultoa((unsigned long)t, str, 10);
159 twister_small_ctx2hash(data, &ctx, 256);
161 cli_putstr_P(PSTR("\r\n\tctx2hash time: "));
162 ultoa((unsigned long)t, str, 10);
165 cli_putstr_P(PSTR("\r\n"));
169 /*****************************************************************************
171 *****************************************************************************/
173 const char nessie_str[] PROGMEM = "nessie";
174 const char test_str[] PROGMEM = "test";
175 const char performance_str[] PROGMEM = "performance";
176 const char echo_str[] PROGMEM = "echo";
178 cmdlist_entry_t cmdlist[] PROGMEM = {
179 { nessie_str, NULL, testrun_nessie_twister256},
180 { test_str, NULL, testrun_twister256},
181 { performance_str, NULL, testrun_performance_twister256},
182 { echo_str, (void*)1, (void_fpt)echo_ctrl},
192 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
193 cli_putstr(algo_name);
194 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
195 cmd_interface(cmdlist);