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 "serial-tools.h"
29 #include "threefish.h"
30 #include "nessie_bc_test.h"
32 #include "performance_test.h"
38 char* algo_name = "Threefish";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
43 void testrun_stdtest_threefish256(void){
44 uint8_t key[32], data[32];
47 threefish256_ctx_t ctx;
49 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (256 bits):"));
54 cli_putstr_P(PSTR("\r\nkey: "));
56 cli_putstr_P(PSTR("\r\ntweak: "));
57 cli_hexdump(tweak, 16);
58 cli_putstr_P(PSTR("\r\nplain: "));
59 cli_hexdump(data, 32);
60 threefish256_init(key, tweak, &ctx);
61 threefish256_enc(data, &ctx);
62 cli_putstr_P(PSTR("\r\ncipher: "));
63 cli_hexdump(data, 32);
72 cli_putstr_P(PSTR("\r\n\r\nkey: "));
74 cli_putstr_P(PSTR("\r\ntweak: "));
75 cli_hexdump(tweak, 16);
76 cli_putstr_P(PSTR("\r\nplain: "));
77 cli_hexdump(data, 32);
78 threefish256_init(key, tweak, &ctx);
79 threefish256_enc(data, &ctx);
80 cli_putstr_P(PSTR("\r\ncipher: "));
81 cli_hexdump(data, 32);
84 void testrun_stdtest_threefish512(void){
85 uint8_t key[64], data[64];
88 threefish512_ctx_t ctx;
90 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (512 bits) :"));
95 cli_putstr_P(PSTR("\r\nkey: "));
97 cli_putstr_P(PSTR("\r\n "));
98 cli_hexdump(key+32, 32);
99 cli_putstr_P(PSTR("\r\ntweak: "));
100 cli_hexdump(tweak, 16);
101 cli_putstr_P(PSTR("\r\nplain: "));
102 cli_hexdump(data, 32);
103 cli_putstr_P(PSTR("\r\n "));
104 cli_hexdump(data+32, 32);
105 threefish512_init(key, tweak, &ctx);
106 threefish512_enc(data, &ctx);
107 cli_putstr_P(PSTR("\r\ncipher: "));
108 cli_hexdump(data, 32);
109 cli_putstr_P(PSTR("\r\n "));
110 cli_hexdump(data+32, 32);
119 cli_putstr_P(PSTR("\r\n\r\nkey: "));
120 cli_hexdump(key, 32);
121 cli_putstr_P(PSTR("\r\n "));
122 cli_hexdump(key+32, 32);
123 cli_putstr_P(PSTR("\r\ntweak: "));
124 cli_hexdump(tweak, 16);
125 cli_putstr_P(PSTR("\r\nplain: "));
126 cli_hexdump(data, 32);
127 cli_putstr_P(PSTR("\r\n "));
128 cli_hexdump(data+32, 32);
129 threefish512_init(key, tweak, &ctx);
130 threefish512_enc(data, &ctx);
131 cli_putstr_P(PSTR("\r\ncipher: "));
132 cli_hexdump(data, 32);
133 cli_putstr_P(PSTR("\r\n "));
134 cli_hexdump(data+32, 32);
137 void testrun_stdtest_threefish1024(void){
138 uint8_t key[128], data[128];
141 threefish1024_ctx_t ctx;
143 cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (1024 bits) :"));
145 memset(data, 0, 128);
146 memset(tweak, 0, 16);
148 cli_putstr_P(PSTR("\r\nkey: "));
149 cli_hexdump(key, 32);
150 cli_putstr_P(PSTR("\r\n "));
151 cli_hexdump(key+32, 32);
152 cli_putstr_P(PSTR("\r\n "));
153 cli_hexdump(key+64, 32);
154 cli_putstr_P(PSTR("\r\n "));
155 cli_hexdump(key+96, 32);
156 cli_putstr_P(PSTR("\r\ntweak: "));
157 cli_hexdump(tweak, 16);
158 cli_putstr_P(PSTR("\r\nplain: "));
159 cli_hexdump(data, 32);
160 cli_putstr_P(PSTR("\r\n "));
161 cli_hexdump(data+32, 32);
162 cli_putstr_P(PSTR("\r\n "));
163 cli_hexdump(data+64, 32);
164 cli_putstr_P(PSTR("\r\n "));
165 cli_hexdump(data+96, 32);
166 threefish1024_init(key, tweak, &ctx);
167 threefish1024_enc(data, &ctx);
168 cli_putstr_P(PSTR("\r\ncipher: "));
169 cli_hexdump(data, 32);
170 cli_putstr_P(PSTR("\r\n "));
171 cli_hexdump(data+32, 32);
172 cli_putstr_P(PSTR("\r\n "));
173 cli_hexdump(data+64, 32);
174 cli_putstr_P(PSTR("\r\n "));
175 cli_hexdump(data+96, 32);
177 for(i=0; i<128; ++i){
184 cli_putstr_P(PSTR("\r\n\r\nkey: "));
185 cli_hexdump(key, 32);
186 cli_putstr_P(PSTR("\r\n "));
187 cli_hexdump(key+32, 32);
188 cli_putstr_P(PSTR("\r\n "));
189 cli_hexdump(key+64, 32);
190 cli_putstr_P(PSTR("\r\n "));
191 cli_hexdump(key+96, 32);
192 cli_putstr_P(PSTR("\r\ntweak: "));
193 cli_hexdump(tweak, 16);
194 cli_putstr_P(PSTR("\r\nplain: "));
195 cli_hexdump(data, 32);
196 cli_putstr_P(PSTR("\r\n "));
197 cli_hexdump(data+32, 32);
198 cli_putstr_P(PSTR("\r\n "));
199 cli_hexdump(data+64, 32);
200 cli_putstr_P(PSTR("\r\n "));
201 cli_hexdump(data+96, 32);
202 threefish1024_init(key, tweak, &ctx);
203 threefish1024_enc(data, &ctx);
204 cli_putstr_P(PSTR("\r\ncipher: "));
205 cli_hexdump(data, 32);
206 cli_putstr_P(PSTR("\r\n "));
207 cli_hexdump(data+32, 32);
208 cli_putstr_P(PSTR("\r\n "));
209 cli_hexdump(data+64, 32);
210 cli_putstr_P(PSTR("\r\n "));
211 cli_hexdump(data+96, 32);
215 void testrun_stdtest_threefish(void){
216 testrun_stdtest_threefish256();
217 testrun_stdtest_threefish512();
218 testrun_stdtest_threefish1024();
220 /*****************************************************************************
222 *****************************************************************************/
224 const char nessie_str[] PROGMEM = "nessie";
225 const char test_str[] PROGMEM = "test";
226 const char performance_str[] PROGMEM = "performance";
227 const char echo_str[] PROGMEM = "echo";
229 cmdlist_entry_t cmdlist[] PROGMEM = {
230 // { nessie_str, NULL, testrun_nessie_noekeon},
231 { test_str, NULL, testrun_stdtest_threefish},
232 // { performance_str, NULL, testrun_performance_noekeon},
233 { echo_str, (void*)1, (void_fpt)echo_ctrl},
243 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
244 cli_putstr(algo_name);
245 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
246 cmd_interface(cmdlist);