]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-shabal-test.c
bcdc57aeef20e90b94527ff138a191221ce71868
[avr-crypto-lib.git] / test_src / main-shabal-test.c
1 /* main-shabal-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  * shabal test-suit
21  *
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "shabal.h"
30 #include "cli.h"
31 #include "hfal_shabal.h"
32 #include "hfal-test.h"
33 #include "hfal-nessie.h"
34 #include "hfal-performance.h"
35 #include "shavs.h"
36 #include "nessie_hash_test.h"
37 #include "performance_test.h"
38
39 #include <stdint.h>
40 #include <string.h>
41 #include <stdlib.h>
42
43 char* algo_name = "Shabal";
44
45
46 const hfdesc_t* algolist[] PROGMEM = {
47         (hfdesc_t*)&shabal192_desc,
48         (hfdesc_t*)&shabal224_desc,
49         (hfdesc_t*)&shabal256_desc,
50         (hfdesc_t*)&shabal384_desc,
51         (hfdesc_t*)&shabal512_desc,
52         NULL
53 };
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58 void testrun_stdtest_shabal192(void* msg, uint16_t size_b){
59         hfal_test(&shabal192_desc, msg, size_b);
60 }
61
62 void testrun_stdtest_shabal224(void* msg, uint16_t size_b){
63         hfal_test(&shabal224_desc, msg, size_b);
64 }
65
66 void testrun_stdtest_shabal256(void* msg, uint16_t size_b){
67         hfal_test(&shabal256_desc, msg, size_b);
68 }
69
70 void testrun_stdtest_shabal384(void* msg, uint16_t size_b){
71         hfal_test(&shabal384_desc, msg, size_b);
72 }
73
74 void testrun_stdtest_shabal512(void* msg, uint16_t size_b){
75         hfal_test(&shabal512_desc, msg, size_b);
76 }
77
78 void testrun_stdtest_shabal(void){
79         uint8_t ma[64];
80         char*   mb= "abcdefghijklmnopqrstuvwxyz-"
81                     "0123456789-"
82                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
83                 "0123456789-"
84                                 "abcdefghijklmnopqrstuvwxyz";
85
86         memset(ma, 0, 64);
87         testrun_stdtest_shabal192(ma, 64*8);
88         testrun_stdtest_shabal192(mb, strlen(mb)*8);
89         testrun_stdtest_shabal224(ma, 64*8);
90         testrun_stdtest_shabal224(mb, strlen(mb)*8);
91         testrun_stdtest_shabal256(ma, 64*8);
92         testrun_stdtest_shabal256(mb, strlen(mb)*8);
93         testrun_stdtest_shabal384(ma, 64*8);
94         testrun_stdtest_shabal384(mb, strlen(mb)*8);
95         testrun_stdtest_shabal512(ma, 64*8);
96         testrun_stdtest_shabal512(mb, strlen(mb)*8);
97 }
98
99 void testshort(void){
100         uint8_t ma[64];
101         memset(ma, 0, 64);
102         testrun_stdtest_shabal192(ma, 64*8);
103 }
104
105 void shabal_ctx_dump(shabal_ctx_t* ctx){
106         uint8_t i;
107         void* p;
108         cli_putstr_P(PSTR("\r\n=== shabal ctx dump ===\r\n  size = "));
109         i=sizeof(shabal_ctx_t);
110         if(i>=100)
111                 cli_putc('0'+i/100);
112         if(i>=10)
113                 cli_putc('0'+(i/10)%10);
114         cli_putc('0'+i%10);
115         cli_putstr_P(PSTR("\r\n  a = "));
116         cli_hexdump_block(ctx->a, 12*4, 5, 4*8);
117         cli_putstr_P(PSTR("\r\n  b_buffer = "));
118         cli_hexdump_block(ctx->b_buffer, 12*4, 5, 4*8);
119         cli_putstr_P(PSTR("\r\n  c_buffer = "));
120         cli_hexdump_block(ctx->c_buffer, 12*4, 5, 4*8);
121         if(ctx->b == &(ctx->b_buffer[0]))
122                 cli_putstr_P(PSTR("\r\nb --> b_buffer"));
123         if(ctx->b == &(ctx->c_buffer[0]))
124                 cli_putstr_P(PSTR("\r\nb --> c_buffer"));
125         if(ctx->c == &(ctx->b_buffer[0]))
126                 cli_putstr_P(PSTR("\r\nc --> b_buffer"));
127         if(ctx->c == &(ctx->c_buffer[0]))
128                 cli_putstr_P(PSTR("\r\nc --> c_buffer"));
129         cli_putstr_P(PSTR("\r\n b = "));
130         cli_hexdump(&(ctx->b), 2);
131         p = ctx->b_buffer;
132         cli_putstr_P(PSTR("\r\n b (should) = "));
133         cli_hexdump(&p, 2);
134         cli_putstr_P(PSTR("\r\n c = "));
135         cli_hexdump(&(ctx->c), 2);
136         p = ctx->c_buffer;
137         cli_putstr_P(PSTR("\r\n c (should) = "));
138         cli_hexdump(&p, 2);
139 }
140
141
142 void testinit_192(void){
143         shabal_ctx_t ctx;
144         shabal192_init(&ctx);
145         shabal_ctx_dump(&ctx);
146 }
147
148 void testinit_224(void){
149         shabal_ctx_t ctx;
150         shabal224_init(&ctx);
151         shabal_ctx_dump(&ctx);
152 }
153
154 void testinit_256(void){
155         shabal_ctx_t ctx;
156         shabal256_init(&ctx);
157         shabal_ctx_dump(&ctx);
158 }
159
160 void testinit_384(void){
161         shabal_ctx_t ctx;
162         shabal384_init(&ctx);
163         shabal_ctx_dump(&ctx);
164 }
165
166 void testinit_512(void){
167         shabal_ctx_t ctx;
168         shabal512_init(&ctx);
169         shabal_ctx_dump(&ctx);
170 }
171 void testinit(void){
172         testinit_192();
173         testinit_224();
174         testinit_256();
175         testinit_384();
176         testinit_512();
177 }
178
179 void performance_shabal(void){
180         hfal_performance_multiple(algolist);
181 }
182
183 void testrun_nessie_shabal(void){
184         hfal_nessie_multiple(algolist);
185 }
186
187 /*****************************************************************************
188  *  main                                                                                                                                         *
189  *****************************************************************************/
190
191
192 const char nessie_str[]      PROGMEM = "nessie";
193 const char test_str[]        PROGMEM = "test";
194 const char testinit192_str[] PROGMEM = "testinit192";
195 const char testinit_str[]    PROGMEM = "testinit";
196 const char testshort_str[]   PROGMEM = "short";
197 const char ztest_str[]       PROGMEM = "zerotest";
198 const char performance_str[] PROGMEM = "performance";
199 const char echo_str[]        PROGMEM = "echo";
200 const char shavs_list_str[]  PROGMEM = "shavs_list";
201 const char shavs_set_str[]   PROGMEM = "shavs_set";
202 const char shavs_test1_str[] PROGMEM = "shavs_test1";
203 const char shavs_test2_str[] PROGMEM = "shavs_test2";
204 const char shavs_test3_str[] PROGMEM = "shavs_test3";
205
206 cmdlist_entry_t cmdlist[] PROGMEM = {
207         { nessie_str,          NULL, testrun_nessie_shabal          },
208         { test_str,            NULL, testrun_stdtest_shabal         },
209         { testinit192_str,     NULL, testinit_192                   },
210         { testinit_str,        NULL, testinit                       },
211         { testshort_str,       NULL, testshort                      },
212         { performance_str,     NULL, performance_shabal             },
213         { shavs_list_str,      NULL, shavs_listalgos                },
214         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo        },
215         { shavs_test1_str,     NULL, shavs_test1                    },
216         { shavs_test2_str,     NULL, shavs_test2                    },
217         { shavs_test3_str,     NULL, shavs_test3                    },
218         { echo_str,        (void*)1, (void_fpt)echo_ctrl            },
219         { NULL,                NULL, NULL                           }
220 };
221
222 int main (void){
223         DEBUG_INIT();
224
225         cli_rx = (cli_rx_fpt)uart0_getc;
226         cli_tx = (cli_tx_fpt)uart0_putc;
227         shavs_algolist=(hfdesc_t**)algolist;
228         shavs_algo=(hfdesc_t*)&shabal256_desc;
229         for(;;){
230                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
231                 cli_putstr(algo_name);
232                 cli_putstr_P(PSTR("; "));
233                 cli_putstr(__DATE__);
234                 cli_putstr_P(PSTR(" "));
235                 cli_putstr(__TIME__);
236                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
237
238                 cmd_interface(cmdlist);
239         }
240 }