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