1 /* main-noekeon-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/>.
29 #include <noekeon/noekeon.h>
30 #include "nessie_bc_test.h"
32 #include "performance_test.h"
33 #include "bcal-performance.h"
34 #include "bcal_noekeon.h"
40 char* algo_name = "Noekeon";
42 const bcdesc_t* algolist[] PROGMEM = {
43 (bcdesc_t*)&noekeon_direct_desc,
44 (bcdesc_t*)&noekeon_indirect_desc,
47 /*****************************************************************************
48 * additional validation-functions *
49 *****************************************************************************/
50 void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
51 noekeon_init(key, ctx);
54 void testrun_nessie_noekeon_indirect(void){
55 char str[strlen(algo_name)+10];
56 strcpy(str, algo_name);
57 strcat(str, "-indirect");
59 nessie_bc_ctx.blocksize_B = 16;
60 nessie_bc_ctx.keysize_b = 128;
61 nessie_bc_ctx.name = str;
62 nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
63 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
64 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
65 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
70 void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
74 void testrun_nessie_noekeon_direct(void){
75 char str[strlen(algo_name)+10];
76 strcpy(str, algo_name);
77 strcat(str, "-Direct");
79 nessie_bc_ctx.blocksize_B = 16;
80 nessie_bc_ctx.keysize_b = 128;
81 nessie_bc_ctx.name = str;
82 nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
83 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
84 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
85 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
90 void testrun_nessie_noekeon(void){
91 testrun_nessie_noekeon_direct();
92 testrun_nessie_noekeon_indirect();
96 void testrun_stdtest_rundirect(void* data, void* key){
97 cli_putstr_P(PSTR("\r\n "));
98 cli_putstr_P(PSTR("k = "));
101 cli_putstr_P(PSTR("\r\n "));
102 cli_putstr_P(PSTR("a = "));
103 cli_hexdump(data,16);
105 noekeon_enc(data, key);
106 cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
107 cli_hexdump(data,16);
109 noekeon_dec(data, key);
110 cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
111 cli_hexdump(data,16);
112 cli_putstr_P(PSTR("\r\n"));
115 void testrun_stdtest_runindirect(void* data, void* key){
117 cli_putstr_P(PSTR("\r\n "));
118 cli_putstr_P(PSTR("k = "));
121 cli_putstr_P(PSTR("\r\n "));
122 cli_putstr_P(PSTR("a = "));
123 cli_hexdump(data,16);
124 noekeon_init(key, &ctx);
125 noekeon_enc(data, &ctx);
126 cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
127 cli_hexdump(data,16);
129 noekeon_dec(data, &ctx);
130 cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
131 cli_hexdump(data,16);
132 cli_putstr_P(PSTR("\r\n"));
135 void testrun_stdtest_noekeon(void){
136 uint8_t key[16], data[16];
140 cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n"));
144 testrun_stdtest_runindirect(data, key);
146 memset(key, 0xFF, 16);
147 memset(data, 0xFF, 16);
148 testrun_stdtest_runindirect(data, key);
152 noekeon_init(key, &ctx);
153 noekeon_enc(data, &ctx);
154 memcpy(key3, data, 16);
155 memset(key, 0xFF, 16);
156 memset(data, 0xFF, 16);
157 noekeon_init(key, &ctx);
158 noekeon_enc(data, &ctx);
159 testrun_stdtest_runindirect(data, key3);
161 cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n"));
165 testrun_stdtest_rundirect(data, key);
167 memset(key, 0xFF, 16);
168 memset(data, 0xFF, 16);
169 testrun_stdtest_rundirect(data, key);
173 noekeon_enc(data, key);
174 memcpy(key3, data, 16);
175 memset(key, 0xFF, 16);
176 memset(data, 0xFF, 16);
177 noekeon_enc(data, key);
178 testrun_stdtest_rundirect(data, key3);
182 void testrun_performance_noekeon(void){
183 bcal_performance_multiple(algolist);
185 /*****************************************************************************
187 *****************************************************************************/
189 const char nessie_str[] PROGMEM = "nessie";
190 const char test_str[] PROGMEM = "test";
191 const char direct_str[] PROGMEM = "direct";
192 const char indirect_str[] PROGMEM = "indirect";
193 const char performance_str[] PROGMEM = "performance";
194 const char echo_str[] PROGMEM = "echo";
196 cmdlist_entry_t cmdlist[] PROGMEM = {
197 { nessie_str, NULL, testrun_nessie_noekeon},
198 { test_str, NULL, testrun_stdtest_noekeon},
199 { direct_str, NULL, testrun_nessie_noekeon_direct},
200 { indirect_str, NULL, testrun_nessie_noekeon_indirect},
201 { performance_str, NULL, testrun_performance_noekeon},
202 { echo_str, (void*)1, (void_fpt)echo_ctrl},
209 cli_rx = (cli_rx_fpt)uart0_getc;
210 cli_tx = (cli_tx_fpt)uart0_putc;
212 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
213 cli_putstr(algo_name);
214 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
215 cmd_interface(cmdlist);