1 /* main-cast5-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 "performance_test.h"
31 #include "bcal-performance.h"
32 #include "bcal-nessie.h"
33 #include "bcal_cast5.h"
40 char* algo_name = "cast-128 (cast5)";
42 const bcdesc_t* algolist[] PROGMEM = {
43 (bcdesc_t*)&cast5_desc,
47 /*****************************************************************************
48 * additional validation-functions *
49 *****************************************************************************/
51 void testrun_nessie_cast5(void){
52 bcal_nessie_multiple(algolist);
55 /*****************************************************************************
57 *****************************************************************************/
59 void cast5_ctx_dump(cast5_ctx_t *s){
61 cli_putstr("\r\n==== cast5_ctx_dump ====\r\n shortkey: ");
62 cli_putstr(s->shortkey?"yes":"no");
65 cli_putstr("\r\n Km"); cli_hexdump(&i, 1); cli_putc(':');
66 cli_hexdump(&(s->mask[i]), 4);
67 cli_putstr("\r\n Kr"); cli_hexdump(&i, 1); cli_putc(':');
71 r += (s->roth[i>>3]&(1<<(i&0x7)))?0x10:0x00;
77 void test_encrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
80 cli_putstr("\r\nCAST5:\r\n key:\t");
81 cli_hexdump(key, keylength/8);
82 cli_putstr("\r\n plaintext:\t");
83 cli_hexdump(block, 8);
85 cast5_init(key, keylength, &s);
88 cli_putstr("\r\n ciphertext:\t");
89 cli_hexdump(block, 8);
93 void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
96 cli_putstr("\r\nCAST5:\r\n key:\t");
97 cli_hexdump(key, keylength/8);
98 cli_putstr("\r\n ciphertext:\t");
99 cli_hexdump(block, 8);
101 cast5_init(key, keylength, &s);
102 cast5_dec(block, &s);
104 cli_putstr("\r\n plaintext:\t");
105 cli_hexdump(block, 8);
109 void testrun_cast5(void){
112 uint8_t *tda = (uint8_t*)"\x01\x23\x45\x67\x89\xAB\xCD\xEF",
113 *tka = (uint8_t*)"\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A";
114 memcpy(block, tda, 8);
115 memcpy(key, tka, 16);
116 test_encrypt(block, key, 128, true);
117 test_decrypt(block, key, 128, true);
118 memcpy(block, tda, 8);
119 memcpy(key, tka, 16);
120 test_encrypt(block, key, 80, true);
121 test_decrypt(block, key, 80, true);
122 memcpy(block, tda, 8);
123 memcpy(key, tka, 16);
124 test_encrypt(block, key, 40, true);
125 test_decrypt(block, key, 40, true);
127 /**** long test *****/
128 cli_putstr("\r\nmaintance-test");
129 uint8_t a[16]= {0x01, 0x23, 0x45, 0x67, 0x12,
130 0x34, 0x56, 0x78, 0x23, 0x45,
131 0x67, 0x89, 0x34, 0x56, 0x78,
133 b[16]= {0x01, 0x23, 0x45, 0x67, 0x12,
134 0x34, 0x56, 0x78, 0x23, 0x45,
135 0x67, 0x89, 0x34, 0x56, 0x78,
138 for(i=0;i<1000000; ++i){
139 test_encrypt(&(a[0]), &(b[0]), 128, false);
140 test_encrypt(&(a[8]), &(b[0]), 128, false);
141 test_encrypt(&(b[0]), &(a[0]), 128, false);
142 test_encrypt(&(b[8]), &(a[0]), 128, false);
143 if ((i&0x000000ff) == 0){
148 cli_putstr("\r\na = "); cli_hexdump(a, 16);
149 cli_putstr("\r\nb = "); cli_hexdump(b, 16);
153 void testrun_performance_cast5(void){
154 bcal_performance_multiple(algolist);
157 /*****************************************************************************
159 *****************************************************************************/
161 const char nessie_str[] PROGMEM = "nessie";
162 const char test_str[] PROGMEM = "test";
163 const char performance_str[] PROGMEM = "performance";
164 const char echo_str[] PROGMEM = "echo";
166 cmdlist_entry_t cmdlist[] PROGMEM = {
167 { nessie_str, NULL, testrun_nessie_cast5},
168 { test_str, NULL, testrun_cast5},
169 { performance_str, NULL, testrun_performance_cast5},
170 { echo_str, (void*)1, (void_fpt)echo_ctrl},
177 cli_rx = (cli_rx_fpt)uart0_getc;
178 cli_tx = (cli_tx_fpt)uart0_putc;
180 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
181 cli_putstr(algo_name);
182 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
183 cmd_interface(cmdlist);