1 /* main-base64-test.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2008, 2009 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/>.
30 #include "uart_lowlevel.h"
35 #include "noekeon_prng.h"
36 #include "base64_enc.h"
37 #include "base64_dec.h"
38 #include "string-extras.h"
40 #include "performance_test.h"
42 void uart0_putc(char byte){
43 uart_putc(UART_0, byte);
46 char uart0_getc(void){
47 return uart_getc(UART_0);
50 char* algo_name = "Base64";
52 /*****************************************************************************
53 * additional validation-functions *
54 *****************************************************************************/
55 #define TESTLENGTH 4096
57 void testrun_stdtest_base64(void){
62 uint8_t bin_buffer[TESTLENGTH];
63 char b64_buffer[TESTLENGTH*4/3+10];
64 uint8_t bin_buffer2[TESTLENGTH];
65 random_seed(bin_buffer);
67 for(l=0; l<TESTLENGTH-1; ++l){
68 cli_putstr("\r\nTest ");
74 bin_buffer[i] = random8();
76 cli_putstr("\r\n bin: ");
77 cli_hexdump(bin_buffer, l);
80 base64enc(b64_buffer, bin_buffer, l);
81 cli_putstr("\r\n b64: ");
82 cli_putstr(b64_buffer);
85 sl = base64_binlength(b64_buffer, 1);
88 cli_putstr("\r\n ERROR length ");
99 cli_putstr("\r\n length ok");
103 base64dec(bin_buffer2, b64_buffer, 1);
104 if(memcmp(bin_buffer, bin_buffer2, l)){
105 cli_putstr("\r\n ERROR value\r\n out: ");
106 cli_hexdump(bin_buffer2, l);
109 cli_putstr("\r\n value ok");
115 cli_putstr(fail?"\r\n [FAIL]\r\n":"\r\n [OK]\r\n");
118 void testrun_performance_base64(void){
122 uint8_t key[16], data[16];
132 noekeon_init(key, &ctx);
134 cli_putstr("\r\n\tctx-gen time: ");
135 ultoa((unsigned long)t, str, 10);
139 noekeon_enc(data, &ctx);
141 cli_putstr("\r\n\tencrypt time: ");
142 ultoa((unsigned long)t, str, 10);
146 noekeon_dec(data, &ctx);
148 cli_putstr("\r\n\tdecrypt time: ");
149 ultoa((unsigned long)t, str, 10);
155 /*****************************************************************************
157 *****************************************************************************/
159 const char test_str[] = "test";
160 const char performance_str[] = "performance";
161 const char echo_str[] = "echo";
163 const cmdlist_entry_t cmdlist[] = {
164 { test_str, NULL, testrun_stdtest_base64},
165 { performance_str, NULL, testrun_performance_base64},
166 { echo_str, (void*)1, (void_fpt)echo_ctrl},
171 sysclk_set_freq(SYS_FREQ);
172 sysclk_mosc_verify_enable();
173 uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
174 gptm_set_timer_32periodic(TIMER0);
180 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
181 cli_putstr(algo_name);
183 cli_putstr(__DATE__);
185 cli_putstr(__TIME__);
186 cli_putstr(")\r\nloaded and running\r\n");
187 cmd_interface(cmdlist);