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