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/>.
24 #include "main-test-common.h"
26 #include <present80.h>
27 #include <present128.h>
28 #include "performance_test.h"
29 #include "bcal-performance.h"
30 #include "bcal-nessie.h"
31 #include "bcal_present80.h"
32 #include "bcal_present128.h"
34 char* algo_name = "Present";
36 const bcdesc_t* const algolist[] PROGMEM = {
37 (bcdesc_t*)&present80_desc,
38 (bcdesc_t*)&present128_desc,
41 /*****************************************************************************
42 * additional validation-functions *
43 *****************************************************************************/
44 void testrun_nessie_present(void){
45 bcal_nessie_multiple(algolist);
48 void testrun_selfenc(uint8_t* key, uint8_t* buffer){
51 cli_putstr_P(PSTR("\r\nkey : "));
53 cli_putstr_P(PSTR("\r\nplain : "));
54 cli_hexdump(buffer, 8);
55 present80_init(key, 80, &ctx);
56 present80_enc(buffer, &ctx);
57 cli_putstr_P(PSTR("\r\ncipher: "));
58 cli_hexdump(buffer, 8);
59 present80_dec(buffer, &ctx);
60 cli_putstr_P(PSTR("\r\nplain : "));
61 cli_hexdump(buffer, 8);
62 cli_putstr_P(PSTR("\r\n"));
65 void testrun_selfenc_128(uint8_t* key, uint8_t* buffer){
68 cli_putstr_P(PSTR("\r\nkey : "));
70 cli_putstr_P(PSTR("\r\nplain : "));
71 cli_hexdump(buffer, 8);
72 present128_init(key, 128, &ctx);
73 present128_enc(buffer, &ctx);
74 cli_putstr_P(PSTR("\r\ncipher: "));
75 cli_hexdump(buffer, 8);
76 present128_dec(buffer, &ctx);
77 cli_putstr_P(PSTR("\r\nplain : "));
78 cli_hexdump(buffer, 8);
79 cli_putstr_P(PSTR("\r\n"));
81 // void present_key_test(const uint8_t* key);
84 void testrun_self_present(void){
85 uint8_t buffer[8], key[10], i;
86 cli_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n"));
88 memset(buffer, (i&2)?0xff:0x00, 8);
89 memset(key, (i&1)?0xff:0x00, 10);
90 testrun_selfenc(key, buffer);
92 memset(buffer, 0x00, 8);
93 memset(key, 0x00, 10);
95 testrun_selfenc(key, buffer);
97 // present_key_test(key);
101 void testrun_self_present_128(void){
102 uint8_t buffer[8], key[16], i;
103 cli_putstr_P(PSTR("\r\n\r\n=== Testvectors from the paper ===\r\n"));
105 memset(buffer, (i&2)?0xff:0x00, 8);
106 memset(key, (i&1)?0xff:0x00, 16);
107 testrun_selfenc_128(key, buffer);
109 memset(buffer, 0x00, 8);
110 memset(key, 0x00, 16);
112 testrun_selfenc_128(key, buffer);
114 // present_key_test(key);
118 void testrun_performance_present(void){
119 bcal_performance_multiple(algolist);
122 /*****************************************************************************
124 *****************************************************************************/
126 const char nessie_str[] PROGMEM = "nessie";
127 const char test_str[] PROGMEM = "test";
128 const char test_128_str[] PROGMEM = "test-128";
129 const char performance_str[] PROGMEM = "performance";
130 const char echo_str[] PROGMEM = "echo";
132 const cmdlist_entry_t cmdlist[] PROGMEM = {
133 { nessie_str, NULL, testrun_nessie_present},
134 { test_str, NULL, testrun_self_present},
135 { test_128_str, NULL, testrun_self_present_128},
136 { performance_str, NULL, testrun_performance_present},
137 { echo_str, (void*)1, (void_fpt)echo_ctrl},
145 welcome_msg(algo_name);
146 cmd_interface(cmdlist);