1 /* main-twister384-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-big.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
38 char* algo_name = "TWISTER-384";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
43 void twister384_init_dummy(void* ctx){
44 twister_big_init(ctx, 384);
47 void twister384_next_dummy(void* buffer, void* ctx){
48 twister_big_nextBlock(ctx, buffer);
51 void twister384_last_dummy(void* buffer, uint16_t size_b, void* ctx){
52 twister_big_lastBlock(ctx, buffer, size_b);
55 void twister384_ctx2hash_dummy(void* buffer, void* ctx){
56 twister_big_ctx2hash(buffer, ctx, 384);
60 void testrun_nessie_twister384(void){
61 nessie_hash_ctx.hashsize_b = 384;
62 nessie_hash_ctx.blocksize_B = 512/8;
63 nessie_hash_ctx.ctx_size_B = sizeof(twister_big_ctx_t);
64 nessie_hash_ctx.name = algo_name;
65 nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)twister384_init_dummy;
66 nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)twister384_next_dummy;
67 nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)twister384_last_dummy;
68 nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)twister384_ctx2hash_dummy;
73 /******************************************************************************
75 ******************************************************************************/
77 void print_hash(void* hash){
78 uart_hexdump(hash, 256/8);
79 uart_putstr_P(PSTR("\r\n\t"));
80 uart_hexdump((uint8_t*)hash+256/8, 128/8);
84 void testrun_twister384(void){
85 twister384_hash_t hash;
91 "abcdefghijklmnopqrstuvwxyz",
92 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
93 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
96 uart_putstr_P(PSTR("\r\n=== TWISTER-384 test suit (MD5 test values) ==="));
98 uart_putstr_P(PSTR("\r\n TWISTER-384 (\""));
99 uart_putstr(testv[i]);
100 uart_putstr_P(PSTR("\") = \r\n\t"));
101 twister384(&hash, testv[i], strlen(testv[i])*8);
106 uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-384 test suit (short test values) ==="));
107 uint8_t stestv[]= {0x00, 0x00, 0xC0, 0xC0, 0x80, 0x48, 0x50};
108 uint8_t stestl[]= { 0, 1, 2, 3, 4, 5, 6};
110 uart_putstr_P(PSTR("\r\n TWISTER-384 (\""));
111 uart_hexdump(&(stestv[i]), 1);
112 uart_putstr_P(PSTR("\") = \r\n\t"));
113 twister384(hash, &(stestv[i]), stestl[i]);
117 #ifdef TWISTER_LONGTEST
118 uart_putstr_P(PSTR("\r\n\r\n=== TWISTER-384 test suit (long test) ==="));
119 char* ltest= "abcdefghbcdefghicdefghijdefghijk"
120 "efghijklfghijklmghijklmnhijklmno";
121 twister384_ctx_t ctx;
122 twister384_init(&ctx);
123 uart_putstr_P(PSTR("\r\n TWISTER-384 ( 16777216 x \""));
125 uart_putstr_P(PSTR("\") = \r\n\t"));
126 for(i=0; i<16777216; ++i){
127 twister384_nextBlock(&ctx, ltest);
129 twister384_ctx2hash(hash, &ctx);
135 void testrun_performance_twister384(void){
139 twister_big_ctx_t ctx;
147 twister_big_init(&ctx, 384);
149 uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
150 ultoa((unsigned long)t, str, 10);
155 twister_big_nextBlock(&ctx, data);
157 uart_putstr_P(PSTR("\r\n\tone-block time: "));
158 ultoa((unsigned long)t, str, 10);
163 twister_big_lastBlock(&ctx, data, 0);
165 uart_putstr_P(PSTR("\r\n\tlast block time: "));
166 ultoa((unsigned long)t, str, 10);
170 twister_big_ctx2hash(data, &ctx, 384);
172 uart_putstr_P(PSTR("\r\n\tctx2hash time: "));
173 ultoa((unsigned long)t, str, 10);
176 uart_putstr_P(PSTR("\r\n"));
180 /*****************************************************************************
183 *****************************************************************************/
185 const char nessie_str[] PROGMEM = "nessie";
186 const char test_str[] PROGMEM = "test";
187 const char performance_str[] PROGMEM = "performance";
188 const char echo_str[] PROGMEM = "echo";
190 cmdlist_entry_t cmdlist[] PROGMEM = {
191 { nessie_str, NULL, testrun_nessie_twister384},
192 { test_str, NULL, testrun_twister384},
193 { performance_str, NULL, testrun_performance_twister384},
194 { echo_str, (void*)1, (void_fpt)echo_ctrl},
204 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
205 uart_putstr(algo_name);
206 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
207 cmd_interface(cmdlist);