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"
31 #include "performance_test.h"
37 char* algo_name = "Skein";
39 /*****************************************************************************
40 * additional validation-functions *
41 *****************************************************************************/
42 void testrun_stdtest_skein256(uint16_t outsize_b){
44 uint8_t hash[(outsize_b+7)/8];
48 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
52 cli_putstr_P(PSTR("\r\nmessage: "));
53 cli_hexdump(message, 1);
54 skein256_init(&ctx, outsize_b);
55 skein256_lastBlock(&ctx, message, 8);
56 skein256_ctx2hash(hash, &ctx);
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 cli_hexdump_block(message, 32, 4, 16);
62 skein256_init(&ctx, outsize_b);
63 skein256_lastBlock(&ctx, message, 32*8);
64 skein256_ctx2hash(hash, &ctx);
65 cli_putstr_P(PSTR("\r\nhash:"));
66 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
68 cli_putstr_P(PSTR("\r\nmessage:"));
69 cli_hexdump_block(message, 64, 4, 16);
70 skein256_init(&ctx, outsize_b);
71 skein256_lastBlock(&ctx, message, 64*8);
72 skein256_ctx2hash(hash, &ctx);
73 cli_putstr_P(PSTR("\r\nhash:"));
74 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
77 void testrun_stdtest_skein512(uint16_t outsize_b){
79 uint8_t hash[(outsize_b+7)/8];
83 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
87 cli_putstr_P(PSTR("\r\nmessage: "));
88 cli_hexdump(message, 1);
89 skein512_init(&ctx, outsize_b);
90 skein512_lastBlock(&ctx, message, 8);
91 skein512_ctx2hash(hash, &ctx);
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, 64, 4, 16);
97 skein512_init(&ctx, outsize_b);
98 skein512_lastBlock(&ctx, message, 64*8);
99 skein512_ctx2hash(hash, &ctx);
100 cli_putstr_P(PSTR("\r\nhash:"));
101 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
103 cli_putstr_P(PSTR("\r\nmessage:"));
104 cli_hexdump_block(message, 128, 4, 16);
105 skein512_init(&ctx, outsize_b);
106 skein512_lastBlock(&ctx, message, 128*8);
107 skein512_ctx2hash(hash, &ctx);
108 cli_putstr_P(PSTR("\r\nhash:"));
109 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
112 void testrun_stdtest_skein1024(uint16_t outsize_b){
113 uint8_t message[256];
114 uint8_t hash[(outsize_b+7)/8];
118 cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
122 cli_putstr_P(PSTR("\r\nmessage: "));
123 cli_hexdump(message, 1);
124 skein1024_init(&ctx, outsize_b);
125 skein1024_lastBlock(&ctx, message, 8);
126 skein1024_ctx2hash(hash, &ctx);
127 cli_putstr_P(PSTR("\r\nhash:"));
128 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
130 cli_putstr_P(PSTR("\r\nmessage:"));
131 cli_hexdump_block(message, 128, 4, 16);
132 skein1024_init(&ctx, outsize_b);
133 skein1024_lastBlock(&ctx, message, 128*8);
134 skein1024_ctx2hash(hash, &ctx);
135 cli_putstr_P(PSTR("\r\nhash:"));
136 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
138 cli_putstr_P(PSTR("\r\nmessage:"));
139 cli_hexdump_block(message, 256, 4, 16);
140 skein1024_init(&ctx, outsize_b);
141 skein1024_lastBlock(&ctx, message, 256*8);
142 skein1024_ctx2hash(hash, &ctx);
143 cli_putstr_P(PSTR("\r\nhash:"));
144 cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
147 void testrun_stdtest_skein(void){
148 testrun_stdtest_skein256(256);
149 testrun_stdtest_skein512(512);
150 testrun_stdtest_skein1024(1024);
153 void testrun_performance_threefish256(void){
156 uint8_t key[THREEFISH256_BLOCKSIZE_B];
157 uint8_t data[THREEFISH256_BLOCKSIZE_B];
159 threefish256_ctx_t ctx;
161 cli_putstr_P(PSTR("\r\nThreefish-256 performance:"));
166 // memset(key, 0, THREEFISH256_BLOCKSIZE_B);
167 // memset(tweak, 0, 16);
170 threefish256_init(key, tweak, &ctx);
172 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
173 ultoa((unsigned long)t, str, 10);
177 threefish256_enc(data, &ctx);
179 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
180 ultoa((unsigned long)t, str, 10);
183 cli_putstr_P(PSTR("\r\n"));
186 void testrun_performance_threefish512(void){
189 uint8_t key[THREEFISH512_BLOCKSIZE_B];
190 uint8_t data[THREEFISH512_BLOCKSIZE_B];
192 threefish512_ctx_t ctx;
194 cli_putstr_P(PSTR("\r\nThreefish-512 performance:"));
199 // memset(key, 0, THREEFISH512_BLOCKSIZE_B);
200 // memset(tweak, 0, 16);
203 threefish512_init(key, tweak, &ctx);
205 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
206 ultoa((unsigned long)t, str, 10);
210 threefish512_enc(data, &ctx);
212 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
213 ultoa((unsigned long)t, str, 10);
216 cli_putstr_P(PSTR("\r\n"));
219 void testrun_performance_threefish1024(void){
222 uint8_t key[THREEFISH1024_BLOCKSIZE_B];
223 uint8_t data[THREEFISH1024_BLOCKSIZE_B];
225 threefish1024_ctx_t ctx;
227 cli_putstr_P(PSTR("\r\nThreefish-1024 performance:"));
232 // memset(key, 0, THREEFISH1024_BLOCKSIZE_B);
233 // memset(tweak, 0, 16);
236 threefish1024_init(key, tweak, &ctx);
238 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
239 ultoa((unsigned long)t, str, 10);
243 threefish1024_enc(data, &ctx);
245 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
246 ultoa((unsigned long)t, str, 10);
249 cli_putstr_P(PSTR("\r\n"));
252 void testrun_performance_threefish(void){
253 testrun_performance_threefish256();
254 testrun_performance_threefish512();
255 testrun_performance_threefish1024();
258 /*****************************************************************************
260 *****************************************************************************/
262 const char nessie_str[] PROGMEM = "nessie";
263 const char test_str[] PROGMEM = "test";
264 const char performance_str[] PROGMEM = "performance";
265 const char echo_str[] PROGMEM = "echo";
267 cmdlist_entry_t cmdlist[] PROGMEM = {
268 // { nessie_str, NULL, testrun_nessie_noekeon},
269 { test_str, NULL, testrun_stdtest_skein},
270 // { performance_str, NULL, testrun_performance_threefish},
271 { echo_str, (void*)1, (void_fpt)echo_ctrl},
281 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
282 cli_putstr(algo_name);
283 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
284 cmd_interface(cmdlist);