1 /* main-whirlpool-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2011 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/>.
29 #include "whirlpool.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
32 #include "hfal-performance.h"
33 #include "hfal-nessie.h"
40 #include "hfal_whirlpool.h"
43 char* algo_name = "Whirlpool";
45 const hfdesc_t* algolist[] PROGMEM = {
46 (hfdesc_t*)&whirlpool_desc,
50 /*****************************************************************************
51 * additional validation-functions *
52 *****************************************************************************/
54 void testrun_nessie_whirlpool(void){
55 hfal_nessie_multiple(algolist);
58 void testrun_whirlpool(void){
67 whirlpool_lastBlock(&ctx, data, 3*8);
68 whirlpool_ctx2hash(hash, &ctx);
69 cli_putstr_P(PSTR("\r\nEmpty message hash:"));
70 cli_hexdump_block(hash, 64, 4, 16);
73 void testrun_performance_whirlpool(void){
74 hfal_performance_multiple(algolist);
79 cli_putstr_P(PSTR("\r\nWhirlpool S-Box:"));
82 cli_putstr_P(PSTR("\r\n\t"));
84 cli_hexdump_byte(whirlpool_sbox(i++));
89 void testrun_nessie2(void){
92 uint8_t data[128], hash[64];
96 cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
97 for(i=0; i<1024; ++i){
98 cli_putstr_P(PSTR("\r\n L = "));
109 cli_putstr_P(PSTR(": "));
110 whirlpool_init(&ctx);
111 whirlpool_lastBlock(&ctx, data, i);
112 whirlpool_ctx2hash(hash, &ctx);
113 cli_hexdump(hash, 64);
115 cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
116 for(i=0; i<512; ++i){
117 cli_putstr_P(PSTR("\r\n S = "));
118 data[i/8] = 0x80>>(i&7);
119 cli_hexdump(data, 64);
120 cli_putstr_P(PSTR(": "));
121 whirlpool_init(&ctx);
122 whirlpool_lastBlock(&ctx, data, 512);
123 whirlpool_ctx2hash(hash, &ctx);
125 cli_hexdump(hash, 64);
127 cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
130 for(c=0; c<1000000; ++c){
131 whirlpool_init(&ctx);
132 whirlpool_lastBlock(&ctx, hash, 512);
133 whirlpool_ctx2hash(hash, &ctx);
135 cli_hexdump(hash, 64);
136 cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
139 /*****************************************************************************
141 *****************************************************************************/
143 const char nessie_str[] PROGMEM = "nessie";
144 const char nessie2_str[] PROGMEM = "nessie2";
145 const char test_str[] PROGMEM = "test";
146 const char test_sbox_str[] PROGMEM = "test_sbox";
147 const char performance_str[] PROGMEM = "performance";
148 const char echo_str[] PROGMEM = "echo";
149 const char shavs_list_str[] PROGMEM = "shavs_list";
150 const char shavs_set_str[] PROGMEM = "shavs_set";
151 const char shavs_test1_str[] PROGMEM = "shavs_test1";
152 const char shavs_test2_str[] PROGMEM = "shavs_test2";
153 const char shavs_test3_str[] PROGMEM = "shavs_test3";
154 const char dump_str[] PROGMEM = "dump";
156 cmdlist_entry_t cmdlist[] PROGMEM = {
157 { nessie_str, NULL, testrun_nessie_whirlpool },
158 { nessie2_str, NULL, testrun_nessie2 },
159 { test_str, NULL, testrun_whirlpool },
160 { test_sbox_str, NULL, test_sbox },
161 { performance_str, NULL, testrun_performance_whirlpool },
162 { echo_str, (void*)1, (void_fpt)echo_ctrl },
163 { shavs_list_str, NULL, shavs_listalgos },
164 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo },
165 { shavs_test1_str, NULL, shavs_test1 },
166 { shavs_test2_str, NULL, shavs_test2 },
167 { shavs_test3_str, NULL, shavs_test3 },
168 { dump_str, (void*)1, (void_fpt)dump },
175 cli_rx = (cli_rx_fpt)uart0_getc;
176 cli_tx = (cli_tx_fpt)uart0_putc;
177 shavs_algolist=(hfdesc_t**)algolist;
178 shavs_algo=(hfdesc_t*)&whirlpool_desc;
180 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
181 cli_putstr(algo_name);
182 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
183 cmd_interface(cmdlist);