7 #include "serial-tools.h"
12 #include "nessie_bc_test.h"
14 #include "performance_test.h"
20 char* cipher_name = "Present";
22 /*****************************************************************************
23 * additional validation-functions *
24 *****************************************************************************/
25 void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){
26 present_init(key, keysize_b, ctx);
29 void testrun_nessie_present(void){
30 nessie_bc_ctx.blocksize_B = 8;
31 nessie_bc_ctx.keysize_b = 80;
32 nessie_bc_ctx.name = cipher_name;
33 nessie_bc_ctx.ctx_size_B = sizeof(present_ctx_t);
34 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)present_enc;
35 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)present_dec;
36 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)present_genctx_dummy;
41 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
43 uart_putstr_P(PSTR("\r\nkey : "));
44 uart_hexdump(key, 10);
45 uart_putstr_P(PSTR("\r\nplain : "));
46 uart_hexdump(buffer, 8);
47 present_init(key, 80, &ctx);
48 present_enc(buffer, &ctx);
49 uart_putstr_P(PSTR("\r\ncipher: "));
50 uart_hexdump(buffer, 8);
51 present_dec(buffer, &ctx);
52 uart_putstr_P(PSTR("\r\nplain : "));
53 uart_hexdump(buffer, 8);
54 uart_putstr_P(PSTR("\r\n"));
57 void testrun_self_present(void){
58 uint8_t buffer[8], key[10];
59 uart_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n"));
63 testrun_selfenc(key, buffer);
66 memset(key, 0xFF, 10);
67 testrun_selfenc(key, buffer);
69 memset(buffer, 0xFF, 8);
71 testrun_selfenc(key, buffer);
73 memset(buffer, 0xFF, 8);
74 memset(key, 0xFF, 10);
75 testrun_selfenc(key, buffer);
79 void testrun_performance_present(void){
83 uint8_t key[10], data[8];
88 uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
90 uart_putstr_P(PSTR("\r\n\tconst overhead: "));
93 uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
100 present_init(key, 80, &ctx);
102 uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
103 ultoa((unsigned long)t, str, 10);
107 present_enc(data, &ctx);
109 uart_putstr_P(PSTR("\r\n\tencrypt time: "));
110 ultoa((unsigned long)t, str, 10);
114 present_dec(data, &ctx);
116 uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
117 ultoa((unsigned long)t, str, 10);
119 uart_putstr_P(PSTR("\r\n"));
122 /*****************************************************************************
124 *****************************************************************************/
126 typedef void(*void_fpt)(void);
133 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
134 uart_putstr(cipher_name);
135 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
137 PGM_P u = PSTR("nessie\0test\0performance\0");
138 void_fpt v[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present};
141 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
142 if(execcommand_d0_P(str, u, v)<0){
143 uart_putstr_P(PSTR("\r\nunknown command\r\n"));
147 uart_putstr("ERROR\r\n");