7 #include "serial-tools.h"
13 #include "nessie_stream_test.h"
14 #include "performance_test.h"
20 char* cipher_name = "Grain";
22 /*****************************************************************************
23 * additional validation-functions *
24 *****************************************************************************/
25 void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
27 grain_init(key, &iv, ctx);
30 uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){
34 ret |= grain_enc(ctx);
39 uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){
43 ret |= grain_enc(ctx)?0x80:0x00;
48 void testrun_nessie_grain(void){
49 nessie_stream_ctx.outsize_b = 8; /* actually unused */
50 nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */
51 nessie_stream_ctx.ivsize_b = 64;
52 nessie_stream_ctx.name = cipher_name;
53 nessie_stream_ctx.ctx_size_B = sizeof(grain_ctx_t);
54 nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)grain_genctx_dummy;
55 nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)grain_getbyte_dummy_rev;
61 void testrun_std_grain(void){
63 uint8_t i, key[10], iv[8], out[10];
68 uart_putstr_P(PSTR("\r\n=== std test ==="));
69 uart_putstr_P(PSTR("\r\n key: "));
70 uart_hexdump(key, 10);
71 uart_putstr_P(PSTR("\r\n iv: "));
73 grain_init(key, iv, &ctx);
75 out[i] = grain_getbyte_dummy(&ctx);
77 uart_putstr_P(PSTR("\r\n out: "));
78 uart_hexdump(out, 10);
90 uart_putstr_P(PSTR("\r\n\r\n key: "));
91 uart_hexdump(key, 10);
92 uart_putstr_P(PSTR("\r\n iv: "));
94 grain_init(key, iv, &ctx);
96 out[i] = grain_getbyte_dummy(&ctx);
98 uart_putstr_P(PSTR("\r\n out: "));
99 uart_hexdump(out, 10);
102 uart_putstr_P(PSTR("\r\n\r\n"));
105 void testrun_performance_grain(void){
109 uint8_t key[10], iv[8];
114 uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
116 uart_putstr_P(PSTR("\r\n\tconst overhead: "));
119 uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
126 grain_init(key, iv, &ctx);
128 uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
129 ultoa((unsigned long)t, str, 10);
135 uart_putstr_P(PSTR("\r\n\tencrypt time: "));
136 ultoa((unsigned long)t, str, 10);
139 uart_putstr_P(PSTR("\r\n"));
142 /*****************************************************************************
144 *****************************************************************************/
151 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
152 uart_putstr(cipher_name);
153 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
155 PGM_P u = PSTR("nessie\0test\0performance\0");
156 void_fpt v[] = {testrun_nessie_grain, testrun_std_grain, testrun_performance_grain};
159 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
160 if(execcommand_d0_P(str, u, v)<0){
161 uart_putstr_P(PSTR("\r\nunknown command\r\n"));
165 uart_putstr("ERROR\r\n");