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