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/>.
25 #include "main-test-common.h"
27 #include "threefish.h"
28 #include "performance_test.h"
29 #include "bcal-performance.h"
30 #include "bcal-nessie.h"
31 #include "bcal_threefish256.h"
32 #include "bcal_threefish512.h"
33 #include "bcal_threefish1024.h"
35 char* algo_name = "Threefish";
37 const bcdesc_t* const algolist[] PROGMEM = {
38 (bcdesc_t*)&threefish256_desc,
39 (bcdesc_t*)&threefish512_desc,
40 (bcdesc_t*)&threefish1024_desc,
43 /*****************************************************************************
44 * additional validation-functions *
45 *****************************************************************************/
47 void threefish256_dump(threefish256_ctx_t* ctx){
49 cli_putstr_P(PSTR("\r\n=== ctx dump (256) === \r\n k: "));
51 cli_hexdump(&(ctx->k[i]), 8);
54 cli_putstr_P(PSTR("\r\n t: "));
56 cli_hexdump(&(ctx->t[i]), 8);
61 void testrun_nessie_threefish(void){
62 bcal_nessie_multiple(algolist);
65 void testrun_stdtest_threefish256(void){
66 uint8_t key[32], data[32];
69 threefish256_ctx_t ctx;
71 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (256 bits):"));
76 cli_putstr_P(PSTR("\r\nkey: "));
77 cli_hexdump_block(key, 32, 4, 16);
78 cli_putstr_P(PSTR("\r\ntweak: "));
79 cli_hexdump_block(tweak, 16, 4, 16);
80 cli_putstr_P(PSTR("\r\nplain: "));
81 cli_hexdump_block(data, 32, 4, 16);
82 threefish256_init(key, tweak, &ctx);
83 threefish256_enc(data, &ctx);
84 cli_putstr_P(PSTR("\r\ncipher: "));
85 cli_hexdump_block(data, 32, 4, 16);
86 cli_putstr_P(PSTR("\r\ndecipher: "));
87 threefish256_dec(data, &ctx);
88 cli_hexdump_block(data, 32, 4, 16);
98 cli_putstr_P(PSTR("\r\nkey: "));
99 cli_hexdump_block(key, 32, 4, 16);
100 cli_putstr_P(PSTR("\r\ntweak: "));
101 cli_hexdump_block(tweak, 16, 4, 16);
102 cli_putstr_P(PSTR("\r\nplain: "));
103 cli_hexdump_block(data, 32, 4, 16);
104 threefish256_init(key, tweak, &ctx);
105 threefish256_enc(data, &ctx);
106 cli_putstr_P(PSTR("\r\ncipher: "));
107 cli_hexdump_block(data, 32, 4, 16);
108 cli_putstr_P(PSTR("\r\ndecipher: "));
109 threefish256_dec(data, &ctx);
110 cli_hexdump_block(data, 32, 4, 16);
113 void testrun_stdtest_threefish512(void){
114 uint8_t key[64], data[64];
117 threefish512_ctx_t ctx;
119 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (512 bits) :"));
122 memset(tweak, 0, 16);
124 cli_putstr_P(PSTR("\r\nkey: "));
125 cli_hexdump_block(key, 32, 4, 16);
126 cli_putstr_P(PSTR("\r\n "));
127 cli_hexdump_block(key+32, 32, 4, 16);
128 cli_putstr_P(PSTR("\r\ntweak: "));
129 cli_hexdump_block(tweak, 16, 4, 16);
130 cli_putstr_P(PSTR("\r\nplain: "));
131 cli_hexdump_block(data, 64, 4, 16);
132 threefish512_init(key, tweak, &ctx);
133 threefish512_enc(data, &ctx);
134 cli_putstr_P(PSTR("\r\ncipher: "));
135 cli_hexdump_block(data, 64, 4, 16);
136 threefish512_dec(data, &ctx);
137 cli_putstr_P(PSTR("\r\ndecipher: "));
138 cli_hexdump_block(data, 64, 4, 16);
148 cli_putstr_P(PSTR("\r\nkey: "));
149 cli_hexdump_block(key, 32, 4, 16);
150 cli_putstr_P(PSTR("\r\n "));
151 cli_hexdump_block(key+32, 32, 4, 16);
152 cli_putstr_P(PSTR("\r\ntweak: "));
153 cli_hexdump_block(tweak, 16, 4, 16);
154 cli_putstr_P(PSTR("\r\nplain: "));
155 cli_hexdump_block(data, 64, 4, 16);
156 threefish512_init(key, tweak, &ctx);
157 threefish512_enc(data, &ctx);
158 cli_putstr_P(PSTR("\r\ncipher: "));
159 cli_hexdump_block(data, 64, 4, 16);
160 threefish512_dec(data, &ctx);
161 cli_putstr_P(PSTR("\r\ndecipher: "));
162 cli_hexdump_block(data, 64, 4, 16);
166 void testrun_stdtest_threefish1024(void){
167 uint8_t key[128], data[128];
170 threefish1024_ctx_t ctx;
172 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (1024 bits) :"));
174 memset(data, 0, 128);
175 memset(tweak, 0, 16);
177 cli_putstr_P(PSTR("\r\nkey: "));
178 cli_hexdump_block(key, 128, 4, 16);
179 cli_putstr_P(PSTR("\r\ntweak: "));
180 cli_hexdump_block(tweak, 16, 4, 16);
181 cli_putstr_P(PSTR("\r\nplain: "));
182 cli_hexdump_block(data, 128, 4, 16);
183 threefish1024_init(key, tweak, &ctx);
184 threefish1024_enc(data, &ctx);
185 cli_putstr_P(PSTR("\r\ncipher: "));
186 cli_hexdump_block(data, 128, 4, 16);
187 threefish1024_dec(data, &ctx);
188 cli_putstr_P(PSTR("\r\ndecipher: "));
189 cli_hexdump_block(data, 128, 4, 16);
191 for(i=0; i<128; ++i){
198 cli_putstr_P(PSTR("\r\nkey: "));
199 cli_hexdump_block(key, 128, 4, 16);
200 cli_putstr_P(PSTR("\r\ntweak: "));
201 cli_hexdump_block(tweak, 16, 4, 16);
202 cli_putstr_P(PSTR("\r\nplain: "));
203 cli_hexdump_block(data, 128, 4, 16);
204 threefish1024_init(key, tweak, &ctx);
205 threefish1024_enc(data, &ctx);
206 cli_putstr_P(PSTR("\r\ncipher: "));
207 cli_hexdump_block(data, 128, 4, 16);
208 threefish1024_dec(data, &ctx);
209 cli_putstr_P(PSTR("\r\ndecipher: "));
210 cli_hexdump_block(data, 128, 4, 16);
214 void testrun_stdtest_threefish(void){
215 testrun_stdtest_threefish256();
216 testrun_stdtest_threefish512();
217 testrun_stdtest_threefish1024();
220 void testrun_performance_threefish(void){
221 bcal_performance_multiple(algolist);
224 void init_test(void){
225 threefish256_ctx_t ctx;
226 uint8_t key[32], tweak[16];
229 threefish256_init(key, tweak, &ctx);
230 cli_putstr_P(PSTR("\r\n ctx: \r\n\tk:"));
231 cli_hexdump(ctx.k, 5*8);
232 cli_putstr_P(PSTR("\r\n\tt:"));
233 cli_hexdump(ctx.t, 3*8);
237 /*****************************************************************************
239 *****************************************************************************/
241 const char nessie_str[] PROGMEM = "nessie";
242 const char test_str[] PROGMEM = "test";
243 const char test256_str[] PROGMEM = "test256";
244 const char test512_str[] PROGMEM = "test512";
245 const char test1024_str[] PROGMEM = "test1024";
246 const char inittest_str[] PROGMEM = "inittest";
247 const char performance_str[] PROGMEM = "performance";
248 const char echo_str[] PROGMEM = "echo";
250 const cmdlist_entry_t cmdlist[] PROGMEM = {
251 { nessie_str, NULL, testrun_nessie_threefish},
252 { test_str, NULL, testrun_stdtest_threefish},
253 { test256_str, NULL, testrun_stdtest_threefish256},
254 { test512_str, NULL, testrun_stdtest_threefish512},
255 { test1024_str, NULL, testrun_stdtest_threefish1024},
256 { inittest_str, NULL, init_test},
257 { performance_str, NULL, testrun_performance_threefish},
258 { echo_str, (void*)1, (void_fpt)echo_ctrl},
266 welcome_msg(algo_name);
267 cmd_interface(cmdlist);