]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-threefish-test.c
+threefish +ubi
[avr-crypto-lib.git] / test_src / main-threefish-test.c
1 /* main-threefish-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * threefish test-suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "threefish.h"
30 #include "nessie_bc_test.h"
31 #include "cli.h"
32 #include "performance_test.h"
33
34 #include <stdint.h>
35 #include <string.h>
36 #include <stdlib.h>
37
38 char* algo_name = "Threefish";
39
40 /*****************************************************************************
41  *  additional validation-functions                                                                                      *
42  *****************************************************************************/
43 void testrun_stdtest_threefish256(void){
44         uint8_t key[32], data[32];
45         uint8_t tweak[16];
46         uint8_t i;
47         threefish256_ctx_t ctx;
48         
49         cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (256 bits):"));
50         memset(key,  0, 32);
51         memset(data, 0, 32);
52         memset(tweak, 0, 16);
53         
54         cli_putstr_P(PSTR("\r\nkey:    "));
55         cli_hexdump(key, 32);
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);
64         
65         for(i=0; i<32; ++i){
66                 key[i] = 0x10+i;
67                 data[i] = 0xFF-i;
68         }
69         for(i=0; i<16; ++i){
70                 tweak[i] = i;
71         }
72         cli_putstr_P(PSTR("\r\n\r\nkey:    "));
73         cli_hexdump(key, 32);
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);
82 }
83
84 void testrun_stdtest_threefish512(void){
85         uint8_t key[64], data[64];
86         uint8_t tweak[16];
87         uint8_t i;
88         threefish512_ctx_t ctx;
89         
90         cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (512 bits) :"));
91         memset(key,  0, 64);
92         memset(data, 0, 64);
93         memset(tweak, 0, 16);
94         
95         cli_putstr_P(PSTR("\r\nkey:    "));
96         cli_hexdump(key, 32);
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);
111         
112         for(i=0; i<64; ++i){
113                 key[i] = 0x10+i;
114                 data[i] = 0xFF-i;
115         }
116         for(i=0; i<16; ++i){
117                 tweak[i] = i;
118         }
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);
135 }
136
137 void testrun_stdtest_threefish1024(void){
138         uint8_t key[128], data[128];
139         uint8_t tweak[16];
140         uint8_t i;
141         threefish1024_ctx_t ctx;
142         
143         cli_putstr_P(PSTR("\r\n\r\nTest vectors for block cipher Threefish (1024 bits) :"));
144         memset(key,  0, 128);
145         memset(data, 0, 128);
146         memset(tweak, 0, 16);
147         
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);
176         
177         for(i=0; i<128; ++i){
178                 key[i] = 0x10+i;
179                 data[i] = 0xFF-i;
180         }
181         for(i=0; i<16; ++i){
182                 tweak[i] = i;
183         }
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);
212         }
213
214
215 void testrun_stdtest_threefish(void){
216         testrun_stdtest_threefish256();
217         testrun_stdtest_threefish512();
218         testrun_stdtest_threefish1024();
219 }
220 /*****************************************************************************
221  *  main                                                                                                                                         *
222  *****************************************************************************/
223
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";
228
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},
234         { NULL,            NULL, NULL}
235 };
236
237 int main (void){
238         DEBUG_INIT();
239         
240         cli_rx = uart_getc;
241         cli_tx = uart_putc;             
242         for(;;){
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);
247         }
248 }