1 /* main-grain-test.c */
3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "serial-tools.h"
31 #include "nessie_stream_test.h"
32 #include "performance_test.h"
38 char* cipher_name = "Grain";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
43 void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
45 grain_init(key, &iv, ctx);
48 uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){
52 ret |= grain_enc(ctx);
57 uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){
61 ret |= grain_enc(ctx)?0x80:0x00;
66 void testrun_nessie_grain(void){
67 nessie_stream_ctx.outsize_b = 8; /* actually unused */
68 nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */
69 nessie_stream_ctx.ivsize_b = 64;
70 nessie_stream_ctx.name = cipher_name;
71 nessie_stream_ctx.ctx_size_B = sizeof(grain_ctx_t);
72 nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)grain_genctx_dummy;
73 nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)grain_getbyte_dummy_rev;
79 void testrun_std_grain(void){
81 uint8_t i, key[10], iv[8], out[10];
86 uart_putstr_P(PSTR("\r\n=== std test ==="));
87 uart_putstr_P(PSTR("\r\n key: "));
88 uart_hexdump(key, 10);
89 uart_putstr_P(PSTR("\r\n iv: "));
91 grain_init(key, iv, &ctx);
93 out[i] = grain_getbyte_dummy(&ctx);
95 uart_putstr_P(PSTR("\r\n out: "));
96 uart_hexdump(out, 10);
108 uart_putstr_P(PSTR("\r\n\r\n key: "));
109 uart_hexdump(key, 10);
110 uart_putstr_P(PSTR("\r\n iv: "));
111 uart_hexdump(key, 8);
112 grain_init(key, iv, &ctx);
114 out[i] = grain_getbyte_dummy(&ctx);
116 uart_putstr_P(PSTR("\r\n out: "));
117 uart_hexdump(out, 10);
120 uart_putstr_P(PSTR("\r\n\r\n"));
123 void testrun_performance_grain(void){
126 uint8_t key[10], iv[8];
136 grain_init(key, iv, &ctx);
138 uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
139 ultoa((unsigned long)t, str, 10);
145 uart_putstr_P(PSTR("\r\n\tencrypt time: "));
146 ultoa((unsigned long)t, str, 10);
149 uart_putstr_P(PSTR("\r\n"));
152 /*****************************************************************************
154 *****************************************************************************/
161 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
162 uart_putstr(cipher_name);
163 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
165 PGM_P u = PSTR("nessie\0test\0performance\0");
166 void_fpt v[] = {testrun_nessie_grain, testrun_std_grain, testrun_performance_grain};
169 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
170 if(execcommand_d0_P(str, u, v)<0){
171 uart_putstr_P(PSTR("\r\nunknown command\r\n"));
175 uart_putstr("ERROR\r\n");