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/>.
24 #include "main-test-common.h"
27 #include "bcal-nessie.h"
28 #include "performance_test.h"
29 #include "bcal-performance.h"
30 #include "bcal_cscipher.h"
32 char *algo_name = "CS-Cipher";
34 const bcdesc_t *const algolist[] PROGMEM = {
35 (bcdesc_t*)&cscipher_desc,
39 /*****************************************************************************
40 * additional validation-functions *
41 *****************************************************************************/
43 void cscipher_init_dummy(const uint8_t *key, uint16_t keysize_b, void *ctx){
44 cscipher_init(key, ctx);
47 void testrun_nessie_cscipher(void){
48 bcal_nessie(&cscipher_desc);
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 };
56 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
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: "));
64 cscipher_enc(data, &ctx);
65 cli_putstr_P(PSTR("\r\ncipher: "));
67 cscipher_dec(data, &ctx);
68 cli_putstr_P(PSTR("\r\nplain: "));
72 void testrun_long_cscipher(void){
77 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
78 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
80 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
82 cscipher_init(key, &ctx);
84 cli_putstr_P(PSTR("\r\nplain: "));
86 cli_putstr_P(PSTR("\r\nencrypting 1,000,000 times:\r\n"));
87 for(i=0; i<10000;++i){
89 cscipher_enc(data, &ctx);
93 cli_putstr_P(PSTR("\r\n"));
95 cli_putstr_P(PSTR(": "));
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){
105 cscipher_dec(data, &ctx);
109 cli_putstr_P(PSTR("\r\n"));
111 cli_putstr_P(PSTR(": "));
115 cli_putstr_P(PSTR("\r\nplain: "));
116 cli_hexdump(data, 8);
120 void testrun_performance_cscipher(void){
121 bcal_performance_multiple(algolist);
123 /*****************************************************************************
125 *****************************************************************************/
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";
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},
146 welcome_msg(algo_name);
147 cmd_interface(cmdlist);