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