]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-skein-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-skein-test.c
1 /* main-skein-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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  * skein test-suit
21  *
22 */
23
24 #include "main-test-common.h"
25
26 #include "skein.h"
27 #include "hfal_skein256.h"
28 #include "hfal_skein512.h"
29 #include "hfal_skein1024.h"
30 #include "shavs.h"
31 #include "nessie_hash_test.h"
32 #include "performance_test.h"
33 #include "hfal-performance.h"
34 #include "hfal-nessie.h"
35 #include "hfal-basic.h"
36
37 char *algo_name = "Skein";
38
39 const hfdesc_t *const algolist[] PROGMEM = {
40         (hfdesc_t*)&skein256_128_desc,
41         (hfdesc_t*)&skein256_160_desc,
42         (hfdesc_t*)&skein256_224_desc,
43         (hfdesc_t*)&skein256_256_desc,
44         (hfdesc_t*)&skein256_384_desc,
45         (hfdesc_t*)&skein256_512_desc,
46
47         (hfdesc_t*)&skein512_128_desc,
48         (hfdesc_t*)&skein512_160_desc,
49         (hfdesc_t*)&skein512_224_desc,
50         (hfdesc_t*)&skein512_256_desc,
51         (hfdesc_t*)&skein512_384_desc,
52         (hfdesc_t*)&skein512_512_desc,
53         (hfdesc_t*)&skein512_1024_desc,
54
55         (hfdesc_t*)&skein1024_128_desc,
56         (hfdesc_t*)&skein1024_160_desc,
57         (hfdesc_t*)&skein1024_224_desc,
58         (hfdesc_t*)&skein1024_256_desc,
59         (hfdesc_t*)&skein1024_384_desc,
60         (hfdesc_t*)&skein1024_512_desc,
61         (hfdesc_t*)&skein1024_1024_desc,
62         NULL
63 };
64
65 /*****************************************************************************
66  *  additional validation-functions                                                                                      *
67  *****************************************************************************/
68 void testrun_stdtest_skein256(uint16_t outsize_b){
69         uint8_t message[64];
70         uint8_t hash[(outsize_b+7)/8];
71         uint8_t i;
72
73         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
74         for(i=0; i<64; ++i)
75                 message[i] = 0xFF-i;
76
77         cli_putstr_P(PSTR("\r\nmessage:    "));
78         cli_hexdump(message, 1);
79         skein256(hash, outsize_b, message, 8);
80         cli_putstr_P(PSTR("\r\nhash:"));
81         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
82
83         cli_putstr_P(PSTR("\r\nmessage:"));
84         cli_hexdump_block(message, 32, 4, 16);
85         skein256(hash, outsize_b, message, 32*8);
86         cli_putstr_P(PSTR("\r\nhash:"));
87         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
88
89         cli_putstr_P(PSTR("\r\nmessage:"));
90         cli_hexdump_block(message, 64, 4, 16);
91         skein256(hash, outsize_b, message, 64*8);
92         cli_putstr_P(PSTR("\r\nhash:"));
93         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
94 }
95
96 void testrun_stdtest_skein512(uint16_t outsize_b){
97         uint8_t message[128];
98         uint8_t hash[(outsize_b+7)/8];
99         uint8_t i;
100
101         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
102         for(i=0; i<128; ++i)
103                 message[i] = 0xFF-i;
104
105         cli_putstr_P(PSTR("\r\nmessage:    "));
106         cli_hexdump(message, 1);
107         skein512(hash, outsize_b, message, 8);
108         cli_putstr_P(PSTR("\r\nhash:"));
109         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
110
111         cli_putstr_P(PSTR("\r\nmessage:"));
112         cli_hexdump_block(message, 64, 4, 16);
113         skein512(hash, outsize_b, message, 64*8);
114         cli_putstr_P(PSTR("\r\nhash:"));
115         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
116
117         cli_putstr_P(PSTR("\r\nmessage:"));
118         cli_hexdump_block(message, 128, 4, 16);
119         skein512(hash, outsize_b, message, 128*8);
120         cli_putstr_P(PSTR("\r\nhash:"));
121         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
122 }
123
124 void testrun_stdtest_skein1024(uint16_t outsize_b){
125         uint8_t message[256];
126         uint8_t hash[(outsize_b+7)/8];
127         uint16_t i;
128
129         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
130         for(i=0; i<256; ++i)
131                 message[i] = 0xFF-i;
132
133         cli_putstr_P(PSTR("\r\nmessage:    "));
134         cli_hexdump(message, 1);
135         skein1024(hash, outsize_b, message, 8);
136         cli_putstr_P(PSTR("\r\nhash:"));
137         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
138
139         cli_putstr_P(PSTR("\r\nmessage:"));
140         cli_hexdump_block(message, 128, 4, 16);
141         skein1024(hash, outsize_b, message, 128*8);
142         cli_putstr_P(PSTR("\r\nhash:"));
143         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
144
145         cli_putstr_P(PSTR("\r\nmessage:"));
146         cli_hexdump_block(message, 256, 4, 16);
147         skein1024(hash, outsize_b, message, 256*8);
148         cli_putstr_P(PSTR("\r\nhash:"));
149         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
150 }
151
152 void testrun_stdtest_skein(void){
153         testrun_stdtest_skein256(256);
154         testrun_stdtest_skein512(512);
155         testrun_stdtest_skein1024(1024);
156 }
157
158 void zeromsg_test_skein(uint16_t outsize_b){
159         char str[8];
160         uint8_t hash[(outsize_b+7)/8];
161
162         skein256(hash, outsize_b, NULL, 0);
163         cli_putstr_P(PSTR("\r\nskein256-"));
164         utoa(outsize_b, str, 10);
165         cli_putstr(str);
166         cli_putstr_P(PSTR(" :"));
167         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
168
169         skein512(hash, outsize_b, NULL, 0);
170         cli_putstr_P(PSTR("\r\nskein512-"));
171         utoa(outsize_b, str, 10);
172         cli_putstr(str);
173         cli_putstr_P(PSTR(" :"));
174         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
175
176         skein1024(hash, outsize_b, NULL, 0);
177         cli_putstr_P(PSTR("\r\nskein1024-"));
178         utoa(outsize_b, str, 10);
179         cli_putstr(str);
180         cli_putstr_P(PSTR(" :"));
181         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
182 }
183
184 void zeromsg_test_common(char *p){
185         uint8_t i;
186         uint16_t s=0;
187         uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
188         if(p){
189                 s = strtoul(p, NULL, 0);
190         }
191         if(s){
192                 zeromsg_test_skein(s);
193         }else{
194                 for(i=0; i<7; ++i)
195                         zeromsg_test_skein(sizes[i]);
196         }
197 }
198
199 void performance_skein(void){
200         hfal_performance_multiple(algolist);
201 }
202
203 void testrun_nessie_skein(void){
204         nessie_hash_quick = 1;
205         hfal_nessie_multiple(algolist);
206 }
207
208 void test_monte2(void){
209         uint8_t data[] = {
210         0x6c, 0xd4, 0xc0, 0xc5, 0xcb, 0x2c, 0xa2, 0xa0,
211         0xf1, 0xd1, 0xae, 0xce, 0xba, 0xc0, 0x3b, 0x52,
212         0xe6, 0x4e, 0xa0, 0x3d, 0x1a, 0x16, 0x54, 0x37,
213         0x29, 0x36, 0x54, 0x5b, 0x92, 0xbb, 0xc5, 0x48,
214         0x4a, 0x59, 0xdb, 0x74, 0xbb, 0x60, 0xf9, 0xc4,
215         0x0c, 0xeb, 0x1a, 0x5a, 0xa3, 0x5a, 0x6f, 0xaf,
216         0xe8, 0x03, 0x49, 0xe1, 0x4c, 0x25, 0x3a, 0x4e,
217         0x8b, 0x1d, 0x77, 0x61, 0x2d, 0xdd, 0x81, 0xac,
218         0xe9, 0x26, 0xae, 0x8b, 0x0a, 0xf6, 0xe5, 0x31,
219         0x76, 0xdb, 0xff, 0xcc, 0x2a, 0x6b, 0x88, 0xc6,
220         0xbd, 0x76, 0x5f, 0x93, 0x9d, 0x3d, 0x17, 0x8a,
221         0x9b, 0xde, 0x9e, 0xf3, 0xaa, 0x13, 0x1c, 0x61,
222         0xe3, 0x1c, 0x1e, 0x42, 0xcd, 0xfa, 0xf4, 0xb4,
223         0xdc, 0xde, 0x57, 0x9a, 0x37, 0xe1, 0x50, 0xef,
224         0xbe, 0xf5, 0x55, 0x5b, 0x4c, 0x1c, 0xb4, 0x04,
225         0x39, 0xd8, 0x35, 0xa7, 0x24, 0xe2, 0xfa, 0xe7 };
226
227    uint8_t hash[256/8];
228    skein256(hash, 256, data, 1024);
229    cli_putstr_P(PSTR("\r\n hash(data) = "));
230    cli_hexdump(hash, 32);
231    hfal_hash_mem(&skein256_256_desc,hash, data, 1024);
232    cli_putstr_P(PSTR("\r\n hash(data) = "));
233    cli_hexdump(hash, 32);
234 }
235
236 /*****************************************************************************
237  *  main                                                                                                                                         *
238  *****************************************************************************/
239
240
241 const char nessie_str[]      PROGMEM = "nessie";
242 const char test_str[]        PROGMEM = "test";
243 const char ztest_str[]       PROGMEM = "zerotest";
244 const char performance_str[] PROGMEM = "performance";
245 const char echo_str[]        PROGMEM = "echo";
246 const char monte2_str[]      PROGMEM = "monte2";
247 const char shavs_list_str[]  PROGMEM = "shavs_list";
248 const char shavs_set_str[]   PROGMEM = "shavs_set";
249 const char shavs_test1_str[] PROGMEM = "shavs_test1";
250 const char shavs_test2_str[] PROGMEM = "shavs_test2";
251 const char shavs_test3_str[] PROGMEM = "shavs_test3";
252
253 const cmdlist_entry_t cmdlist[] PROGMEM = {
254         { nessie_str,          NULL, testrun_nessie_skein            },
255         { performance_str,     NULL, performance_skein               },
256         { test_str,            NULL, testrun_stdtest_skein           },
257         { ztest_str,       (void*)1, (void_fpt)zeromsg_test_common   },
258         { shavs_list_str,      NULL, shavs_listalgos                 },
259         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo         },
260         { monte2_str,          NULL, test_monte2                     },
261         { shavs_test1_str,     NULL, shavs_test1                     },
262         { shavs_test2_str,     NULL, shavs_test2                     },
263         { shavs_test3_str,     NULL, shavs_test3                     },
264         { echo_str,        (void*)1, (void_fpt)echo_ctrl             },
265         { NULL,                NULL, NULL                            }
266 };
267
268 int main (void){
269     main_setup();
270
271     shavs_algolist=(hfdesc_t**)algolist;
272         shavs_algo=(hfdesc_t*)&skein256_256_desc;
273
274         for(;;){
275             welcome_msg(algo_name);
276                 cmd_interface(cmdlist);
277         }
278 }