]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-arcfour-test.c
added arcfour/rc4
[arm-crypto-lib.git] / test_src / main-arcfour-test.c
1 /* main-arcfour-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  * arcfour (RC4 compatible) 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 "arcfour.h"
35 #include "scal_arcfour.h"
36
37 #include "scal-nessie.h"
38 #include "nessie_stream_test.h"
39 #include "performance_test.h"
40
41 #include <stdlib.h>
42 #include <stdint.h>
43 #include <string.h>
44
45 const char* algo_name = "Arcfour";
46
47 void uart0_putc(char byte){
48         uart_putc(UART_0, byte);
49 }
50
51 char uart0_getc(void){
52         return uart_getc(UART_0);
53 }
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58
59
60
61 void testrun_nessie_arcfour(void){
62         scal_nessie_run(&arcfour_desc);
63 }
64
65 void testrun_performance_arcfour(void){
66         uint64_t t;
67         char str[16];
68         uint8_t key[16];
69         arcfour_ctx_t ctx;
70         
71         calibrateTimer();
72         print_overhead();       
73         
74         memset(key,  0, 16);
75         
76         startTimer(1);
77         arcfour_init(key, 16, &ctx);
78         t = stopTimer();
79         cli_putstr("\r\n\tctx-gen time: ");
80         ultoa((unsigned long)t, str, 10);
81         cli_putstr(str);        
82         
83         startTimer(1);
84         arcfour_gen(&ctx);
85         t = stopTimer();
86         cli_putstr("\r\n\tencrypt time: ");
87         ultoa((unsigned long)t, str, 10);
88         cli_putstr(str);        
89         
90         cli_putstr("\r\n");
91 }
92
93
94 /*****************************************************************************
95  *  main                                                                                                                                         *
96  *****************************************************************************/
97
98 const cmdlist_entry_t cmdlist[] = {
99         { "nessie",      NULL, testrun_nessie_arcfour },
100         { "test",        NULL, testrun_nessie_arcfour},
101         { "performance", NULL, testrun_performance_arcfour},
102         { "echo",    (void*)1, (void_fpt)echo_ctrl},
103         { NULL,            NULL, NULL}
104 };
105
106 int main (void){
107         sysclk_set_freq(SYS_FREQ);
108         sysclk_mosc_verify_enable();
109         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
110         gptm_set_timer_32periodic(TIMER0);
111
112         cli_rx = uart0_getc;
113         cli_tx = uart0_putc;
114         
115         for(;;){
116                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
117                 cli_putstr(algo_name);
118                 cli_putstr("; ");
119                 cli_putstr(__DATE__);
120                 cli_putc(' ');
121                 cli_putstr(__TIME__);
122                 cli_putstr(")\r\nloaded and running\r\n");
123                 cmd_interface(cmdlist);
124         }
125 }