1 /* main-grain-test.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 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/>.
23 #include "main-test-common.h"
26 #include "scal_grain.h"
27 #include "scal-basic.h"
28 #include "scal-nessie.h"
29 #include "performance_test.h"
31 char* algo_name = "Grain";
33 /*****************************************************************************
34 * additional validation-functions *
35 *****************************************************************************/
36 void grain_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
38 grain_init(key, &iv, ctx);
41 uint8_t grain_getbyte_dummy(grain_ctx_t* ctx){
45 ret |= grain_enc(ctx);
50 uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){
54 ret |= grain_enc(ctx)?0x80:0x00;
59 void testrun_nessie_grain(void){
60 scal_nessie_set_estream(1);
61 scal_nessie_run(&grain_desc);
65 void testrun_std_grain(void){
67 uint8_t i, key[10], iv[8], out[10];
72 cli_putstr("\r\n=== std test ===");
73 cli_putstr("\r\n key: ");
75 cli_putstr("\r\n iv: ");
77 grain_init(key, iv, &ctx);
79 out[i] = grain_getbyte_dummy(&ctx);
81 cli_putstr("\r\n out: ");
94 cli_putstr("\r\n\r\n key: ");
96 cli_putstr("\r\n iv: ");
98 grain_init(key, iv, &ctx);
100 out[i] = grain_getbyte_dummy(&ctx);
102 cli_putstr("\r\n out: ");
103 cli_hexdump(out, 10);
106 cli_putstr("\r\n\r\n");
109 void testrun_performance_grain(void){
112 uint8_t key[10], iv[8];
122 grain_init(key, iv, &ctx);
124 cli_putstr("\r\n\tctx-gen time: ");
125 ultoa((unsigned long)t, str, 10);
131 cli_putstr("\r\n\tencrypt time: ");
132 ultoa((unsigned long)t, str, 10);
138 /*****************************************************************************
140 *****************************************************************************/
142 const char nessie_str[] = "nessie";
143 const char test_str[] = "test";
144 const char performance_str[] = "performance";
145 const char echo_str[] = "echo";
147 cmdlist_entry_t cmdlist[] = {
148 { nessie_str, NULL, testrun_nessie_grain },
149 { test_str, NULL, testrun_std_grain},
150 { performance_str, NULL, testrun_performance_grain},
151 { echo_str, (void*)1, (void_fpt)echo_ctrl},
159 welcome_msg(algo_name);
160 cmd_interface(cmdlist);