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/>.
25 #include "serial-tools.h"
30 #include "hfal_skein256.h"
31 #include "hfal_skein512.h"
32 #include "hfal_skein1024.h"
35 #include "performance_test.h"
41 char* algo_name = "Skein";
43 /*****************************************************************************
44 * additional validation-functions *
45 *****************************************************************************/
46 void testrun_stdtest_skein256(uint16_t outsize_b){
48 uint8_t hash[(outsize_b+7)/8];
51 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
55 cli_putstr_P(PSTR("\r\nmessage: "));
56 cli_hexdump(message, 1);
57 skein256(hash, outsize_b, message, 8);
58 cli_putstr_P(PSTR("\r\nhash:"));
59 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
61 cli_putstr_P(PSTR("\r\nmessage:"));
62 cli_hexdump_block(message, 32, 4, 16);
63 skein256(hash, outsize_b, message, 32*8);
64 cli_putstr_P(PSTR("\r\nhash:"));
65 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
67 cli_putstr_P(PSTR("\r\nmessage:"));
68 cli_hexdump_block(message, 64, 4, 16);
69 skein256(hash, outsize_b, message, 64*8);
70 cli_putstr_P(PSTR("\r\nhash:"));
71 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
74 void testrun_stdtest_skein512(uint16_t outsize_b){
76 uint8_t hash[(outsize_b+7)/8];
79 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
83 cli_putstr_P(PSTR("\r\nmessage: "));
84 cli_hexdump(message, 1);
85 skein512(hash, outsize_b, message, 8);
86 cli_putstr_P(PSTR("\r\nhash:"));
87 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
89 cli_putstr_P(PSTR("\r\nmessage:"));
90 cli_hexdump_block(message, 64, 4, 16);
91 skein512(hash, outsize_b, message, 64*8);
92 cli_putstr_P(PSTR("\r\nhash:"));
93 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
95 cli_putstr_P(PSTR("\r\nmessage:"));
96 cli_hexdump_block(message, 128, 4, 16);
97 skein512(hash, outsize_b, message, 128*8);
98 cli_putstr_P(PSTR("\r\nhash:"));
99 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
102 void testrun_stdtest_skein1024(uint16_t outsize_b){
103 uint8_t message[256];
104 uint8_t hash[(outsize_b+7)/8];
107 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
111 cli_putstr_P(PSTR("\r\nmessage: "));
112 cli_hexdump(message, 1);
113 skein1024(hash, outsize_b, message, 8);
114 cli_putstr_P(PSTR("\r\nhash:"));
115 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
117 cli_putstr_P(PSTR("\r\nmessage:"));
118 cli_hexdump_block(message, 128, 4, 16);
119 skein1024(hash, outsize_b, message, 128*8);
120 cli_putstr_P(PSTR("\r\nhash:"));
121 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
123 cli_putstr_P(PSTR("\r\nmessage:"));
124 cli_hexdump_block(message, 256, 4, 16);
125 skein1024(hash, outsize_b, message, 256*8);
126 cli_putstr_P(PSTR("\r\nhash:"));
127 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
130 void testrun_stdtest_skein(void){
131 testrun_stdtest_skein256(256);
132 testrun_stdtest_skein512(512);
133 testrun_stdtest_skein1024(1024);
136 void zeromsg_test_skein(uint16_t outsize_b){
138 uint8_t hash[(outsize_b+7)/8];
140 skein256(hash, outsize_b, NULL, 0);
141 cli_putstr_P(PSTR("\r\nskein256-"));
142 utoa(outsize_b, str, 10);
144 cli_putstr_P(PSTR(" :"));
145 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
147 skein512(hash, outsize_b, NULL, 0);
148 cli_putstr_P(PSTR("\r\nskein512-"));
149 utoa(outsize_b, str, 10);
151 cli_putstr_P(PSTR(" :"));
152 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
154 skein1024(hash, outsize_b, NULL, 0);
155 cli_putstr_P(PSTR("\r\nskein1024-"));
156 utoa(outsize_b, str, 10);
158 cli_putstr_P(PSTR(" :"));
159 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
162 void zeromsg_test_common(char* p){
165 uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
167 s = strtoul(p, NULL, 0);
170 zeromsg_test_skein(s);
173 zeromsg_test_skein(sizes[i]);
177 /*****************************************************************************
179 *****************************************************************************/
181 const hfdesc_t* algolist[] PROGMEM = {
182 (hfdesc_t*)&skein256_128_desc,
183 (hfdesc_t*)&skein256_160_desc,
184 (hfdesc_t*)&skein256_224_desc,
185 (hfdesc_t*)&skein256_256_desc,
186 (hfdesc_t*)&skein256_384_desc,
187 (hfdesc_t*)&skein256_512_desc,
189 (hfdesc_t*)&skein512_128_desc,
190 (hfdesc_t*)&skein512_160_desc,
191 (hfdesc_t*)&skein512_224_desc,
192 (hfdesc_t*)&skein512_256_desc,
193 (hfdesc_t*)&skein512_384_desc,
194 (hfdesc_t*)&skein512_512_desc,
195 (hfdesc_t*)&skein512_1024_desc,
197 (hfdesc_t*)&skein1024_128_desc,
198 (hfdesc_t*)&skein1024_160_desc,
199 (hfdesc_t*)&skein1024_224_desc,
200 (hfdesc_t*)&skein1024_256_desc,
201 (hfdesc_t*)&skein1024_384_desc,
202 (hfdesc_t*)&skein1024_512_desc,
203 (hfdesc_t*)&skein1024_1024_desc,
207 const char nessie_str[] PROGMEM = "nessie";
208 const char test_str[] PROGMEM = "test";
209 const char ztest_str[] PROGMEM = "zerotest";
210 const char performance_str[] PROGMEM = "performance";
211 const char echo_str[] PROGMEM = "echo";
212 const char shavs_list_str[] PROGMEM = "shavs_list";
213 const char shavs_set_str[] PROGMEM = "shavs_set";
214 const char shavs_test1_str[] PROGMEM = "shavs_test1";
216 cmdlist_entry_t cmdlist[] PROGMEM = {
217 // { nessie_str, NULL, testrun_nessie_noekeon},
218 { test_str, NULL, testrun_stdtest_skein},
219 { ztest_str, (void*)1, (void_fpt)zeromsg_test_common},
220 { shavs_list_str, NULL, shavs_listalgos},
221 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
222 { shavs_test1_str, NULL, shavs_test1},
223 { echo_str, (void*)1, (void_fpt)echo_ctrl},
232 shavs_algolist=(hfdesc_t**)algolist;
233 shavs_algo=(hfdesc_t*)&skein256_256_desc;
235 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
236 cli_putstr(algo_name);
237 cli_putstr_P(PSTR("; "));
238 cli_putstr(__DATE__);
239 cli_putstr_P(PSTR(" "));
240 cli_putstr(__TIME__);
241 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
243 cmd_interface(cmdlist);