1 /* main-noekeon-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/>.
29 #include "uart_lowlevel.h"
33 #include <noekeon/noekeon.h>
34 #include "nessie_bc_test.h"
35 #include "performance_test.h"
36 #include "bcal-performance.h"
37 #include "bcal_noekeon.h"
39 const char* algo_name = "Noekeon";
41 void uart0_putc(char byte){
42 uart_putc(UART_0, byte);
45 char uart0_getc(void){
46 return uart_getc(UART_0);
49 const bcdesc_t* algolist[] = {
50 (bcdesc_t*)&noekeon_direct_desc,
51 (bcdesc_t*)&noekeon_indirect_desc,
54 /*****************************************************************************
55 * additional validation-functions *
56 *****************************************************************************/
57 void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
58 noekeon_init(key, ctx);
61 void testrun_nessie_noekeon_indirect(void){
62 char str[strlen(algo_name)+10];
63 strcpy(str, algo_name);
64 strcat(str, "-indirect");
66 nessie_bc_ctx.blocksize_B = 16;
67 nessie_bc_ctx.keysize_b = 128;
68 nessie_bc_ctx.name = str;
69 nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
70 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
71 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
72 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
77 void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
81 void testrun_nessie_noekeon_direct(void){
82 char str[strlen(algo_name)+10];
83 strcpy(str, algo_name);
84 strcat(str, "-Direct");
86 nessie_bc_ctx.blocksize_B = 16;
87 nessie_bc_ctx.keysize_b = 128;
88 nessie_bc_ctx.name = str;
89 nessie_bc_ctx.ctx_size_B = sizeof(noekeon_ctx_t);
90 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)noekeon_enc;
91 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)noekeon_dec;
92 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
97 void testrun_nessie_noekeon(void){
98 testrun_nessie_noekeon_direct();
99 testrun_nessie_noekeon_indirect();
103 void testrun_stdtest_rundirect(void* data, void* key){
110 cli_hexdump(data,16);
112 noekeon_enc(data, key);
113 cli_putstr("\r\nafter NESSIEencrypt, b = ");
114 cli_hexdump(data,16);
116 noekeon_dec(data, key);
117 cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
118 cli_hexdump(data,16);
122 void testrun_stdtest_runindirect(void* data, void* key){
130 cli_hexdump(data,16);
131 noekeon_init(key, &ctx);
132 noekeon_enc(data, &ctx);
133 cli_putstr("\r\nafter NESSIEencrypt, b = ");
134 cli_hexdump(data,16);
136 noekeon_dec(data, &ctx);
137 cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
138 cli_hexdump(data,16);
142 void testrun_stdtest_noekeon(void){
143 uint8_t key[16], data[16];
147 cli_putstr("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n");
151 testrun_stdtest_runindirect(data, key);
153 memset(key, 0xFF, 16);
154 memset(data, 0xFF, 16);
155 testrun_stdtest_runindirect(data, key);
159 noekeon_init(key, &ctx);
160 noekeon_enc(data, &ctx);
161 memcpy(key3, data, 16);
162 memset(key, 0xFF, 16);
163 memset(data, 0xFF, 16);
164 noekeon_init(key, &ctx);
165 noekeon_enc(data, &ctx);
166 testrun_stdtest_runindirect(data, key3);
168 cli_putstr("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n");
172 testrun_stdtest_rundirect(data, key);
174 memset(key, 0xFF, 16);
175 memset(data, 0xFF, 16);
176 testrun_stdtest_rundirect(data, key);
180 noekeon_enc(data, key);
181 memcpy(key3, data, 16);
182 memset(key, 0xFF, 16);
183 memset(data, 0xFF, 16);
184 noekeon_enc(data, key);
185 testrun_stdtest_rundirect(data, key3);
189 void testrun_performance_noekeon(void){
190 bcal_performance_multiple(algolist);
192 /*****************************************************************************
194 *****************************************************************************/
196 const char nessie_str[] = "nessie";
197 const char test_str[] = "test";
198 const char direct_str[] = "direct";
199 const char indirect_str[] = "indirect";
200 const char performance_str[] = "performance";
201 const char echo_str[] = "echo";
203 cmdlist_entry_t cmdlist[] = {
204 { nessie_str, NULL, testrun_nessie_noekeon},
205 { test_str, NULL, testrun_stdtest_noekeon},
206 { direct_str, NULL, testrun_nessie_noekeon_direct},
207 { indirect_str, NULL, testrun_nessie_noekeon_indirect},
208 { performance_str, NULL, testrun_performance_noekeon},
209 { echo_str, (void*)1, (void_fpt)echo_ctrl},
214 sysclk_set_freq(SYS_FREQ);
215 sysclk_mosc_verify_enable();
216 uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
217 gptm_set_timer_32periodic(TIMER0);
223 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
224 cli_putstr(algo_name);
226 cli_putstr(__DATE__);
228 cli_putstr(__TIME__);
229 cli_putstr(")\r\nloaded and running\r\n");
230 cmd_interface(cmdlist);