1 /* main-cscipher-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2008 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 "bcal-nessie.h"
32 #include "performance_test.h"
33 #include "bcal-performance.h"
34 #include "bcal_cscipher.h"
40 char* algo_name = "CS-Cipher";
42 const bcdesc_t* algolist[] PROGMEM = {
43 (bcdesc_t*)&cscipher_desc,
47 /*****************************************************************************
48 * additional validation-functions *
49 *****************************************************************************/
51 void cscipher_init_dummy(const uint8_t* key, uint16_t keysize_b, void* ctx){
52 cscipher_init(key, ctx);
55 void testrun_nessie_cscipher(void){
56 bcal_nessie(&cscipher_desc);
59 void testrun_cscipher(void){
60 uint8_t data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
61 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
62 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
64 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
67 cscipher_init(key, &ctx);
68 cli_putstr_P(PSTR("\r\nround keys:\r\n"));
69 cli_hexdump_block(&ctx, 8*9, 4, 8);
70 cli_putstr_P(PSTR("\r\nplain: "));
72 cscipher_enc(data, &ctx);
73 cli_putstr_P(PSTR("\r\ncipher: "));
75 cscipher_dec(data, &ctx);
76 cli_putstr_P(PSTR("\r\nplain: "));
80 void testrun_long_cscipher(void){
85 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
86 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
88 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
90 cscipher_init(key, &ctx);
92 cli_putstr_P(PSTR("\r\nplain: "));
94 cli_putstr_P(PSTR("\r\nencrypting 1,000,000 times:\r\n"));
95 for(i=0; i<10000;++i){
97 cscipher_enc(data, &ctx);
101 cli_putstr_P(PSTR("\r\n"));
103 cli_putstr_P(PSTR(": "));
108 cli_putstr_P(PSTR("\r\ncipher: "));
109 cli_hexdump(data, 8);
110 cli_putstr_P(PSTR("\r\ndecrypting 1,000,000 times:"));
111 for(i=0; i<10000;++i){
113 cscipher_dec(data, &ctx);
117 cli_putstr_P(PSTR("\r\n"));
119 cli_putstr_P(PSTR(": "));
123 cli_putstr_P(PSTR("\r\nplain: "));
124 cli_hexdump(data, 8);
128 void testrun_performance_cscipher(void){
129 bcal_performance_multiple(algolist);
131 /*****************************************************************************
133 *****************************************************************************/
135 const char nessie_str[] PROGMEM = "nessie";
136 const char test_str[] PROGMEM = "test";
137 const char longtest_str[] PROGMEM = "longtest";
138 const char performance_str[] PROGMEM = "performance";
139 const char echo_str[] PROGMEM = "echo";
141 cmdlist_entry_t cmdlist[] PROGMEM = {
142 { nessie_str, NULL, testrun_nessie_cscipher },
143 { test_str, NULL, testrun_cscipher},
144 { longtest_str, NULL, testrun_long_cscipher},
145 { performance_str, NULL, testrun_performance_cscipher},
146 { echo_str, (void*)1, (void_fpt)echo_ctrl},
153 cli_rx = (cli_rx_fpt)uart0_getc;
154 cli_tx = (cli_tx_fpt)uart0_putc;
156 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
157 cli_putstr(algo_name);
158 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
159 cmd_interface(cmdlist);