1 /* main-present-test.c */
3 This file is part of the Crypto-avr-lib/microcrypt-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* cipher_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 = cipher_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 uart_putstr_P(PSTR("\r\nkey : "));
62 uart_hexdump(key, 10);
63 uart_putstr_P(PSTR("\r\nplain : "));
64 uart_hexdump(buffer, 8);
65 present_init(key, 80, &ctx);
66 present_enc(buffer, &ctx);
67 uart_putstr_P(PSTR("\r\ncipher: "));
68 uart_hexdump(buffer, 8);
69 present_dec(buffer, &ctx);
70 uart_putstr_P(PSTR("\r\nplain : "));
71 uart_hexdump(buffer, 8);
72 uart_putstr_P(PSTR("\r\n"));
75 void testrun_self_present(void){
76 uint8_t buffer[8], key[10];
77 uart_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 uart_putstr_P(PSTR("\r\n"));
126 /*****************************************************************************
128 *****************************************************************************/
135 uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
136 uart_putstr(cipher_name);
137 uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
139 PGM_P u = PSTR("nessie\0test\0performance\0");
140 void_fpt v[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present};
143 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
144 if(execcommand_d0_P(str, u, v)<0){
145 uart_putstr_P(PSTR("\r\nunknown command\r\n"));
149 uart_putstr("ERROR\r\n");