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