]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-cast6-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-cast6-test.c
1 /*
2  * rc6 test-suit
3  * 
4 */
5
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "config.h"
10 #include "cli.h"
11 #include "dump.h"
12 #include "uart_lowlevel.h"
13 #include "sysclock.h"
14 #include "hw_gptm.h"
15
16 #include "cast6.h"
17 #include "nessie_bc_test.h"
18 #include "cli.h"
19 #include "performance_test.h"
20 #include "bcal-performance.h"
21 #include "bcal_cast6.h"
22
23 char* algo_name = "CAST-256";
24
25 void uart0_putc(char byte){
26         uart_putc(UART_0, byte);
27 }
28
29 char uart0_getc(void){
30         return uart_getc(UART_0);
31 }
32
33 const bcdesc_t* algolist[] = {
34         (bcdesc_t*)&cast6_desc,
35         NULL
36 };
37
38 /*****************************************************************************
39  *  additional validation-functions                                                                                      *
40  *****************************************************************************/
41
42
43 void testrun_nessie_cast6(void){
44         nessie_bc_init();
45         nessie_bc_ctx.blocksize_B =  16;
46         nessie_bc_ctx.keysize_b   = 128;
47         nessie_bc_ctx.name        = algo_name;
48         nessie_bc_ctx.ctx_size_B  = sizeof(cast6_ctx_t);
49         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)cast6_enc;
50         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)cast6_dec;
51         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)cast6_init;
52         
53         nessie_bc_run();
54         
55         nessie_bc_ctx.keysize_b   = 192;
56         nessie_bc_run();
57         
58         nessie_bc_ctx.keysize_b   = 256;
59         nessie_bc_run();
60 }
61
62 void testrun_rfc_cast6(void){
63         cli_putstr("\r\n testvalues from rfc-2612\r\n");
64         uint8_t key[32], data[16];
65         cast6_ctx_t ctx;
66         memcpy(key, "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
67                     "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d", 16);
68         memset(data, 0, 16);
69         
70         cli_putstr("\r\n key: ");
71         cli_hexdump(key, 16);
72         cli_putstr("\r\n PT:  ");
73         cli_hexdump(data, 16);
74         cast6_init(key, 128, &ctx);
75         cast6_enc(data, &ctx);
76         cli_putstr("\r\n CT:  ");
77         cli_hexdump(data, 16);
78         cast6_dec(data, &ctx);
79         cli_putstr("\r\n PT:  ");
80         cli_hexdump(data, 16);
81         
82         cli_putstr("\r\n\r\n");
83
84         memcpy(key, "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
85                     "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
86                                 "\xba\xc7\x7a\x77\x17\x94\x28\x63", 24);
87         
88         cli_putstr("\r\n key: ");
89         cli_hexdump(key, 24);
90         cli_putstr("\r\n PT:  ");
91         cli_hexdump(data, 16);
92         cast6_init(key, 192, &ctx);
93         cast6_enc(data, &ctx);
94         cli_putstr("\r\n CT:  ");
95         cli_hexdump(data, 16);
96         cast6_dec(data, &ctx);
97         cli_putstr("\r\n PT:  ");
98         cli_hexdump(data, 16);
99         
100         cli_putstr("\r\n\r\n");
101         
102         memcpy(key, "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
103                     "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
104                                 "\x8d\x7c\x47\xce\x26\x49\x08\x46"
105                                 "\x1c\xc1\xb5\x13\x7a\xe6\xb6\x04", 32);
106         cli_putstr("\r\n key: ");
107         cli_hexdump(key, 32);
108         cli_putstr("\r\n PT:  ");
109         cli_hexdump(data, 16);
110         cast6_init(key, 256, &ctx);
111         cast6_enc(data, &ctx);
112         cli_putstr("\r\n CT:  ");
113         cli_hexdump(data, 16);
114         cast6_dec(data, &ctx);
115         cli_putstr("\r\n PT:  ");
116         cli_hexdump(data, 16);
117         
118         cli_putstr("\r\n\r\n");
119 }
120
121 void testrun_performance_cast6(void){
122         bcal_performance_multiple(algolist);
123 }
124
125 /*****************************************************************************
126  *  main                                                                                                                                         *
127  *****************************************************************************/
128
129 const char nessie_str[]      = "nessie";
130 const char test_str[]        = "test";
131 const char performance_str[] = "performance";
132 const char echo_str[]        = "echo";
133
134 const cmdlist_entry_t cmdlist[] = {
135         { nessie_str,      NULL, testrun_nessie_cast6 },
136         { test_str,        NULL, testrun_rfc_cast6},
137         { performance_str, NULL, testrun_performance_cast6},
138         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
139         { NULL,            NULL, NULL}
140 };
141
142 int main (void){
143         sysclk_set_freq(SYS_FREQ);
144         sysclk_mosc_verify_enable();
145         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
146         gptm_set_timer_32periodic(TIMER0);
147
148         cli_rx = (cli_rx_fpt)uart0_getc;
149         cli_tx = (cli_tx_fpt)uart0_putc;                
150         for(;;){
151                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
152                 cli_putstr(algo_name);
153                 cli_putstr("; ");
154                 cli_putstr(__DATE__);
155                 cli_putc(' ');
156                 cli_putstr(__TIME__);
157                 cli_putstr(")\r\nloaded and running\r\n");
158         cmd_interface(cmdlist);
159     }
160 }