]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-ubi-test.c
backporting uart_i and cli
[avr-crypto-lib.git] / test_src / main-ubi-test.c
1 /* main-threefish-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_i.h"
27 #include "debug.h"
28
29 #include "ubi.h"
30 #include "cli.h"
31 #include "performance_test.h"
32
33 #include <stdint.h>
34 #include <string.h>
35 #include <stdlib.h>
36
37 char* algo_name = "UBI-Threefish";
38
39 /*****************************************************************************
40  *  additional validation-functions                                                                                      *
41  *****************************************************************************/
42 void testrun_stdtest_ubi256(uint16_t outsize){
43         ubi256_ctx_t ctx;
44         skein_config_t conf;
45         uint64_t iv[4];
46         
47         cli_putstr_P(PSTR("\r\n\r\nTest vectors for UBI (256 bits):"));
48         memset(&conf, 0, sizeof(skein_config_t));
49
50         ubi256_init(&ctx, &conf, UBI_TYPE_CFG);
51         conf.schema[0] = 'S';
52         conf.schema[1] = 'H';
53         conf.schema[2] = 'A';
54         conf.schema[3] = '3';
55         conf.version = 1;
56         conf.out_length = outsize;
57         ubi256_lastBlock(&ctx, &conf, 256);
58         ubi256_ctx2hash(iv, &ctx);
59                 
60         cli_putstr_P(PSTR("\r\nIV: "));
61         cli_hexdump_rev(&(iv[0]), 8);
62         cli_putstr_P(PSTR("    "));
63         cli_hexdump_rev(&(iv[1]), 8);
64         cli_putstr_P(PSTR("    "));
65         cli_hexdump_rev(&(iv[2]), 8);
66         cli_putstr_P(PSTR("    "));
67         cli_hexdump_rev(&(iv[3]), 8);
68 }
69
70 void testrun_stdtest_ubi512(uint16_t outsize){
71         ubi512_ctx_t ctx;
72         skein_config_t conf;
73         uint64_t iv[8];
74         uint8_t null[UBI512_BLOCKSIZE_B];
75         
76         cli_putstr_P(PSTR("\r\n\r\nTest vectors for UBI (512 bits):"));
77         memset(&conf, 0, sizeof(skein_config_t));
78         memset(null, 0, UBI512_BLOCKSIZE_B);
79         ubi512_init(&ctx, null, UBI_TYPE_CFG);
80         conf.schema[0] = 'S';
81         conf.schema[1] = 'H';
82         conf.schema[2] = 'A';
83         conf.schema[3] = '3';
84         conf.version = 1;
85         conf.out_length = outsize;
86         ubi512_lastBlock(&ctx, &conf, 256);
87         ubi512_ctx2hash(iv, &ctx);
88                 
89         cli_putstr_P(PSTR("\r\nIV: "));
90         cli_hexdump_rev(&(iv[0]), 8);
91         cli_putstr_P(PSTR("    "));
92         cli_hexdump_rev(&(iv[1]), 8);
93         cli_putstr_P(PSTR("    "));
94         cli_hexdump_rev(&(iv[2]), 8);
95         cli_putstr_P(PSTR("    "));
96         cli_hexdump_rev(&(iv[3]), 8);
97         cli_putstr_P(PSTR("\r\n    "));
98         cli_hexdump_rev(&(iv[4]), 8);
99         cli_putstr_P(PSTR("    "));
100         cli_hexdump_rev(&(iv[5]), 8);
101         cli_putstr_P(PSTR("    "));
102         cli_hexdump_rev(&(iv[6]), 8);
103         cli_putstr_P(PSTR("    "));
104         cli_hexdump_rev(&(iv[7]), 8);
105 }
106
107 void testrun_stdtest_ubi1024(uint16_t outsize){
108         ubi1024_ctx_t ctx;
109         skein_config_t conf;
110         uint64_t iv[16];
111         uint8_t null[UBI1024_BLOCKSIZE_B];
112         
113         cli_putstr_P(PSTR("\r\n\r\nTest vectors for UBI (1024 bits):"));
114         memset(&conf, 0, sizeof(skein_config_t));
115
116         memset(null, 0, UBI1024_BLOCKSIZE_B);
117         ubi1024_init(&ctx, null, UBI_TYPE_CFG);
118         conf.schema[0] = 'S';
119         conf.schema[1] = 'H';
120         conf.schema[2] = 'A';
121         conf.schema[3] = '3';
122         conf.version = 1;
123         conf.out_length = outsize;
124         ubi1024_lastBlock(&ctx, &conf, 256);
125         ubi1024_ctx2hash(iv, &ctx);
126                 
127         cli_putstr_P(PSTR("\r\nIV: "));
128         cli_hexdump_rev(&(iv[0]), 8);
129         cli_putstr_P(PSTR("    "));
130         cli_hexdump_rev(&(iv[1]), 8);
131         cli_putstr_P(PSTR("    "));
132         cli_hexdump_rev(&(iv[2]), 8);
133         cli_putstr_P(PSTR("    "));
134         cli_hexdump_rev(&(iv[3]), 8);
135         cli_putstr_P(PSTR("\r\n    "));
136         cli_hexdump_rev(&(iv[4]), 8);
137         cli_putstr_P(PSTR("    "));
138         cli_hexdump_rev(&(iv[5]), 8);
139         cli_putstr_P(PSTR("    "));
140         cli_hexdump_rev(&(iv[6]), 8);
141         cli_putstr_P(PSTR("    "));
142         cli_hexdump_rev(&(iv[7]), 8);
143         cli_putstr_P(PSTR("\r\n    "));
144         cli_hexdump_rev(&(iv[8]), 8);
145         cli_putstr_P(PSTR("    "));
146         cli_hexdump_rev(&(iv[9]), 8);
147         cli_putstr_P(PSTR("    "));
148         cli_hexdump_rev(&(iv[10]), 8);
149         cli_putstr_P(PSTR("    "));
150         cli_hexdump_rev(&(iv[11]), 8);
151         cli_putstr_P(PSTR("\r\n    "));
152         cli_hexdump_rev(&(iv[12]), 8);
153         cli_putstr_P(PSTR("    "));
154         cli_hexdump_rev(&(iv[13]), 8);
155         cli_putstr_P(PSTR("    "));
156         cli_hexdump_rev(&(iv[14]), 8);
157         cli_putstr_P(PSTR("    "));
158         cli_hexdump_rev(&(iv[15]), 8);
159 }
160
161 void testrun_stdtest_ubi(void){
162         testrun_stdtest_ubi256(128);
163         testrun_stdtest_ubi256(160);
164         testrun_stdtest_ubi256(224);
165         testrun_stdtest_ubi256(256);
166         
167         testrun_stdtest_ubi512(128);
168         testrun_stdtest_ubi512(160);
169         testrun_stdtest_ubi512(224);
170         testrun_stdtest_ubi512(256);
171         testrun_stdtest_ubi512(384);
172         testrun_stdtest_ubi512(512);
173         
174         testrun_stdtest_ubi1024(384);
175         testrun_stdtest_ubi1024(512);
176         testrun_stdtest_ubi1024(1024);
177 }
178
179 /*****************************************************************************
180  *  main                                                                                                                                         *
181  *****************************************************************************/
182
183 const char nessie_str[]      PROGMEM = "nessie";
184 const char test_str[]        PROGMEM = "test";
185 const char performance_str[] PROGMEM = "performance";
186 const char echo_str[]        PROGMEM = "echo";
187
188 cmdlist_entry_t cmdlist[] PROGMEM = {
189 //      { nessie_str,      NULL, testrun_nessie_noekeon},
190         { test_str,        NULL, testrun_stdtest_ubi},
191 //      { performance_str, NULL, testrun_performance_noekeon},
192         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
193         { NULL,            NULL, NULL}
194 };
195
196 int main (void){
197         DEBUG_INIT();
198         
199         cli_rx = (cli_rx_fpt)uart0_getc;
200         cli_tx = (cli_tx_fpt)uart0_putc;                
201         for(;;){
202                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
203                 cli_putstr(algo_name);
204                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
205                 cmd_interface(cmdlist);
206         }
207 }