]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-present-test.c
optimizing norx32
[avr-crypto-lib.git] / test_src / main-present-test.c
1 /* main-present-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * present test-suit
21  * 
22 */
23
24 #include "main-test-common.h"
25
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"
33
34 char *algo_name = "Present";
35
36 const bcdesc_t *const algolist[] PROGMEM = {
37         (bcdesc_t*)&present80_desc,
38         (bcdesc_t*)&present128_desc,
39         NULL
40 };
41 /*****************************************************************************
42  *  additional validation-functions                                                                                      *
43  *****************************************************************************/
44 void testrun_nessie_present(void){
45         bcal_nessie_multiple(algolist);
46 }
47
48 void testrun_selfenc(uint8_t *key, uint8_t *buffer){
49
50         present80_ctx_t ctx;
51         cli_putstr_P(PSTR("\r\nkey   : "));
52         cli_hexdump(key, 10);
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"));
63 }
64
65 void testrun_selfenc_128(uint8_t *key, uint8_t *buffer){
66
67         present128_ctx_t ctx;
68         cli_putstr_P(PSTR("\r\nkey   : "));
69         cli_hexdump(key, 16);
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"));
80 }
81 // void present_key_test(const uint8_t *key);
82
83
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"));
87         for(i=0; i<4; ++i){
88                 memset(buffer, (i&2)?0xff:0x00,  8);
89                 memset(key,    (i&1)?0xff:0x00, 10);
90                 testrun_selfenc(key, buffer);
91         }
92         memset(buffer, 0x00,  8);
93         memset(key,    0x00, 10);
94         key[0] = 0x80;
95         testrun_selfenc(key, buffer);
96
97 //      present_key_test(key);
98
99 }
100
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"));
104         for(i=0; i<4; ++i){
105                 memset(buffer, (i&2)?0xff:0x00,  8);
106                 memset(key,    (i&1)?0xff:0x00, 16);
107                 testrun_selfenc_128(key, buffer);
108         }
109         memset(buffer, 0x00,  8);
110         memset(key,    0x00, 16);
111         key[0] = 0x80;
112         testrun_selfenc_128(key, buffer);
113
114 //      present_key_test(key);
115
116 }
117
118 void testrun_performance_present(void){
119         bcal_performance_multiple(algolist);
120 }
121
122 /*****************************************************************************
123  *  main                                                                                                                                         *
124  *****************************************************************************/
125
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";
131
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},
138         { NULL,            NULL, NULL}
139 };
140
141 int main(void) {
142         main_setup();
143
144         for(;;){
145                 welcome_msg(algo_name);
146                 cmd_interface(cmdlist);
147     }
148
149 }