]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-cscipher-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-cscipher-test.c
1 /* main-cscipher-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  * cscipher test-suit
21  * 
22 */
23
24 #include "main-test-common.h"
25
26 #include "cscipher.h"
27 #include "bcal-nessie.h"
28 #include "performance_test.h"
29 #include "bcal-performance.h"
30 #include "bcal_cscipher.h"
31
32 char *algo_name = "CS-Cipher";
33
34 const bcdesc_t *const algolist[] PROGMEM = {
35         (bcdesc_t*)&cscipher_desc,
36         NULL
37 };
38
39 /*****************************************************************************
40  *  additional validation-functions                                                                                      *
41  *****************************************************************************/
42
43 void cscipher_init_dummy(const uint8_t *key, uint16_t keysize_b, void *ctx){
44         cscipher_init(key, ctx);
45 }
46
47 void testrun_nessie_cscipher(void){
48         bcal_nessie(&cscipher_desc);
49 }
50
51 void testrun_cscipher(void){
52         uint8_t data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
53         uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
54                                          0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
55         cscipher_ctx_t ctx;
56         cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
57         cli_hexdump(key, 16);
58         memset(&ctx, 0, 8*9);
59         cscipher_init(key, &ctx);
60         cli_putstr_P(PSTR("\r\nround keys:\r\n"));
61         cli_hexdump_block(&ctx, 8*9, 4, 8);
62         cli_putstr_P(PSTR("\r\nplain:  "));
63         cli_hexdump(data, 8);
64         cscipher_enc(data, &ctx);
65         cli_putstr_P(PSTR("\r\ncipher: "));
66         cli_hexdump(data, 8);
67         cscipher_dec(data, &ctx);
68         cli_putstr_P(PSTR("\r\nplain:  "));
69         cli_hexdump(data, 8);
70 }
71
72 void testrun_long_cscipher(void){
73         uint8_t data[8];
74         char str[10];
75         uint16_t i;
76         uint8_t j;
77         uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
78                                          0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
79         cscipher_ctx_t ctx;
80         cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
81         cli_hexdump(key, 16);
82         cscipher_init(key, &ctx);
83         memset(data, 0, 8);
84         cli_putstr_P(PSTR("\r\nplain:  "));
85         cli_hexdump(data, 8);
86         cli_putstr_P(PSTR("\r\nencrypting 1,000,000 times:\r\n"));
87         for(i=0; i<10000;++i){
88                 for(j=0;j<100;++j){
89                         cscipher_enc(data, &ctx);
90                 }
91                 if(i%128==0){
92                         itoa(i, str, 10);
93                         cli_putstr_P(PSTR("\r\n"));
94                         cli_putstr(str);
95                         cli_putstr_P(PSTR(": "));
96                 }
97                 cli_putc('*');
98
99         }
100         cli_putstr_P(PSTR("\r\ncipher: "));
101         cli_hexdump(data, 8);
102         cli_putstr_P(PSTR("\r\ndecrypting 1,000,000 times:"));
103         for(i=0; i<10000;++i){
104                 for(j=0;j<100;++j){
105                         cscipher_dec(data, &ctx);
106                 }
107                 if(i%128==0){
108                         itoa(i, str, 10);
109                         cli_putstr_P(PSTR("\r\n"));
110                         cli_putstr(str);
111                         cli_putstr_P(PSTR(": "));
112                 }
113                 cli_putc('*');
114         }
115         cli_putstr_P(PSTR("\r\nplain:  "));
116         cli_hexdump(data, 8);
117 }
118
119
120 void testrun_performance_cscipher(void){
121         bcal_performance_multiple(algolist);
122 }
123 /*****************************************************************************
124  *  main                                                                                                                                         *
125  *****************************************************************************/
126
127 const char nessie_str[]      PROGMEM = "nessie";
128 const char test_str[]        PROGMEM = "test";
129 const char longtest_str[]    PROGMEM = "longtest";
130 const char performance_str[] PROGMEM = "performance";
131 const char echo_str[]        PROGMEM = "echo";
132
133 const cmdlist_entry_t cmdlist[] PROGMEM = {
134         { nessie_str,      NULL, testrun_nessie_cscipher },
135         { test_str,        NULL, testrun_cscipher},
136         { longtest_str,    NULL, testrun_long_cscipher},
137         { performance_str, NULL, testrun_performance_cscipher},
138         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
139         { NULL,            NULL, NULL}
140 };
141
142 int main (void){
143     main_setup();
144
145     for(;;){
146         welcome_msg(algo_name);
147         cmd_interface(cmdlist);
148         }
149 }