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/>.
31 #include "scal_grain.h"
32 #include "scal-basic.h"
33 #include "scal-nessie.h"
34 #include "performance_test.h"
40 char* algo_name = "Grain";
42 /*****************************************************************************
43 * additional validation-functions *
44 *****************************************************************************/
45 void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
47 grain_init(key, &iv, ctx);
50 uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){
54 ret |= grain_enc(ctx);
59 uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){
63 ret |= grain_enc(ctx)?0x80:0x00;
68 void testrun_nessie_grain(void){
69 scal_nessie_run(&grain_desc);
73 void testrun_std_grain(void){
75 uint8_t i, key[10], iv[8], out[10];
80 cli_putstr_P(PSTR("\r\n=== std test ==="));
81 cli_putstr_P(PSTR("\r\n key: "));
83 cli_putstr_P(PSTR("\r\n iv: "));
85 grain_init(key, iv, &ctx);
87 out[i] = grain_getbyte_dummy(&ctx);
89 cli_putstr_P(PSTR("\r\n out: "));
102 cli_putstr_P(PSTR("\r\n\r\n key: "));
103 cli_hexdump(key, 10);
104 cli_putstr_P(PSTR("\r\n iv: "));
106 grain_init(key, iv, &ctx);
108 out[i] = grain_getbyte_dummy(&ctx);
110 cli_putstr_P(PSTR("\r\n out: "));
111 cli_hexdump(out, 10);
114 cli_putstr_P(PSTR("\r\n\r\n"));
117 void testrun_performance_grain(void){
120 uint8_t key[10], iv[8];
130 grain_init(key, iv, &ctx);
132 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
133 ultoa((unsigned long)t, str, 10);
139 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
140 ultoa((unsigned long)t, str, 10);
143 cli_putstr_P(PSTR("\r\n"));
146 /*****************************************************************************
148 *****************************************************************************/
150 const char nessie_str[] PROGMEM = "nessie";
151 const char test_str[] PROGMEM = "test";
152 const char performance_str[] PROGMEM = "performance";
153 const char echo_str[] PROGMEM = "echo";
155 cmdlist_entry_t cmdlist[] PROGMEM = {
156 { nessie_str, NULL, testrun_nessie_grain },
157 { test_str, NULL, testrun_std_grain},
158 { performance_str, NULL, testrun_performance_grain},
159 { echo_str, (void*)1, (void_fpt)echo_ctrl},
166 cli_rx = (cli_rx_fpt)uart0_getc;
167 cli_tx = (cli_tx_fpt)uart0_putc;
169 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
170 cli_putstr(algo_name);
171 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
172 cmd_interface(cmdlist);