1 /* main-present-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/>.
25 #include "serial-tools.h"
30 #include "nessie_bc_test.h"
32 #include "performance_test.h"
38 char* algo_name = "Present";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
43 void present_genctx_dummy(uint8_t* key, uint16_t keysize_b, present_ctx_t* ctx){
44 present_init(key, keysize_b, ctx);
47 void testrun_nessie_present(void){
48 nessie_bc_ctx.blocksize_B = 8;
49 nessie_bc_ctx.keysize_b = 80;
50 nessie_bc_ctx.name = algo_name;
51 nessie_bc_ctx.ctx_size_B = sizeof(present_ctx_t);
52 nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)present_enc;
53 nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)present_dec;
54 nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)present_genctx_dummy;
59 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
61 cli_putstr_P(PSTR("\r\nkey : "));
63 cli_putstr_P(PSTR("\r\nplain : "));
64 cli_hexdump(buffer, 8);
65 present_init(key, 80, &ctx);
66 present_enc(buffer, &ctx);
67 cli_putstr_P(PSTR("\r\ncipher: "));
68 cli_hexdump(buffer, 8);
69 present_dec(buffer, &ctx);
70 cli_putstr_P(PSTR("\r\nplain : "));
71 cli_hexdump(buffer, 8);
72 cli_putstr_P(PSTR("\r\n"));
75 void testrun_self_present(void){
76 uint8_t buffer[8], key[10];
77 cli_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n"));
81 testrun_selfenc(key, buffer);
84 memset(key, 0xFF, 10);
85 testrun_selfenc(key, buffer);
87 memset(buffer, 0xFF, 8);
89 testrun_selfenc(key, buffer);
91 memset(buffer, 0xFF, 8);
92 memset(key, 0xFF, 10);
93 testrun_selfenc(key, buffer);
97 void testrun_performance_present(void){
99 uint8_t key[10], data[8];
109 present_init(key, 80, &ctx);
111 print_time_P(PSTR("\tctx-gen time: "),t);
114 present_enc(data, &ctx);
116 print_time_P(PSTR("\tencrypt time: "), t);
119 present_dec(data, &ctx);
121 print_time_P(PSTR("\tdecrypt time: "), t);
123 cli_putstr_P(PSTR("\r\n"));
126 /*****************************************************************************
128 *****************************************************************************/
130 const char nessie_str[] PROGMEM = "nessie";
131 const char test_str[] PROGMEM = "test";
132 const char performance_str[] PROGMEM = "performance";
133 const char echo_str[] PROGMEM = "echo";
135 cmdlist_entry_t cmdlist[] PROGMEM = {
136 { nessie_str, NULL, testrun_nessie_present},
137 { test_str, NULL, testrun_self_present},
138 { performance_str, NULL, testrun_performance_present},
139 { echo_str, (void*)1, (void_fpt)echo_ctrl},
149 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
150 cli_putstr(algo_name);
151 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
152 cmd_interface(cmdlist);