]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-xtea-test.c
bigint looks good but needs more testing
[arm-crypto-lib.git] / test_src / main-xtea-test.c
1 /* main-xtea-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  * XTEA 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 "xtea.h"
34 #include "nessie_bc_test.h"
35 #include "performance_test.h"
36 #include "bcal-performance.h"
37 #include "bcal_xtea.h"
38
39 char* algo_name = "XTEA";
40
41 void uart0_putc(char byte){
42         uart_putc(UART_0, byte);
43 }
44
45 char uart0_getc(void){
46         return uart_getc(UART_0);
47 }
48
49 const bcdesc_t* algolist[] = {
50         (bcdesc_t*)&xtea_desc,
51         NULL
52 };
53
54 /******************************************************************************/
55
56 void xtea_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
57         memcpy(ctx, key, (keysize+7)/8);
58 }
59
60 void xtea_enc_dummy(uint8_t* buffer, void* ctx){
61         xtea_enc((uint32_t*)buffer, (uint32_t*)buffer, ctx);
62 }
63
64 void xtea_dec_dummy(uint8_t* buffer, void* ctx){
65         xtea_dec((uint32_t*)buffer, (uint32_t*)buffer, ctx);
66 }
67
68 void testrun_nessie_xtea(void){
69         nessie_bc_ctx.blocksize_B =   8;
70         nessie_bc_ctx.keysize_b   = 128;
71         nessie_bc_ctx.name        = algo_name;
72         nessie_bc_ctx.ctx_size_B  = 128/8;
73         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)xtea_enc_dummy;
74         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)xtea_dec_dummy;
75         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)xtea_genctx_dummy;
76         
77         nessie_bc_run();        
78 }
79
80 void testrun_performance_xtea(void){
81         bcal_performance_multiple(algolist);
82 }
83
84 /*****************************************************************************
85  *  main                                                                                                                                         *
86  *****************************************************************************/
87
88 const char nessie_str[]      = "nessie";
89 const char test_str[]        = "test";
90 const char performance_str[] = "performance";
91 const char echo_str[]        = "echo";
92
93 const cmdlist_entry_t cmdlist[] = {
94         { nessie_str,      NULL, testrun_nessie_xtea},
95         { test_str,        NULL, testrun_nessie_xtea},
96         { performance_str, NULL, testrun_performance_xtea},
97         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
98         { NULL,            NULL, NULL}
99 };
100
101 int main (void){
102         sysclk_set_freq(SYS_FREQ);
103         sysclk_mosc_verify_enable();
104         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
105         gptm_set_timer_32periodic(TIMER0);
106
107         cli_rx = uart0_getc;
108         cli_tx = uart0_putc;
109         
110         for(;;){
111                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
112                 cli_putstr(algo_name);
113                 cli_putstr("; ");
114                 cli_putstr(__DATE__);
115                 cli_putc(' ');
116                 cli_putstr(__TIME__);
117                 cli_putstr(")\r\nloaded and running\r\n");
118                 cmd_interface(cmdlist);
119         }
120 }