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