1 /* main-grain-test.c */
3 This file is part of the AVR-Crypto-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* algo_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 = algo_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 cli_putstr_P(PSTR("\r\n=== std test ==="));
87 cli_putstr_P(PSTR("\r\n key: "));
89 cli_putstr_P(PSTR("\r\n iv: "));
91 grain_init(key, iv, &ctx);
93 out[i] = grain_getbyte_dummy(&ctx);
95 cli_putstr_P(PSTR("\r\n out: "));
108 cli_putstr_P(PSTR("\r\n\r\n key: "));
109 cli_hexdump(key, 10);
110 cli_putstr_P(PSTR("\r\n iv: "));
112 grain_init(key, iv, &ctx);
114 out[i] = grain_getbyte_dummy(&ctx);
116 cli_putstr_P(PSTR("\r\n out: "));
117 cli_hexdump(out, 10);
120 cli_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 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
139 ultoa((unsigned long)t, str, 10);
145 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
146 ultoa((unsigned long)t, str, 10);
149 cli_putstr_P(PSTR("\r\n"));
152 /*****************************************************************************
154 *****************************************************************************/
156 const char nessie_str[] PROGMEM = "nessie";
157 const char test_str[] PROGMEM = "test";
158 const char performance_str[] PROGMEM = "performance";
159 const char echo_str[] PROGMEM = "echo";
161 cmdlist_entry_t cmdlist[] PROGMEM = {
162 { nessie_str, NULL, testrun_nessie_grain },
163 { test_str, NULL, testrun_std_grain},
164 { performance_str, NULL, testrun_performance_grain},
165 { echo_str, (void*)1, (void_fpt)echo_ctrl},
175 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
176 cli_putstr(algo_name);
177 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
178 cmd_interface(cmdlist);