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 skein256(hash, outsize_b, message, 8);
57 cli_putstr_P(PSTR("\r\nhash:"));
58 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
60 cli_putstr_P(PSTR("\r\nmessage:"));
61 skein256(hash, outsize_b, message, 32*8);
62 cli_putstr_P(PSTR("\r\nhash:"));
63 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
65 cli_putstr_P(PSTR("\r\nmessage:"));
66 skein256(hash, outsize_b, message, 64*8);
67 cli_putstr_P(PSTR("\r\nhash:"));
68 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
71 void testrun_stdtest_skein512(uint16_t outsize_b){
73 uint8_t hash[(outsize_b+7)/8];
76 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
80 cli_putstr_P(PSTR("\r\nmessage: "));
81 cli_hexdump(message, 1);
82 skein512(hash, outsize_b, message, 8);
83 cli_putstr_P(PSTR("\r\nhash:"));
84 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
86 cli_putstr_P(PSTR("\r\nmessage:"));
87 skein512(hash, outsize_b, message, 64*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 skein512(hash, outsize_b, message, 128*8);
93 cli_putstr_P(PSTR("\r\nhash:"));
94 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
97 void testrun_stdtest_skein1024(uint16_t outsize_b){
99 uint8_t hash[(outsize_b+7)/8];
102 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
106 cli_putstr_P(PSTR("\r\nmessage: "));
107 cli_hexdump(message, 1);
108 skein1024(hash, outsize_b, message, 8);
109 cli_putstr_P(PSTR("\r\nhash:"));
110 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
112 cli_putstr_P(PSTR("\r\nmessage:"));
113 skein1024(hash, outsize_b, message, 128*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, 256, 4, 16);
119 skein1024(hash, outsize_b, message, 256*8);
120 cli_putstr_P(PSTR("\r\nhash:"));
121 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
124 void testrun_stdtest_skein(void){
125 testrun_stdtest_skein256(256);
126 testrun_stdtest_skein512(512);
127 testrun_stdtest_skein1024(1024);
130 void zeromsg_test_skein(uint16_t outsize_b){
132 uint8_t hash[(outsize_b+7)/8];
134 skein256(hash, outsize_b, NULL, 0);
135 cli_putstr_P(PSTR("\r\nskein256-"));
136 utoa(outsize_b, str, 10);
138 cli_putstr_P(PSTR(" :"));
139 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
141 skein512(hash, outsize_b, NULL, 0);
142 cli_putstr_P(PSTR("\r\nskein512-"));
143 utoa(outsize_b, str, 10);
145 cli_putstr_P(PSTR(" :"));
146 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
148 skein1024(hash, outsize_b, NULL, 0);
149 cli_putstr_P(PSTR("\r\nskein1024-"));
150 utoa(outsize_b, str, 10);
152 cli_putstr_P(PSTR(" :"));
153 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
156 void zeromsg_test_common(char* p){
159 uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
161 s = strtoul(p, NULL, 0);
164 zeromsg_test_skein(s);
167 zeromsg_test_skein(sizes[i]);
171 /*****************************************************************************
173 *****************************************************************************/
175 const hfdesc_t* algolist[] PROGMEM = {
176 (hfdesc_t*)&skein256_128_desc,
177 (hfdesc_t*)&skein256_160_desc,
178 (hfdesc_t*)&skein256_224_desc,
179 (hfdesc_t*)&skein256_256_desc,
180 (hfdesc_t*)&skein256_384_desc,
181 (hfdesc_t*)&skein256_512_desc,
183 (hfdesc_t*)&skein512_128_desc,
184 (hfdesc_t*)&skein512_160_desc,
185 (hfdesc_t*)&skein512_224_desc,
186 (hfdesc_t*)&skein512_256_desc,
187 (hfdesc_t*)&skein512_384_desc,
188 (hfdesc_t*)&skein512_512_desc,
189 (hfdesc_t*)&skein512_1024_desc,
191 (hfdesc_t*)&skein1024_128_desc,
192 (hfdesc_t*)&skein1024_160_desc,
193 (hfdesc_t*)&skein1024_224_desc,
194 (hfdesc_t*)&skein1024_256_desc,
195 (hfdesc_t*)&skein1024_384_desc,
196 (hfdesc_t*)&skein1024_512_desc,
197 (hfdesc_t*)&skein1024_1024_desc,
201 const char nessie_str[] PROGMEM = "nessie";
202 const char test_str[] PROGMEM = "test";
203 const char ztest_str[] PROGMEM = "zerotest";
204 const char performance_str[] PROGMEM = "performance";
205 const char echo_str[] PROGMEM = "echo";
206 const char shavs_list_str[] PROGMEM = "shavs_list";
207 const char shavs_set_str[] PROGMEM = "shavs_set";
208 const char shavs_test1_str[] PROGMEM = "shavs_test1";
210 cmdlist_entry_t cmdlist[] PROGMEM = {
211 // { nessie_str, NULL, testrun_nessie_noekeon},
212 { test_str, NULL, testrun_stdtest_skein},
213 { ztest_str, (void*)1, (void_fpt)zeromsg_test_common},
214 { shavs_list_str, NULL, shavs_listalgos},
215 { shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
216 { shavs_test1_str, NULL, shavs_test1},
217 { echo_str, (void*)1, (void_fpt)echo_ctrl},
226 shavs_algolist=(hfdesc_t**)algolist;
227 shavs_algo=(hfdesc_t*)&skein256_256_desc;
229 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
230 cli_putstr(algo_name);
231 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
232 cmd_interface(cmdlist);