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 "nessie_bc_test.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){
57 nessie_bc_ctx.blocksize_B = 8;
58 nessie_bc_ctx.keysize_b = 128;
59 nessie_bc_ctx.name = algo_name;
60 nessie_bc_ctx.ctx_size_B = sizeof(cscipher_ctx_t);
61 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)cscipher_enc;
62 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)cscipher_dec;
63 nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)NULL;
64 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)cscipher_init_dummy;
69 void testrun_cscipher(void){
70 uint8_t data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
71 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
72 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
74 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
77 cscipher_init(key, &ctx);
78 cli_putstr_P(PSTR("\r\nround keys:\r\n"));
79 cli_hexdump_block(&ctx, 8*9, 4, 8);
80 cli_putstr_P(PSTR("\r\nplain: "));
82 cscipher_enc(data, &ctx);
83 cli_putstr_P(PSTR("\r\ncipher: "));
85 cscipher_dec(data, &ctx);
86 cli_putstr_P(PSTR("\r\nplain: "));
90 void testrun_long_cscipher(void){
95 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
96 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
98 cli_putstr_P(PSTR("\r\n== CS-Cipher test==\r\nkey: "));
100 cscipher_init(key, &ctx);
102 cli_putstr_P(PSTR("\r\nplain: "));
103 cli_hexdump(data, 8);
104 cli_putstr_P(PSTR("\r\nencrypting 1,000,000 times:\r\n"));
105 for(i=0; i<10000;++i){
107 cscipher_enc(data, &ctx);
111 cli_putstr_P(PSTR("\r\n"));
113 cli_putstr_P(PSTR(": "));
118 cli_putstr_P(PSTR("\r\ncipher: "));
119 cli_hexdump(data, 8);
120 cli_putstr_P(PSTR("\r\ndecrypting 1,000,000 times:"));
121 for(i=0; i<10000;++i){
123 cscipher_dec(data, &ctx);
127 cli_putstr_P(PSTR("\r\n"));
129 cli_putstr_P(PSTR(": "));
133 cli_putstr_P(PSTR("\r\nplain: "));
134 cli_hexdump(data, 8);
138 void testrun_performance_cscipher(void){
139 bcal_performance_multiple(algolist);
141 /*****************************************************************************
143 *****************************************************************************/
145 const char nessie_str[] PROGMEM = "nessie";
146 const char test_str[] PROGMEM = "test";
147 const char longtest_str[] PROGMEM = "longtest";
148 const char performance_str[] PROGMEM = "performance";
149 const char echo_str[] PROGMEM = "echo";
151 cmdlist_entry_t cmdlist[] PROGMEM = {
152 { nessie_str, NULL, testrun_nessie_cscipher },
153 { test_str, NULL, testrun_cscipher},
154 { longtest_str, NULL, testrun_long_cscipher},
155 { performance_str, NULL, testrun_performance_cscipher},
156 { echo_str, (void*)1, (void_fpt)echo_ctrl},
163 cli_rx = (cli_rx_fpt)uart0_getc;
164 cli_tx = (cli_tx_fpt)uart0_putc;
166 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
167 cli_putstr(algo_name);
168 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
169 cmd_interface(cmdlist);