1 /* main-threefish-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/>.
29 #include "threefish.h"
31 #include "performance_test.h"
32 #include "bcal-performance.h"
33 #include "bcal-nessie.h"
34 #include "bcal_threefish256.h"
35 #include "bcal_threefish512.h"
36 #include "bcal_threefish1024.h"
42 char* algo_name = "Threefish";
44 const bcdesc_t* algolist[] PROGMEM = {
45 (bcdesc_t*)&threefish256_desc,
46 (bcdesc_t*)&threefish512_desc,
47 (bcdesc_t*)&threefish1024_desc,
50 /*****************************************************************************
51 * additional validation-functions *
52 *****************************************************************************/
54 void threefish256_dump(threefish256_ctx_t* ctx){
56 cli_putstr_P(PSTR("\r\n=== ctx dump (256) === \r\n k: "));
58 cli_hexdump(&(ctx->k[i]), 8);
61 cli_putstr_P(PSTR("\r\n t: "));
63 cli_hexdump(&(ctx->t[i]), 8);
68 void testrun_nessie_threefish(void){
69 bcal_nessie_multiple(algolist);
72 void testrun_stdtest_threefish256(void){
73 uint8_t key[32], data[32];
76 threefish256_ctx_t ctx;
78 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (256 bits):"));
83 cli_putstr_P(PSTR("\r\nkey: "));
84 cli_hexdump_block(key, 32, 4, 16);
85 cli_putstr_P(PSTR("\r\ntweak: "));
86 cli_hexdump_block(tweak, 16, 4, 16);
87 cli_putstr_P(PSTR("\r\nplain: "));
88 cli_hexdump_block(data, 32, 4, 16);
89 threefish256_init(key, tweak, &ctx);
90 threefish256_enc(data, &ctx);
91 cli_putstr_P(PSTR("\r\ncipher: "));
92 cli_hexdump_block(data, 32, 4, 16);
93 cli_putstr_P(PSTR("\r\ndecipher: "));
94 threefish256_dec(data, &ctx);
95 cli_hexdump_block(data, 32, 4, 16);
105 cli_putstr_P(PSTR("\r\nkey: "));
106 cli_hexdump_block(key, 32, 4, 16);
107 cli_putstr_P(PSTR("\r\ntweak: "));
108 cli_hexdump_block(tweak, 16, 4, 16);
109 cli_putstr_P(PSTR("\r\nplain: "));
110 cli_hexdump_block(data, 32, 4, 16);
111 threefish256_init(key, tweak, &ctx);
112 threefish256_enc(data, &ctx);
113 cli_putstr_P(PSTR("\r\ncipher: "));
114 cli_hexdump_block(data, 32, 4, 16);
115 cli_putstr_P(PSTR("\r\ndecipher: "));
116 threefish256_dec(data, &ctx);
117 cli_hexdump_block(data, 32, 4, 16);
120 void testrun_stdtest_threefish512(void){
121 uint8_t key[64], data[64];
124 threefish512_ctx_t ctx;
126 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (512 bits) :"));
129 memset(tweak, 0, 16);
131 cli_putstr_P(PSTR("\r\nkey: "));
132 cli_hexdump_block(key, 32, 4, 16);
133 cli_putstr_P(PSTR("\r\n "));
134 cli_hexdump_block(key+32, 32, 4, 16);
135 cli_putstr_P(PSTR("\r\ntweak: "));
136 cli_hexdump_block(tweak, 16, 4, 16);
137 cli_putstr_P(PSTR("\r\nplain: "));
138 cli_hexdump_block(data, 64, 4, 16);
139 threefish512_init(key, tweak, &ctx);
140 threefish512_enc(data, &ctx);
141 cli_putstr_P(PSTR("\r\ncipher: "));
142 cli_hexdump_block(data, 64, 4, 16);
143 threefish512_dec(data, &ctx);
144 cli_putstr_P(PSTR("\r\ndecipher: "));
145 cli_hexdump_block(data, 64, 4, 16);
155 cli_putstr_P(PSTR("\r\nkey: "));
156 cli_hexdump_block(key, 32, 4, 16);
157 cli_putstr_P(PSTR("\r\n "));
158 cli_hexdump_block(key+32, 32, 4, 16);
159 cli_putstr_P(PSTR("\r\ntweak: "));
160 cli_hexdump_block(tweak, 16, 4, 16);
161 cli_putstr_P(PSTR("\r\nplain: "));
162 cli_hexdump_block(data, 64, 4, 16);
163 threefish512_init(key, tweak, &ctx);
164 threefish512_enc(data, &ctx);
165 cli_putstr_P(PSTR("\r\ncipher: "));
166 cli_hexdump_block(data, 64, 4, 16);
167 threefish512_dec(data, &ctx);
168 cli_putstr_P(PSTR("\r\ndecipher: "));
169 cli_hexdump_block(data, 64, 4, 16);
173 void testrun_stdtest_threefish1024(void){
174 uint8_t key[128], data[128];
177 threefish1024_ctx_t ctx;
179 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (1024 bits) :"));
181 memset(data, 0, 128);
182 memset(tweak, 0, 16);
184 cli_putstr_P(PSTR("\r\nkey: "));
185 cli_hexdump_block(key, 128, 4, 16);
186 cli_putstr_P(PSTR("\r\ntweak: "));
187 cli_hexdump_block(tweak, 16, 4, 16);
188 cli_putstr_P(PSTR("\r\nplain: "));
189 cli_hexdump_block(data, 128, 4, 16);
190 threefish1024_init(key, tweak, &ctx);
191 threefish1024_enc(data, &ctx);
192 cli_putstr_P(PSTR("\r\ncipher: "));
193 cli_hexdump_block(data, 128, 4, 16);
194 threefish1024_dec(data, &ctx);
195 cli_putstr_P(PSTR("\r\ndecipher: "));
196 cli_hexdump_block(data, 128, 4, 16);
198 for(i=0; i<128; ++i){
205 cli_putstr_P(PSTR("\r\nkey: "));
206 cli_hexdump_block(key, 128, 4, 16);
207 cli_putstr_P(PSTR("\r\ntweak: "));
208 cli_hexdump_block(tweak, 16, 4, 16);
209 cli_putstr_P(PSTR("\r\nplain: "));
210 cli_hexdump_block(data, 128, 4, 16);
211 threefish1024_init(key, tweak, &ctx);
212 threefish1024_enc(data, &ctx);
213 cli_putstr_P(PSTR("\r\ncipher: "));
214 cli_hexdump_block(data, 128, 4, 16);
215 threefish1024_dec(data, &ctx);
216 cli_putstr_P(PSTR("\r\ndecipher: "));
217 cli_hexdump_block(data, 128, 4, 16);
221 void testrun_stdtest_threefish(void){
222 testrun_stdtest_threefish256();
223 testrun_stdtest_threefish512();
224 testrun_stdtest_threefish1024();
227 void testrun_performance_threefish(void){
228 bcal_performance_multiple(algolist);
231 void init_test(void){
232 threefish256_ctx_t ctx;
233 uint8_t key[32], tweak[16];
236 threefish256_init(key, tweak, &ctx);
237 cli_putstr_P(PSTR("\r\n ctx: \r\n\tk:"));
238 cli_hexdump(ctx.k, 5*8);
239 cli_putstr_P(PSTR("\r\n\tt:"));
240 cli_hexdump(ctx.t, 3*8);
244 /*****************************************************************************
246 *****************************************************************************/
248 const char nessie_str[] PROGMEM = "nessie";
249 const char test_str[] PROGMEM = "test";
250 const char test256_str[] PROGMEM = "test256";
251 const char test512_str[] PROGMEM = "test512";
252 const char test1024_str[] PROGMEM = "test1024";
253 const char inittest_str[] PROGMEM = "inittest";
254 const char performance_str[] PROGMEM = "performance";
255 const char echo_str[] PROGMEM = "echo";
257 cmdlist_entry_t cmdlist[] PROGMEM = {
258 { nessie_str, NULL, testrun_nessie_threefish},
259 { test_str, NULL, testrun_stdtest_threefish},
260 { test256_str, NULL, testrun_stdtest_threefish256},
261 { test512_str, NULL, testrun_stdtest_threefish512},
262 { test1024_str, NULL, testrun_stdtest_threefish1024},
263 { inittest_str, NULL, init_test},
264 { performance_str, NULL, testrun_performance_threefish},
265 { echo_str, (void*)1, (void_fpt)echo_ctrl},
272 cli_rx = (cli_rx_fpt)uart0_getc;
273 cli_tx = (cli_tx_fpt)uart0_putc;
275 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
276 cli_putstr(algo_name);
277 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
278 cmd_interface(cmdlist);