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