]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-rc6-test.c
5be9a3ed7679e03ccd1abc121d4c52e281d2f87d
[avr-crypto-lib.git] / main-rc6-test.c
1 /*
2  * rc5 test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "rc6.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
20 #define RC6_ROUNDS 20
21 char* cipher_name = "RC6-32/20/16";
22
23 /*****************************************************************************
24  *  additional validation-functions                                                                                      *
25  *****************************************************************************/
26 void rc6_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
27         rc6_initl(key, keysize_b, RC6_ROUNDS, ctx);
28 }
29
30 void testrun_nessie_rc6(void){
31         nessie_bc_init();
32         nessie_bc_ctx.blocksize_B =  16;
33         nessie_bc_ctx.keysize_b   = 128;
34         nessie_bc_ctx.name        = cipher_name;
35         nessie_bc_ctx.ctx_size_B  = sizeof(rc6_ctx_t);
36         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)rc6_enc;
37         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)rc6_dec;
38         nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)rc6_free;
39         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)rc6_init;
40         
41         nessie_bc_run();
42         
43         nessie_bc_ctx.keysize_b   = 192;
44         nessie_bc_run();
45         
46         nessie_bc_ctx.keysize_b   = 256;
47         nessie_bc_run();
48         
49 }
50
51
52 void testrun_performance_rc6(void){
53         uint16_t i,c;
54         uint64_t t;
55         char str[16];
56         uint8_t key[16], data[16];
57         rc6_ctx_t ctx;
58         
59         calibrateTimer();
60         getOverhead(&c, &i);
61         uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
62         utoa(c, str, 10);
63         uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
64         uart_putstr(str);
65         utoa(i, str, 10);
66         uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
67         uart_putstr(str);
68         
69         memset(key,  0, 16);
70         memset(data, 0, 16);
71         
72         startTimer(1);
73         rc6_init(key, 128, &ctx);
74         t = stopTimer();
75         uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
76         ultoa((unsigned long)t, str, 10);
77         uart_putstr(str);       
78         
79         startTimer(1);
80         rc6_enc(data, &ctx);
81         t = stopTimer();
82         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
83         ultoa((unsigned long)t, str, 10);
84         uart_putstr(str);
85         
86         startTimer(1);
87         rc6_dec(data, &ctx);
88         t = stopTimer();
89         uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
90         ultoa((unsigned long)t, str, 10);
91         uart_putstr(str);
92
93         startTimer(1);
94         rc6_free(&ctx);
95         t = stopTimer();
96         uart_putstr_P(PSTR("\r\n\tfree time: "));
97         ultoa((unsigned long)t, str, 10);
98         uart_putstr(str);
99         uart_putstr_P(PSTR("\r\n"));
100 }
101 /*****************************************************************************
102  *  main                                                                                                                                         *
103  *****************************************************************************/
104
105 int main (void){
106         char  str[20];
107         DEBUG_INIT();
108         uart_putstr("\r\n");
109
110         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
111         uart_putstr(cipher_name);
112         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
113
114         PGM_P    u   = PSTR("nessie\0test\0performance\0");
115         void_fpt v[] = {testrun_nessie_rc6, testrun_nessie_rc6, testrun_performance_rc6};
116
117         while(1){ 
118                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
119                 if(execcommand_d0_P(str, u, v)<0){
120                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
121                 }
122                 continue;
123         error:
124                 uart_putstr("ERROR\r\n");
125         }
126         
127 }
128