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