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