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