]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-cast6-test.c
bcd97744f50200846246e83096ee91f440a8dcc4
[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 "cli.h"
13 #include "performance_test.h"
14 #include "bcal-performance.h"
15 #include "bcal-nessie.h"
16 #include "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* const 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         bcal_nessie_multiple(algolist);
37 }
38
39 void testrun_rfc_cast6(void){
40         cli_putstr_P(PSTR("\r\n testvalues from rfc-2612\r\n"));
41         uint8_t key[32], data[16];
42         cast6_ctx_t ctx;
43         memcpy_P(key, PSTR("\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
44                            "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d"), 16);
45         memset(data, 0, 16);
46         
47         cli_putstr_P(PSTR("\r\n key: "));
48         cli_hexdump(key, 16);
49         cli_putstr_P(PSTR("\r\n PT:  "));
50         cli_hexdump(data, 16);
51         cast6_init(key, 128, &ctx);
52         cast6_enc(data, &ctx);
53         cli_putstr_P(PSTR("\r\n CT:  "));
54         cli_hexdump(data, 16);
55         cast6_dec(data, &ctx);
56         cli_putstr_P(PSTR("\r\n PT:  "));
57         cli_hexdump(data, 16);
58         
59         cli_putstr_P(PSTR("\r\n\r\n"));
60
61         memcpy_P(key, PSTR("\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
62                            "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
63                                        "\xba\xc7\x7a\x77\x17\x94\x28\x63"), 24);
64         
65         cli_putstr_P(PSTR("\r\n key: "));
66         cli_hexdump(key, 24);
67         cli_putstr_P(PSTR("\r\n PT:  "));
68         cli_hexdump(data, 16);
69         cast6_init(key, 192, &ctx);
70         cast6_enc(data, &ctx);
71         cli_putstr_P(PSTR("\r\n CT:  "));
72         cli_hexdump(data, 16);
73         cast6_dec(data, &ctx);
74         cli_putstr_P(PSTR("\r\n PT:  "));
75         cli_hexdump(data, 16);
76         
77         cli_putstr_P(PSTR("\r\n\r\n"));
78         
79         memcpy_P(key, PSTR("\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
80                            "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
81                                        "\x8d\x7c\x47\xce\x26\x49\x08\x46"
82                                        "\x1c\xc1\xb5\x13\x7a\xe6\xb6\x04"), 32);
83         cli_putstr_P(PSTR("\r\n key: "));
84         cli_hexdump(key, 32);
85         cli_putstr_P(PSTR("\r\n PT:  "));
86         cli_hexdump(data, 16);
87         cast6_init(key, 256, &ctx);
88         cast6_enc(data, &ctx);
89         cli_putstr_P(PSTR("\r\n CT:  "));
90         cli_hexdump(data, 16);
91         cast6_dec(data, &ctx);
92         cli_putstr_P(PSTR("\r\n PT:  "));
93         cli_hexdump(data, 16);
94         
95         cli_putstr_P(PSTR("\r\n\r\n"));
96 }
97
98 void testrun_performance_cast6(void){
99         bcal_performance_multiple(algolist);
100 }
101
102 /*****************************************************************************
103  *  main                                                                                                                                         *
104  *****************************************************************************/
105
106 const char nessie_str[]      PROGMEM = "nessie";
107 const char test_str[]        PROGMEM = "test";
108 const char performance_str[] PROGMEM = "performance";
109 const char echo_str[]        PROGMEM = "echo";
110
111 const cmdlist_entry_t cmdlist[] PROGMEM = {
112         { nessie_str,      NULL, testrun_nessie_cast6 },
113         { test_str,        NULL, testrun_rfc_cast6},
114         { performance_str, NULL, testrun_performance_cast6},
115         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
116         { NULL,            NULL, NULL}
117 };
118
119 int main (void){
120         DEBUG_INIT();
121         cli_rx = (cli_rx_fpt)uart0_getc;
122         cli_tx = (cli_tx_fpt)uart0_putc;                
123         for(;;){
124                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
125                 cli_putstr(algo_name);
126                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
127                 cmd_interface(cmdlist);
128         }
129 }