]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-serpent-test.c
+RC5 +size-statistics tool +small modification to nessie_bc_test (optional free(...
[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[6];
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         uart_hexdump(&t, 8);
73         
74         
75         startTimer(1);
76         serpent_enc(data, &ctx);
77         t = stopTimer();
78         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
79         uart_hexdump(&t, 8);
80         
81         
82         startTimer(1);
83         serpent_dec(data, &ctx);
84         t = stopTimer();
85         uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
86         uart_hexdump(&t, 8);
87         uart_putstr_P(PSTR("\r\n"));
88 }
89 /*****************************************************************************
90  *  main                                                                                                                                         *
91  *****************************************************************************/
92
93 typedef void(*void_fpt)(void);
94
95 int main (void){
96         char  str[20];
97         DEBUG_INIT();
98         uart_putstr("\r\n");
99
100         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
101         uart_putstr(cipher_name);
102         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
103
104         PGM_P    u   = PSTR("nessie\0test\0performance\0");
105         void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent};
106
107         while(1){ 
108                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
109                 if(execcommand_d0_P(str, u, v)<0){
110                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
111                 }
112                 continue;
113         error:
114                 uart_putstr("ERROR\r\n");
115         }
116         
117 }
118