1 /* main-twister224-test.c */
3 This file is part of the Crypto-avr-lib/microcrypt-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"
33 #include <util/delay.h>
40 char* algo_name = "TWISTER-224";
42 /*****************************************************************************
43 * additional validation-functions *
44 *****************************************************************************/
45 void twister224_init_dummy(void* ctx){
46 twister_small_init(ctx, 224);
49 void twister224_next_dummy(void* buffer, void* ctx){
50 twister_small_nextBlock(ctx, buffer);
53 void twister224_last_dummy(void* buffer, uint16_t size_b, void* ctx){
54 twister_small_lastBlock(ctx, buffer, size_b);
57 void twister224_ctx2hash_dummy(void* buffer, void* ctx){
58 twister_small_ctx2hash(buffer, ctx, 224);
62 void testrun_nessie_twister224(void){
63 nessie_hash_ctx.hashsize_b = 224;
64 nessie_hash_ctx.blocksize_B = 512/8;
65 nessie_hash_ctx.ctx_size_B = sizeof(twister_state_t);
66 nessie_hash_ctx.name = algo_name;
67 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)twister224_init_dummy;
68 nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)twister224_next_dummy;
69 nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)twister224_last_dummy;
70 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)twister224_ctx2hash_dummy;
75 /*****************************************************************************
77 *****************************************************************************/
79 void testrun_twister224(void){
80 twister224_hash_t hash;
86 "abcdefghijklmnopqrstuvwxyz",
87 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
88 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
91 uart_putstr_P(PSTR("\r\n=== TWISTER-224 test suit (MD5 test values) ==="));
93 uart_putstr_P(PSTR("\r\n TWISTER-224 (\""));
94 uart_putstr(testv[i]);
95 uart_putstr_P(PSTR("\") = \r\n\t"));
96 twister224(&hash, testv[i], strlen(testv[i])*8);
97 uart_hexdump(hash, 224/8);
100 uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-224 test suit (short test values) ==="));
101 uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
102 uint8_t stestl[]= { 0, 1, 2, 3, 4, 5, 6};
104 uart_putstr_P(PSTR("\r\n TWISTER-224 (\""));
105 uart_hexdump(&(stestv[i]), 1);
106 uart_putstr_P(PSTR("\") = \r\n\t"));
107 twister224(&hash, &(stestv[i]), stestl[i]);
108 uart_hexdump(hash, 224/8);
110 #ifdef TWISTER_LONGTEST
111 uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-224 test suit (long test) ==="));
112 char* ltest= "abcdefghbcdefghicdefghijdefghijk"
113 "efghijklfghijklmghijklmnhijklmno";
114 twister224_ctx_t ctx;
115 twister224_init(&ctx);
116 uart_putstr_P(PSTR("\r\n TWISTER-224 ( 16777216 x \""));
118 uart_putstr_P(PSTR("\") = \r\n\t"));
119 for(i=0; i<16777216; ++i){
120 twister224_nextBlock(&ctx, ltest);
122 twister224_ctx2hash(hash, &ctx);
123 uart_hexdump(hash, 224/8);
128 void testrun_performance_twister224(void){
140 twister_small_init(&ctx, 224);
142 uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
143 ultoa((unsigned long)t, str, 10);
151 twister_small_nextBlock(&ctx, data);
153 uart_putstr_P(PSTR("\r\n\tone-block time: "));
154 ultoa((unsigned long)t, str, 10);
162 twister_small_lastBlock(&ctx, data, 0);
164 uart_putstr_P(PSTR("\r\n\tlast block time: "));
165 ultoa((unsigned long)t, str, 10);
173 twister_small_ctx2hash(data, &ctx, 224);
175 uart_putstr_P(PSTR("\r\n\tctx2hash time: "));
176 ultoa((unsigned long)t, str, 10);
183 uart_putstr_P(PSTR("\r\n"));
187 /*****************************************************************************
189 *****************************************************************************/
196 uart_putstr_P(PSTR("\r\n"));
198 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
199 uart_putstr(algo_name);
200 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
201 PGM_P u = PSTR("nessie\0test\0performance\0");
202 void_fpt v[] = { testrun_nessie_twister224,
204 testrun_performance_twister224 };
207 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
208 if(execcommand_d0_P(str, u, v)<0){
209 uart_putstr_P(PSTR("\r\nunknown command\r\n"));
213 uart_putstr("ERROR\r\n");