1 /* main-skein-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/>.
30 #include "hfal_skein256.h"
31 #include "hfal_skein512.h"
32 #include "hfal_skein1024.h"
35 #include "nessie_hash_test.h"
36 #include "performance_test.h"
37 #include "hfal-performance.h"
38 #include "hfal-nessie.h"
45 char* algo_name = "Skein";
47 const hfdesc_t* algolist[] PROGMEM = {
48 (hfdesc_t*)&skein256_128_desc,
49 (hfdesc_t*)&skein256_160_desc,
50 (hfdesc_t*)&skein256_224_desc,
51 (hfdesc_t*)&skein256_256_desc,
52 (hfdesc_t*)&skein256_384_desc,
53 (hfdesc_t*)&skein256_512_desc,
55 (hfdesc_t*)&skein512_128_desc,
56 (hfdesc_t*)&skein512_160_desc,
57 (hfdesc_t*)&skein512_224_desc,
58 (hfdesc_t*)&skein512_256_desc,
59 (hfdesc_t*)&skein512_384_desc,
60 (hfdesc_t*)&skein512_512_desc,
61 (hfdesc_t*)&skein512_1024_desc,
63 (hfdesc_t*)&skein1024_128_desc,
64 (hfdesc_t*)&skein1024_160_desc,
65 (hfdesc_t*)&skein1024_224_desc,
66 (hfdesc_t*)&skein1024_256_desc,
67 (hfdesc_t*)&skein1024_384_desc,
68 (hfdesc_t*)&skein1024_512_desc,
69 (hfdesc_t*)&skein1024_1024_desc,
73 /*****************************************************************************
74 * additional validation-functions *
75 *****************************************************************************/
76 void testrun_stdtest_skein256(uint16_t outsize_b){
78 uint8_t hash[(outsize_b+7)/8];
81 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
85 cli_putstr_P(PSTR("\r\nmessage: "));
86 cli_hexdump(message, 1);
87 skein256(hash, outsize_b, message, 8);
88 cli_putstr_P(PSTR("\r\nhash:"));
89 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
91 cli_putstr_P(PSTR("\r\nmessage:"));
92 cli_hexdump_block(message, 32, 4, 16);
93 skein256(hash, outsize_b, message, 32*8);
94 cli_putstr_P(PSTR("\r\nhash:"));
95 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
97 cli_putstr_P(PSTR("\r\nmessage:"));
98 cli_hexdump_block(message, 64, 4, 16);
99 skein256(hash, outsize_b, message, 64*8);
100 cli_putstr_P(PSTR("\r\nhash:"));
101 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
104 void testrun_stdtest_skein512(uint16_t outsize_b){
105 uint8_t message[128];
106 uint8_t hash[(outsize_b+7)/8];
109 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
113 cli_putstr_P(PSTR("\r\nmessage: "));
114 cli_hexdump(message, 1);
115 skein512(hash, outsize_b, message, 8);
116 cli_putstr_P(PSTR("\r\nhash:"));
117 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
119 cli_putstr_P(PSTR("\r\nmessage:"));
120 cli_hexdump_block(message, 64, 4, 16);
121 skein512(hash, outsize_b, message, 64*8);
122 cli_putstr_P(PSTR("\r\nhash:"));
123 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
125 cli_putstr_P(PSTR("\r\nmessage:"));
126 cli_hexdump_block(message, 128, 4, 16);
127 skein512(hash, outsize_b, message, 128*8);
128 cli_putstr_P(PSTR("\r\nhash:"));
129 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
132 void testrun_stdtest_skein1024(uint16_t outsize_b){
133 uint8_t message[256];
134 uint8_t hash[(outsize_b+7)/8];
137 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
141 cli_putstr_P(PSTR("\r\nmessage: "));
142 cli_hexdump(message, 1);
143 skein1024(hash, outsize_b, message, 8);
144 cli_putstr_P(PSTR("\r\nhash:"));
145 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
147 cli_putstr_P(PSTR("\r\nmessage:"));
148 cli_hexdump_block(message, 128, 4, 16);
149 skein1024(hash, outsize_b, message, 128*8);
150 cli_putstr_P(PSTR("\r\nhash:"));
151 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
153 cli_putstr_P(PSTR("\r\nmessage:"));
154 cli_hexdump_block(message, 256, 4, 16);
155 skein1024(hash, outsize_b, message, 256*8);
156 cli_putstr_P(PSTR("\r\nhash:"));
157 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
160 void testrun_stdtest_skein(void){
161 testrun_stdtest_skein256(256);
162 testrun_stdtest_skein512(512);
163 testrun_stdtest_skein1024(1024);
166 void zeromsg_test_skein(uint16_t outsize_b){
168 uint8_t hash[(outsize_b+7)/8];
170 skein256(hash, outsize_b, NULL, 0);
171 cli_putstr_P(PSTR("\r\nskein256-"));
172 utoa(outsize_b, str, 10);
174 cli_putstr_P(PSTR(" :"));
175 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
177 skein512(hash, outsize_b, NULL, 0);
178 cli_putstr_P(PSTR("\r\nskein512-"));
179 utoa(outsize_b, str, 10);
181 cli_putstr_P(PSTR(" :"));
182 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
184 skein1024(hash, outsize_b, NULL, 0);
185 cli_putstr_P(PSTR("\r\nskein1024-"));
186 utoa(outsize_b, str, 10);
188 cli_putstr_P(PSTR(" :"));
189 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
192 void zeromsg_test_common(char* p){
195 uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
197 s = strtoul(p, NULL, 0);
200 zeromsg_test_skein(s);
203 zeromsg_test_skein(sizes[i]);
207 void performance_skein(void){
208 hfal_performance_multiple(algolist);
211 void testrun_nessie_skein(void){
212 nessie_hash_quick = 1;
213 hfal_nessie_multiple(algolist);
217 /*****************************************************************************
219 *****************************************************************************/
222 const char nessie_str[] PROGMEM = "nessie";
223 const char test_str[] PROGMEM = "test";
224 const char ztest_str[] PROGMEM = "zerotest";
225 const char performance_str[] PROGMEM = "performance";
226 const char echo_str[] PROGMEM = "echo";
227 const char shavs_list_str[] PROGMEM = "shavs_list";
228 const char shavs_set_str[] PROGMEM = "shavs_set";
229 const char shavs_test1_str[] PROGMEM = "shavs_test1";
231 cmdlist_entry_t cmdlist[] PROGMEM = {
232 { nessie_str, NULL, testrun_nessie_skein},
233 { performance_str, NULL, performance_skein},
234 { test_str, NULL, testrun_stdtest_skein},
235 { ztest_str, (void*)1, (void_fpt)zeromsg_test_common},
236 { shavs_list_str, NULL, shavs_listalgos},
237 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
238 { shavs_test1_str, NULL, shavs_test1},
239 { echo_str, (void*)1, (void_fpt)echo_ctrl},
246 cli_rx = (cli_rx_fpt)uart0_getc;
247 cli_tx = (cli_tx_fpt)uart0_putc;
248 shavs_algolist=(hfdesc_t**)algolist;
249 shavs_algo=(hfdesc_t*)&skein256_256_desc;
251 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
252 cli_putstr(algo_name);
253 cli_putstr_P(PSTR("; "));
254 cli_putstr(__DATE__);
255 cli_putstr_P(PSTR(" "));
256 cli_putstr(__TIME__);
257 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
259 cmd_interface(cmdlist);