]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-base64-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-base64-test.c
1 /* main-base64-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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  * base64 test-suit
21  * 
22 */
23
24 #include "main-test-common.h"
25
26 #include "noekeon.h"
27 #include "noekeon_prng.h"
28 #include "base64_enc.h"
29 #include "base64_dec.h"
30
31 #include "performance_test.h"
32
33 char *algo_name = "Base64";
34
35 /*****************************************************************************
36  *  additional validation-functions                                                                                      *
37  *****************************************************************************/
38
39 void testrun_stdtest_base64(void){
40         uint8_t fail=0;
41         uint8_t l,i; 
42         int     sl;
43         char str[10];
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);
48         
49         for(l=0; l<255; ++l){
50                 cli_putstr_P(PSTR("\r\nTest "));
51                 utoa(l, str, 10);
52                 cli_putstr(str);
53                 
54                 for(i=0; i<l; ++i){
55                         bin_buffer[i] = random8();
56                 }
57                 cli_putstr_P(PSTR("\r\n bin: "));
58                 cli_hexdump(bin_buffer, l);
59                 
60                 base64enc(b64_buffer, bin_buffer, l);
61                 cli_putstr_P(PSTR("\r\n b64: "));
62                 cli_putstr(b64_buffer);
63                 
64                 sl = base64_binlength(b64_buffer, 1);
65                 
66                 if(sl!=l){
67                         cli_putstr_P(PSTR("\r\n ERROR length "));
68                         cli_putstr(str);
69                         if(sl!=-1){
70                                 cli_putstr_P(PSTR(" != "));
71                                 utoa(sl, str, 10);
72                                 cli_putstr(str);
73                         }else{
74                                 cli_putstr_P(PSTR(" != -1"));
75                         }
76                         fail=1;
77                 }else{
78                         cli_putstr_P(PSTR("\r\n length ok"));
79                 }
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);
84                         fail=1;
85                 }else{
86                         cli_putstr_P(PSTR("\r\n value ok"));
87                 }
88                 if(fail)
89                         break;
90         }       
91         cli_putstr_P(fail?PSTR("\r\n [FAIL]\r\n"):PSTR("\r\n [OK]\r\n"));
92 }
93
94 void testrun_performance_base64(void){
95 /*
96         uint64_t t;
97         char str[16];
98         uint8_t key[16], data[16];
99         noekeon_ctx_t ctx;
100         
101         calibrateTimer();
102         print_overhead();
103         
104         memset(key,  0, 16);
105         memset(data, 0, 16);
106         
107         startTimer(1);
108         noekeon_init(key, &ctx);
109         t = stopTimer();
110         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
111         ultoa((unsigned long)t, str, 10);
112         cli_putstr(str);        
113         
114         startTimer(1);
115         noekeon_enc(data, &ctx);
116         t = stopTimer();
117         cli_putstr_P(PSTR("\r\n\tencrypt time: "));
118         ultoa((unsigned long)t, str, 10);
119         cli_putstr(str);        
120         
121         startTimer(1);
122         noekeon_dec(data, &ctx);
123         t = stopTimer();
124         cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
125         ultoa((unsigned long)t, str, 10);
126         cli_putstr(str);
127         
128         cli_putstr_P(PSTR("\r\n"));
129 */
130 }
131 /*****************************************************************************
132  *  main                                                                                                                                         *
133  *****************************************************************************/
134
135 const char test_str[]        PROGMEM = "test";
136 const char performance_str[] PROGMEM = "performance";
137 const char echo_str[]        PROGMEM = "echo";
138
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},
143         { NULL,            NULL, NULL}
144 };
145
146 int main (void){
147     main_setup();
148
149         for(;;){
150             welcome_msg(algo_name);
151             cmd_interface(cmdlist);
152         }
153 }