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/>.
24 #include "main-test-common.h"
27 #include "noekeon_prng.h"
28 #include "base64_enc.h"
29 #include "base64_dec.h"
31 #include "performance_test.h"
33 char* algo_name = "Base64";
35 /*****************************************************************************
36 * additional validation-functions *
37 *****************************************************************************/
39 void testrun_stdtest_base64(void){
44 uint8_t bin_buffer[256];
45 char b64_buffer[256*4/3+10];
46 uint8_t bin_buffer2[256];
47 random_seed(bin_buffer);
50 cli_putstr_P(PSTR("\r\nTest "));
55 bin_buffer[i] = random8();
57 cli_putstr_P(PSTR("\r\n bin: "));
58 cli_hexdump(bin_buffer, l);
60 base64enc(b64_buffer, bin_buffer, l);
61 cli_putstr_P(PSTR("\r\n b64: "));
62 cli_putstr(b64_buffer);
64 sl = base64_binlength(b64_buffer, 1);
67 cli_putstr_P(PSTR("\r\n ERROR length "));
70 cli_putstr_P(PSTR(" != "));
74 cli_putstr_P(PSTR(" != -1"));
78 cli_putstr_P(PSTR("\r\n length ok"));
80 base64dec(bin_buffer2, b64_buffer, 1);
81 if(memcmp(bin_buffer, bin_buffer2, l)){
82 cli_putstr_P(PSTR("\r\n ERROR value\r\n out: "));
83 cli_hexdump(bin_buffer2, l);
86 cli_putstr_P(PSTR("\r\n value ok"));
91 cli_putstr_P(fail?PSTR("\r\n [FAIL]\r\n"):PSTR("\r\n [OK]\r\n"));
94 void testrun_performance_base64(void){
98 uint8_t key[16], data[16];
108 noekeon_init(key, &ctx);
110 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
111 ultoa((unsigned long)t, str, 10);
115 noekeon_enc(data, &ctx);
117 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
118 ultoa((unsigned long)t, str, 10);
122 noekeon_dec(data, &ctx);
124 cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
125 ultoa((unsigned long)t, str, 10);
128 cli_putstr_P(PSTR("\r\n"));
131 /*****************************************************************************
133 *****************************************************************************/
135 const char test_str[] PROGMEM = "test";
136 const char performance_str[] PROGMEM = "performance";
137 const char echo_str[] PROGMEM = "echo";
139 const cmdlist_entry_t cmdlist[] PROGMEM = {
140 { test_str, NULL, testrun_stdtest_base64},
141 { performance_str, NULL, testrun_performance_base64},
142 { echo_str, (void*)1, (void_fpt)echo_ctrl},
150 welcome_msg(algo_name);
151 cmd_interface(cmdlist);