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