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