1 /* main-base64-test.c */
3 This file is part of the AVR-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 "noekeon_prng.h"
31 #include "base64_enc.h"
32 #include "base64_dec.h"
35 #include "performance_test.h"
41 char* algo_name = "Base64";
43 /*****************************************************************************
44 * additional validation-functions *
45 *****************************************************************************/
47 void testrun_stdtest_base64(void){
52 uint8_t bin_buffer[256];
53 char b64_buffer[256*4/3+10];
54 uint8_t bin_buffer2[256];
55 random_seed(bin_buffer);
58 cli_putstr_P(PSTR("\r\nTest "));
63 bin_buffer[i] = random8();
65 cli_putstr_P(PSTR("\r\n bin: "));
66 cli_hexdump(bin_buffer, l);
68 base64enc(b64_buffer, bin_buffer, l);
69 cli_putstr_P(PSTR("\r\n b64: "));
70 cli_putstr(b64_buffer);
72 sl = base64_binlength(b64_buffer, 1);
75 cli_putstr_P(PSTR("\r\n ERROR length "));
78 cli_putstr_P(PSTR(" != "));
82 cli_putstr_P(PSTR(" != -1"));
86 cli_putstr_P(PSTR("\r\n length ok"));
88 base64dec(bin_buffer2, b64_buffer, 1);
89 if(memcmp(bin_buffer, bin_buffer2, l)){
90 cli_putstr_P(PSTR("\r\n ERROR value\r\n out: "));
91 cli_hexdump(bin_buffer2, l);
94 cli_putstr_P(PSTR("\r\n value ok"));
99 cli_putstr_P(fail?PSTR("\r\n [FAIL]\r\n"):PSTR("\r\n [OK]\r\n"));
102 void testrun_performance_base64(void){
106 uint8_t key[16], data[16];
116 noekeon_init(key, &ctx);
118 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
119 ultoa((unsigned long)t, str, 10);
123 noekeon_enc(data, &ctx);
125 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
126 ultoa((unsigned long)t, str, 10);
130 noekeon_dec(data, &ctx);
132 cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
133 ultoa((unsigned long)t, str, 10);
136 cli_putstr_P(PSTR("\r\n"));
139 /*****************************************************************************
141 *****************************************************************************/
143 const char test_str[] PROGMEM = "test";
144 const char performance_str[] PROGMEM = "performance";
145 const char echo_str[] PROGMEM = "echo";
147 cmdlist_entry_t cmdlist[] PROGMEM = {
148 { test_str, NULL, testrun_stdtest_base64},
149 { performance_str, NULL, testrun_performance_base64},
150 { echo_str, (void*)1, (void_fpt)echo_ctrl},
157 cli_rx = (cli_rx_fpt)uart0_getc;
158 cli_tx = (cli_tx_fpt)uart0_putc;
160 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
161 cli_putstr(algo_name);
162 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
163 cmd_interface(cmdlist);