]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-rc5-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-rc5-test.c
1 /* main-rc5-test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * rc5 test-suit
21  * 
22 */
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "config.h"
27 #include "cli.h"
28 #include "dump.h"
29 #include "uart_lowlevel.h"
30 #include "sysclock.h"
31 #include "hw_gptm.h"
32
33 #include "rc5.h"
34 #include "nessie_bc_test.h"
35 #include "performance_test.h"
36 #include "bcal-performance.h"
37 #include "bcal_rc5.h"
38
39 #define RC5_ROUNDS 12
40 char* algo_name = "RC5-32/12/16";
41
42 void uart0_putc(char byte){
43         uart_putc(UART_0, byte);
44 }
45
46 char uart0_getc(void){
47         return uart_getc(UART_0);
48 }
49
50 const bcdesc_t* algolist[] = {
51         (bcdesc_t*)&rc5_desc,
52         NULL
53 };
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58 void rc5_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
59         rc5_init(key, keysize_b, RC5_ROUNDS, ctx);
60 }
61
62 void testrun_nessie_rc5(void){
63         nessie_bc_init();
64         nessie_bc_ctx.blocksize_B =   8;
65         nessie_bc_ctx.keysize_b   = 128;
66         nessie_bc_ctx.name        = algo_name;
67         nessie_bc_ctx.ctx_size_B  = sizeof(rc5_ctx_t);
68         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)rc5_enc;
69         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)rc5_dec;
70         nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc5_free;
71         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)rc5_genctx_dummy;
72         
73         nessie_bc_run();
74 }
75
76
77 void testrun_performance_rc5(void){
78         bcal_performance_multiple(algolist);
79 }
80 /*****************************************************************************
81  *  main                                                                                                                                         *
82  *****************************************************************************/
83
84 const char nessie_str[]      = "nessie";
85 const char test_str[]        = "test";
86 const char performance_str[] = "performance";
87 const char echo_str[]        = "echo";
88
89 const cmdlist_entry_t cmdlist[] = {
90         { nessie_str,      NULL, testrun_nessie_rc5 },
91         { test_str,        NULL, testrun_nessie_rc5},
92         { performance_str, NULL, testrun_performance_rc5},
93         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
94         { NULL,            NULL, NULL}
95 };
96
97 int main (void){
98         sysclk_set_freq(SYS_FREQ);
99         sysclk_mosc_verify_enable();
100         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
101         gptm_set_timer_32periodic(TIMER0);
102         
103         cli_rx = (cli_rx_fpt)uart0_getc;
104         cli_tx = (cli_tx_fpt)uart0_putc;                
105         for(;;){
106                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
107                 cli_putstr(algo_name);
108                 cli_putstr("; ");
109                 cli_putstr(__DATE__);
110                 cli_putc(' ');
111                 cli_putstr(__TIME__);
112                 cli_putstr(")\r\nloaded and running\r\n");
113         cmd_interface(cmdlist);
114     }
115 }