]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-des-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-des-test.c
1 /* main-des-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  * des test-suit
21  * 
22 */
23
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "config.h"
28 #include "cli.h"
29 #include "dump.h"
30 #include "uart_lowlevel.h"
31 #include "sysclock.h"
32 #include "hw_gptm.h"
33
34 #include "des.h"
35 #include "nessie_bc_test.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal_des.h"
39
40 char* algo_name = "DES";
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*)&des_desc,
52         NULL
53 };
54 /*****************************************************************************
55  *  additional validation-functions                                                                                      *
56  *****************************************************************************/
57 void des_init_dummy(const void* key, uint16_t keysize_b, void* ctx){
58         memcpy(ctx, key, 8);
59 }
60
61 void des_enc_dummy(void* buffer, void* ctx){
62         des_enc(buffer, buffer, ctx);
63
64
65 void des_dec_dummy(void* buffer, void* ctx){
66         des_dec(buffer, buffer, ctx);
67
68
69 void testrun_nessie_des(void){
70         nessie_bc_init();
71         nessie_bc_ctx.blocksize_B =   8;
72         nessie_bc_ctx.keysize_b   =  64;
73         nessie_bc_ctx.name        = algo_name;
74         nessie_bc_ctx.ctx_size_B  = 8;
75         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)des_enc_dummy;
76         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)des_dec_dummy;
77         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)des_init_dummy;
78         
79         nessie_bc_run();
80 }
81
82
83 void testrun_performance_des(void){
84         bcal_performance_multiple(algolist);
85 }
86 /*****************************************************************************
87  * main                                         
88  *****************************************************************************/
89
90 const char nessie_str[]      = "nessie";
91 const char test_str[]        = "test";
92 const char performance_str[] = "performance";
93 const char echo_str[]        = "echo";
94
95 cmdlist_entry_t cmdlist[] = {
96         { nessie_str,      NULL, testrun_nessie_des },
97         { test_str,        NULL, testrun_nessie_des },
98         { performance_str, NULL, testrun_performance_des},
99         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
100         { NULL,            NULL, NULL}
101 };
102
103 int main (void){
104         sysclk_set_freq(SYS_FREQ);
105         sysclk_mosc_verify_enable();
106         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
107         gptm_set_timer_32periodic(TIMER0);
108
109         cli_rx = uart0_getc;
110         cli_tx = uart0_putc;
111         
112         for(;;){
113                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
114                 cli_putstr(algo_name);
115                 cli_putstr("; ");
116                 cli_putstr(__DATE__);
117                 cli_putc(' ');
118                 cli_putstr(__TIME__);
119                 cli_putstr(")\r\nloaded and running\r\n");
120                 cmd_interface(cmdlist);
121         }
122 }