1 /* main-shabal-test.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
29 #include "uart_lowlevel.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"
41 #include "hfal_shabal.h"
43 void uart0_putc(char byte){
44 uart_putc(UART_0, byte);
47 char uart0_getc(void){
48 return uart_getc(UART_0);
51 const char* algo_name = "Shabal";
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,
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);
69 void testrun_stdtest_shabal224(const void* msg, uint16_t size_b){
70 hfal_test(&shabal224_desc, msg, size_b);
73 void testrun_stdtest_shabal256(const void* msg, uint16_t size_b){
74 hfal_test(&shabal256_desc, msg, size_b);
77 void testrun_stdtest_shabal384(const void* msg, uint16_t size_b){
78 hfal_test(&shabal384_desc, msg, size_b);
81 void testrun_stdtest_shabal512(const void* msg, uint16_t size_b){
82 hfal_test(&shabal512_desc, msg, size_b);
85 void testrun_stdtest_shabal(void){
87 const char* mb= "abcdefghijklmnopqrstuvwxyz-"
89 "ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
91 "abcdefghijklmnopqrstuvwxyz";
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);
106 void testshort(void){
109 testrun_stdtest_shabal192(ma, 64*8);
112 void shabal_ctx_dump(shabal_ctx_t* ctx){
115 cli_putstr("\r\n=== shabal ctx dump ===\r\n size = ");
116 i=sizeof(shabal_ctx_t);
120 cli_putc('0'+(i/10)%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);
139 cli_putstr("\r\n b (should) = ");
141 cli_putstr("\r\n c = ");
142 cli_hexdump(&(ctx->c), 2);
144 cli_putstr("\r\n c (should) = ");
149 void testinit_192(void){
151 shabal192_init(&ctx);
152 shabal_ctx_dump(&ctx);
155 void testinit_224(void){
157 shabal224_init(&ctx);
158 shabal_ctx_dump(&ctx);
161 void testinit_256(void){
163 shabal256_init(&ctx);
164 shabal_ctx_dump(&ctx);
167 void testinit_384(void){
169 shabal384_init(&ctx);
170 shabal_ctx_dump(&ctx);
173 void testinit_512(void){
175 shabal512_init(&ctx);
176 shabal_ctx_dump(&ctx);
186 void performance_shabal(void){
187 hfal_performance_multiple(algolist);
190 void testrun_nessie_shabal(void){
191 hfal_nessie_multiple(algolist);
194 /*****************************************************************************
196 *****************************************************************************/
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";
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 },
231 sysclk_mosc_verify_enable();
232 uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
233 gptm_set_timer_32periodic(TIMER0);
238 shavs_algolist=(hfdesc_t**)algolist;
239 shavs_algo=(hfdesc_t*)&shabal256_desc;
242 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
243 cli_putstr(algo_name);
245 cli_putstr(__DATE__);
247 cli_putstr(__TIME__);
248 cli_putstr(")\r\nloaded and running\r\n");
249 cmd_interface(cmdlist);