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 "nessie_bc_test.h"
33 #include "performance_test.h"
38 #include <avr/pgmspace.h>
40 char* algo_name = "AES";
42 /*****************************************************************************
43 * additional validation-functions *
44 *****************************************************************************/
46 void testrun_nessie_aes(void){
47 nessie_bc_ctx.blocksize_B = 16;
48 nessie_bc_ctx.keysize_b = 128;
49 nessie_bc_ctx.name = algo_name;
50 nessie_bc_ctx.ctx_size_B = sizeof(aes128_ctx_t);
51 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes128_enc;
52 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes128_dec;
53 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)aes_init;
56 nessie_bc_ctx.keysize_b = 192;
57 nessie_bc_ctx.ctx_size_B = sizeof(aes192_ctx_t);
58 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes192_enc;
59 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes192_dec;
62 nessie_bc_ctx.keysize_b = 256;
63 nessie_bc_ctx.ctx_size_B = sizeof(aes256_ctx_t);
64 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes256_enc;
65 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes256_dec;
69 void testrun_test_aes(void){
70 uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
71 0x28, 0xae, 0xd2, 0xa6,
72 0xab, 0xf7, 0x15, 0x88,
73 0x09, 0xcf, 0x4f, 0x3c };
74 uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
75 0x88, 0x5a, 0x30, 0x8d,
76 0x31, 0x31, 0x98, 0xa2,
77 0xe0, 0x37, 0x07, 0x34 };
79 aes128_init(key, &ctx);
80 cli_putstr_P(PSTR("\r\n\r\n cipher test (FIPS 197):\r\n key: "));
82 cli_putstr_P(PSTR("\r\n plaintext: "));
83 cli_hexdump(data, 16);
84 aes128_enc(data, &ctx);
85 cli_putstr_P(PSTR("\r\n ciphertext: "));
86 cli_hexdump(data, 16);
87 aes128_dec(data, &ctx);
88 cli_putstr_P(PSTR("\r\n plaintext: "));
89 cli_hexdump(data, 16);
94 void testrun_testkey_aes128(void){
95 uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
96 0x28, 0xae, 0xd2, 0xa6,
97 0xab, 0xf7, 0x15, 0x88,
98 0x09, 0xcf, 0x4f, 0x3c};
101 aes128_init(key, &ctx);
102 cli_putstr_P(PSTR("\r\n\r\n keyschedule test (FIPS 197):\r\n key: "));
103 cli_hexdump(key, 16);
105 cli_putstr_P(PSTR("\r\n index: "));
108 cli_putstr_P(PSTR(" roundkey "));
109 cli_hexdump(ctx.key[i].ks, 16);
113 void testrun_testkey_aes192(void){
114 uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7,
115 0xda, 0x0e, 0x64, 0x52,
116 0xc8, 0x10, 0xf3, 0x2b,
117 0x80, 0x90, 0x79, 0xe5,
118 0x62, 0xf8, 0xea, 0xd2,
119 0x52, 0x2c, 0x6b, 0x7b};
122 memset(&ctx, 0, sizeof(aes192_ctx_t));
123 aes192_init(key, &ctx);
124 cli_putstr_P(PSTR("\r\n\r\n keyschedule test (FIPS 197):\r\n key: "));
125 cli_hexdump(key, 24);
127 cli_putstr_P(PSTR("\r\n index: "));
130 cli_putstr_P(PSTR(" roundkey "));
131 cli_hexdump(ctx.key[i].ks, 16);
136 void testrun_testkey_aes256(void){
137 uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10,
138 0x15, 0xca, 0x71, 0xbe,
139 0x2b, 0x73, 0xae, 0xf0,
140 0x85, 0x7d, 0x77, 0x81,
141 0x1f, 0x35, 0x2c, 0x07,
142 0x3b, 0x61, 0x08, 0xd7,
143 0x2d, 0x98, 0x10, 0xa3,
144 0x09, 0x14, 0xdf, 0xf4};
147 memset(&ctx, 0, sizeof(aes256_ctx_t));
148 aes256_init(key, &ctx);
149 cli_putstr_P(PSTR("\r\n\r\n keyschedule test (FIPS 197):\r\n key: "));
150 cli_hexdump(key, 32);
152 cli_putstr_P(PSTR("\r\n index: "));
155 cli_putstr_P(PSTR(" roundkey "));
156 cli_hexdump(ctx.key[i].ks, 16);
160 void testrun_testkey_aes(void){
161 testrun_testkey_aes128();
162 testrun_testkey_aes192();
163 testrun_testkey_aes256();
165 /*****************************************************************************/
167 void testrun_performance_aes128(void){
170 uint8_t key[32], data[16];
180 aes128_init(key, &ctx);
182 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
183 ultoa((unsigned long)t, str, 10);
188 aes128_enc(data, &ctx);
190 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
191 ultoa((unsigned long)t, str, 10);
196 aes128_dec(data, &ctx);
198 cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
199 ultoa((unsigned long)t, str, 10);
202 cli_putstr_P(PSTR("\r\n"));
206 void testrun_performance_aes192(void){
209 uint8_t key[32], data[16];
219 aes192_init(key, &ctx);
221 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
222 ultoa((unsigned long)t, str, 10);
227 aes192_enc(data, &ctx);
229 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
230 ultoa((unsigned long)t, str, 10);
235 aes192_dec(data, &ctx);
237 cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
238 ultoa((unsigned long)t, str, 10);
241 cli_putstr_P(PSTR("\r\n"));
245 void testrun_performance_aes256(void){
248 uint8_t key[32], data[16];
258 aes256_init(key, &ctx);
260 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
261 ultoa((unsigned long)t, str, 10);
266 aes256_enc(data, &ctx);
268 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
269 ultoa((unsigned long)t, str, 10);
274 aes256_dec(data, &ctx);
276 cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
277 ultoa((unsigned long)t, str, 10);
280 cli_putstr_P(PSTR("\r\n"));
283 void testrun_performance_aes(void){
284 cli_putstr_P(PSTR("\r\n -=AES Performance Test=-\r\n"));
285 cli_putstr_P(PSTR("\r\n AES-128\r\n"));
286 testrun_performance_aes128();
287 cli_putstr_P(PSTR("\r\n AES-192\r\n"));
288 testrun_performance_aes192();
289 cli_putstr_P(PSTR("\r\n AES-256\r\n"));
290 testrun_performance_aes256();
292 /*****************************************************************************
294 *****************************************************************************/
296 const char nessie_str[] PROGMEM = "nessie";
297 const char test_str[] PROGMEM = "test";
298 const char testkey_str[] PROGMEM = "testkey";
299 const char performance_str[] PROGMEM = "performance";
300 const char echo_str[] PROGMEM = "echo";
302 cmdlist_entry_t cmdlist[] PROGMEM = {
303 { nessie_str, NULL, testrun_nessie_aes },
304 { test_str, NULL, testrun_test_aes},
305 { testkey_str, NULL, testrun_testkey_aes},
306 { performance_str, NULL, testrun_performance_aes},
307 { echo_str, (void*)1, (void_fpt)echo_ctrl},
315 cli_rx = (cli_rx_fpt)uart0_getc;
316 cli_tx = (cli_tx_fpt)uart0_putc;
318 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
319 cli_putstr(algo_name);
320 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
321 cmd_interface(cmdlist);