]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-skein-test.c
backporting uart_i and cli
[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) 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  * skein test-suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "skein.h"
30 #include "hfal_skein256.h"
31 #include "hfal_skein512.h"
32 #include "hfal_skein1024.h"
33 #include "cli.h"
34 #include "shavs.h"
35 #include "nessie_hash_test.h"
36 #include "performance_test.h"
37 #include "hfal-performance.h"
38 #include "hfal-nessie.h"
39
40
41 #include <stdint.h>
42 #include <string.h>
43 #include <stdlib.h>
44
45 char* algo_name = "Skein";
46
47 const hfdesc_t* algolist[] PROGMEM = {
48         (hfdesc_t*)&skein256_128_desc,
49         (hfdesc_t*)&skein256_160_desc,
50         (hfdesc_t*)&skein256_224_desc,
51         (hfdesc_t*)&skein256_256_desc,
52         (hfdesc_t*)&skein256_384_desc,
53         (hfdesc_t*)&skein256_512_desc,
54         
55         (hfdesc_t*)&skein512_128_desc,
56         (hfdesc_t*)&skein512_160_desc,
57         (hfdesc_t*)&skein512_224_desc,
58         (hfdesc_t*)&skein512_256_desc,
59         (hfdesc_t*)&skein512_384_desc,
60         (hfdesc_t*)&skein512_512_desc,
61         (hfdesc_t*)&skein512_1024_desc,
62         
63         (hfdesc_t*)&skein1024_128_desc,
64         (hfdesc_t*)&skein1024_160_desc,
65         (hfdesc_t*)&skein1024_224_desc,
66         (hfdesc_t*)&skein1024_256_desc,
67         (hfdesc_t*)&skein1024_384_desc,
68         (hfdesc_t*)&skein1024_512_desc,
69         (hfdesc_t*)&skein1024_1024_desc,
70         NULL
71 };
72
73 /*****************************************************************************
74  *  additional validation-functions                                                                                      *
75  *****************************************************************************/
76 void testrun_stdtest_skein256(uint16_t outsize_b){
77         uint8_t message[64];
78         uint8_t hash[(outsize_b+7)/8];
79         uint8_t i;
80                 
81         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (256 bits):"));
82         for(i=0; i<64; ++i)
83                 message[i] = 0xFF-i;
84         
85         cli_putstr_P(PSTR("\r\nmessage:    "));
86         cli_hexdump(message, 1);
87         skein256(hash, outsize_b, message, 8);
88         cli_putstr_P(PSTR("\r\nhash:"));
89         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
90         
91         cli_putstr_P(PSTR("\r\nmessage:"));
92         cli_hexdump_block(message, 32, 4, 16);
93         skein256(hash, outsize_b, message, 32*8);
94         cli_putstr_P(PSTR("\r\nhash:"));
95         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
96         
97         cli_putstr_P(PSTR("\r\nmessage:"));
98         cli_hexdump_block(message, 64, 4, 16);
99         skein256(hash, outsize_b, message, 64*8);
100         cli_putstr_P(PSTR("\r\nhash:"));
101         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
102 }
103
104 void testrun_stdtest_skein512(uint16_t outsize_b){
105         uint8_t message[128];
106         uint8_t hash[(outsize_b+7)/8];
107         uint8_t i;
108                 
109         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (512 bits):"));
110         for(i=0; i<128; ++i)
111                 message[i] = 0xFF-i;
112         
113         cli_putstr_P(PSTR("\r\nmessage:    "));
114         cli_hexdump(message, 1);
115         skein512(hash, outsize_b, message, 8);
116         cli_putstr_P(PSTR("\r\nhash:"));
117         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
118         
119         cli_putstr_P(PSTR("\r\nmessage:"));
120         cli_hexdump_block(message, 64, 4, 16);
121         skein512(hash, outsize_b, message, 64*8);
122         cli_putstr_P(PSTR("\r\nhash:"));
123         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
124         
125         cli_putstr_P(PSTR("\r\nmessage:"));
126         cli_hexdump_block(message, 128, 4, 16);
127         skein512(hash, outsize_b, message, 128*8);
128         cli_putstr_P(PSTR("\r\nhash:"));
129         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
130 }
131
132 void testrun_stdtest_skein1024(uint16_t outsize_b){
133         uint8_t message[256];
134         uint8_t hash[(outsize_b+7)/8];
135         uint16_t i;
136                 
137         cli_putstr_P(PSTR("\r\n\r\nTest vectors for Skein (1024 bits):"));
138         for(i=0; i<256; ++i)
139                 message[i] = 0xFF-i;
140         
141         cli_putstr_P(PSTR("\r\nmessage:    "));
142         cli_hexdump(message, 1);
143         skein1024(hash, outsize_b, message, 8);
144         cli_putstr_P(PSTR("\r\nhash:"));
145         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
146         
147         cli_putstr_P(PSTR("\r\nmessage:"));
148         cli_hexdump_block(message, 128, 4, 16);
149         skein1024(hash, outsize_b, message, 128*8);
150         cli_putstr_P(PSTR("\r\nhash:"));
151         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
152         
153         cli_putstr_P(PSTR("\r\nmessage:"));
154         cli_hexdump_block(message, 256, 4, 16);
155         skein1024(hash, outsize_b, message, 256*8);
156         cli_putstr_P(PSTR("\r\nhash:"));
157         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
158 }
159
160 void testrun_stdtest_skein(void){
161         testrun_stdtest_skein256(256);
162         testrun_stdtest_skein512(512);
163         testrun_stdtest_skein1024(1024);
164 }
165
166 void zeromsg_test_skein(uint16_t outsize_b){
167         char str[8];
168         uint8_t hash[(outsize_b+7)/8];
169         
170         skein256(hash, outsize_b, NULL, 0);
171         cli_putstr_P(PSTR("\r\nskein256-"));
172         utoa(outsize_b, str, 10);
173         cli_putstr(str);
174         cli_putstr_P(PSTR(" :"));
175         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
176         
177         skein512(hash, outsize_b, NULL, 0);
178         cli_putstr_P(PSTR("\r\nskein512-"));
179         utoa(outsize_b, str, 10);
180         cli_putstr(str);
181         cli_putstr_P(PSTR(" :"));
182         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
183         
184         skein1024(hash, outsize_b, NULL, 0);
185         cli_putstr_P(PSTR("\r\nskein1024-"));
186         utoa(outsize_b, str, 10);
187         cli_putstr(str);
188         cli_putstr_P(PSTR(" :"));
189         cli_hexdump_block(hash, (outsize_b+7)/8, 4, 16);
190 }
191
192 void zeromsg_test_common(char* p){
193         uint8_t i;
194         uint16_t s=0;
195         uint16_t sizes[]={128, 160, 224, 256, 384, 512, 1024};
196         if(p){
197                 s = strtoul(p, NULL, 0);
198         }
199         if(s){
200                 zeromsg_test_skein(s);
201         }else{
202                 for(i=0; i<7; ++i)
203                         zeromsg_test_skein(sizes[i]);
204         }
205 }
206
207 void performance_skein(void){
208         hfal_performance_multiple(algolist);
209 }
210
211 void testrun_nessie_skein(void){
212         nessie_hash_quick = 1;
213         hfal_nessie_multiple(algolist);
214 }
215
216
217 /*****************************************************************************
218  *  main                                                                                                                                         *
219  *****************************************************************************/
220
221
222 const char nessie_str[]      PROGMEM = "nessie";
223 const char test_str[]        PROGMEM = "test";
224 const char ztest_str[]       PROGMEM = "zerotest";
225 const char performance_str[] PROGMEM = "performance";
226 const char echo_str[]        PROGMEM = "echo";
227 const char shavs_list_str[]  PROGMEM = "shavs_list";
228 const char shavs_set_str[]   PROGMEM = "shavs_set";
229 const char shavs_test1_str[] PROGMEM = "shavs_test1";
230
231 cmdlist_entry_t cmdlist[] PROGMEM = {
232         { nessie_str,          NULL, testrun_nessie_skein},
233         { performance_str,     NULL, performance_skein},
234         { test_str,            NULL, testrun_stdtest_skein},
235         { ztest_str,       (void*)1, (void_fpt)zeromsg_test_common},
236         { shavs_list_str,      NULL, shavs_listalgos},
237         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
238         { shavs_test1_str,     NULL, shavs_test1},
239         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
240         { NULL,                NULL, NULL}
241 };
242
243 int main (void){
244         DEBUG_INIT();
245         
246         cli_rx = (cli_rx_fpt)uart0_getc;
247         cli_tx = (cli_tx_fpt)uart0_putc;                
248         shavs_algolist=(hfdesc_t**)algolist;
249         shavs_algo=(hfdesc_t*)&skein256_256_desc;
250         for(;;){
251                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
252                 cli_putstr(algo_name);
253                 cli_putstr_P(PSTR("; "));
254                 cli_putstr(__DATE__);
255                 cli_putstr_P(PSTR(" "));
256                 cli_putstr(__TIME__);
257                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
258                 
259                 cmd_interface(cmdlist);
260         }
261 }