1 /* main-cscipher-test.c */
3 This file is part of the ARM-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 "uart_lowlevel.h"
35 #include "bcal-nessie.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal_cscipher.h"
40 char* algo_name = "CS-Cipher";
42 void uart0_putc(char byte){
43 uart_putc(UART_0, byte);
46 char uart0_getc(void){
47 return uart_getc(UART_0);
50 const bcdesc_t* algolist[] = {
51 (bcdesc_t*)&cscipher_desc,
55 /*****************************************************************************
56 * additional validation-functions *
57 *****************************************************************************/
59 void testrun_nessie_cscipher(void){
60 bcal_nessie(&cscipher_desc);
63 void testrun_cscipher(void){
64 uint8_t data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
65 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
66 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
68 cli_putstr("\r\n== CS-Cipher test==\r\nkey: ");
71 cscipher_init(key, &ctx);
72 cli_putstr("\r\nround keys:\r\n");
73 cli_hexdump_block(&ctx, 8*9, 4, 8);
74 cli_putstr("\r\nplain: ");
76 cscipher_enc(data, &ctx);
77 cli_putstr("\r\ncipher: ");
79 cscipher_dec(data, &ctx);
80 cli_putstr("\r\nplain: ");
84 void testrun_long_cscipher(void){
89 uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
90 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
92 cli_putstr("\r\n== CS-Cipher test==\r\nkey: ");
94 cscipher_init(key, &ctx);
96 cli_putstr("\r\nplain: ");
98 cli_putstr("\r\nencrypting 1,000,000 times:\r\n");
99 for(i=0; i<10000;++i){
101 cscipher_enc(data, &ctx);
104 sprintf(str, "%d", i);
112 cli_putstr("\r\ncipher: ");
113 cli_hexdump(data, 8);
114 cli_putstr("\r\ndecrypting 1,000,000 times:");
115 for(i=0; i<10000;++i){
117 cscipher_dec(data, &ctx);
120 sprintf(str, "%d", i);
127 cli_putstr("\r\nplain: ");
128 cli_hexdump(data, 8);
132 void testrun_performance_cscipher(void){
133 bcal_performance_multiple(algolist);
135 /*****************************************************************************
137 *****************************************************************************/
139 const char nessie_str[] = "nessie";
140 const char test_str[] = "test";
141 const char longtest_str[] = "longtest";
142 const char performance_str[] = "performance";
143 const char echo_str[] = "echo";
145 const cmdlist_entry_t cmdlist[] = {
146 { nessie_str, NULL, testrun_nessie_cscipher },
147 { test_str, NULL, testrun_cscipher},
148 { longtest_str, NULL, testrun_long_cscipher},
149 { performance_str, NULL, testrun_performance_cscipher},
150 { echo_str, (void*)1, (void_fpt)echo_ctrl},
155 sysclk_set_freq(SYS_FREQ);
156 sysclk_mosc_verify_enable();
157 uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
158 gptm_set_timer_32periodic(TIMER0);
164 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
165 cli_putstr(algo_name);
167 cli_putstr(__DATE__);
169 cli_putstr(__TIME__);
170 cli_putstr(")\r\nloaded and running\r\n");
171 cmd_interface(cmdlist);