1 /* main-grain-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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/>.
24 #include "main-test-common.h"
27 #include "scal_grain.h"
28 #include "scal-basic.h"
29 #include "scal-nessie.h"
30 #include "performance_test.h"
32 char *algo_name = "Grain";
34 /*****************************************************************************
35 * additional validation-functions *
36 *****************************************************************************/
37 void grain_genctx_dummy(uint8_t *key, uint16_t keysize_b, void *ctx){
39 grain_init(key, &iv, ctx);
42 uint8_t grain_getbyte_dummy(grain_ctx_t *ctx){
46 ret |= grain_enc(ctx);
51 uint8_t grain_getbyte_dummy_rev(grain_ctx_t *ctx){
55 ret |= grain_enc(ctx)?0x80:0x00;
60 void testrun_nessie_grain(void){
61 scal_nessie_set_estream(1);
62 scal_nessie_run(&grain_desc);
66 void testrun_std_grain(void){
68 uint8_t i, key[10], iv[8], out[10];
73 cli_putstr_P(PSTR("\r\n=== std test ==="));
74 cli_putstr_P(PSTR("\r\n key: "));
76 cli_putstr_P(PSTR("\r\n iv: "));
78 grain_init(key, iv, &ctx);
80 out[i] = grain_getbyte_dummy(&ctx);
82 cli_putstr_P(PSTR("\r\n out: "));
95 cli_putstr_P(PSTR("\r\n\r\n key: "));
97 cli_putstr_P(PSTR("\r\n iv: "));
99 grain_init(key, iv, &ctx);
101 out[i] = grain_getbyte_dummy(&ctx);
103 cli_putstr_P(PSTR("\r\n out: "));
104 cli_hexdump(out, 10);
107 cli_putstr_P(PSTR("\r\n\r\n"));
110 void testrun_performance_grain(void){
113 uint8_t key[10], iv[8];
123 grain_init(key, iv, &ctx);
125 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
126 ultoa((unsigned long)t, str, 10);
132 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
133 ultoa((unsigned long)t, str, 10);
136 cli_putstr_P(PSTR("\r\n"));
139 /*****************************************************************************
141 *****************************************************************************/
143 const char nessie_str[] PROGMEM = "nessie";
144 const char test_str[] PROGMEM = "test";
145 const char performance_str[] PROGMEM = "performance";
146 const char echo_str[] PROGMEM = "echo";
148 const cmdlist_entry_t cmdlist[] PROGMEM = {
149 { nessie_str, NULL, testrun_nessie_grain },
150 { test_str, NULL, testrun_std_grain},
151 { performance_str, NULL, testrun_performance_grain},
152 { echo_str, (void*)1, (void_fpt)echo_ctrl},
160 welcome_msg(algo_name);
161 cmd_interface(cmdlist);