]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-noekeon-test.c
a lot of fixes
[avr-crypto-lib.git] / test_src / main-noekeon-test.c
1 /* main-noekeon-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  * noekeon test-suit
21  * 
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "noekeon.h"
30 #include "bcal-nessie.h"
31 #include "performance_test.h"
32 #include "bcal-performance.h"
33 #include "bcal_noekeon.h"
34 #include "cli.h"
35
36 #include <stdint.h>
37 #include <string.h>
38 #include <stdlib.h>
39
40 char* algo_name = "Noekeon";
41
42 const bcdesc_t* const algolist[] PROGMEM = {
43         (bcdesc_t*)&noekeon_direct_desc,
44         (bcdesc_t*)&noekeon_indirect_desc,
45         NULL
46 };
47 /*****************************************************************************
48  *  additional validation-functions                                                                                      *
49  *****************************************************************************/
50
51 void testrun_nessie_noekeon(void){
52         bcal_nessie_multiple(algolist);
53 }
54
55
56 void testrun_stdtest_rundirect(void* data, void* key){
57         cli_putstr_P(PSTR("\r\n                     "));
58         cli_putstr_P(PSTR("k = "));
59         cli_hexdump(key,16);
60
61         cli_putstr_P(PSTR("\r\n                     "));
62         cli_putstr_P(PSTR("a = "));
63         cli_hexdump(data,16);
64         
65         noekeon_enc(data, key);
66         cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
67         cli_hexdump(data,16);
68         
69         noekeon_dec(data, key);
70         cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
71         cli_hexdump(data,16);
72         cli_putstr_P(PSTR("\r\n"));
73 }
74
75 void testrun_stdtest_runindirect(void* data, void* key){
76         noekeon_ctx_t ctx;
77         cli_putstr_P(PSTR("\r\n                     "));
78         cli_putstr_P(PSTR("k = "));
79         cli_hexdump(key,16);
80         
81         cli_putstr_P(PSTR("\r\n                     "));
82         cli_putstr_P(PSTR("a = "));
83         cli_hexdump(data,16);
84         noekeon_init(key, &ctx);
85         noekeon_enc(data, &ctx);
86         cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
87         cli_hexdump(data,16);
88         
89         noekeon_dec(data, &ctx);
90         cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
91         cli_hexdump(data,16);
92         cli_putstr_P(PSTR("\r\n"));
93 }
94
95 void testrun_stdtest_noekeon(void){
96         uint8_t key[16], data[16];
97         uint8_t key3[16];
98         noekeon_ctx_t ctx;
99         
100         cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n"));
101         
102         memset(key,  0, 16);
103         memset(data, 0, 16);
104         testrun_stdtest_runindirect(data, key);
105         
106         memset(key,  0xFF, 16);
107         memset(data, 0xFF, 16);
108         testrun_stdtest_runindirect(data, key);
109         
110         memset(key,  0, 16);
111         memset(data, 0, 16);
112         noekeon_init(key, &ctx);
113         noekeon_enc(data, &ctx);
114         memcpy(key3, data, 16);
115         memset(key,  0xFF, 16);
116         memset(data, 0xFF, 16);
117         noekeon_init(key, &ctx);
118         noekeon_enc(data, &ctx);
119         testrun_stdtest_runindirect(data, key3);
120         
121         cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n"));
122         
123         memset(key,  0, 16);
124         memset(data, 0, 16);
125         testrun_stdtest_rundirect(data, key);
126         
127         memset(key,  0xFF, 16);
128         memset(data, 0xFF, 16);
129         testrun_stdtest_rundirect(data, key);
130         
131         memset(key,  0, 16);
132         memset(data, 0, 16);
133         noekeon_enc(data, key);
134         memcpy(key3, data, 16);
135         memset(key,  0xFF, 16);
136         memset(data, 0xFF, 16);
137         noekeon_enc(data, key);
138         testrun_stdtest_rundirect(data, key3);
139         
140 }
141
142 void testrun_performance_noekeon(void){
143         bcal_performance_multiple(algolist);
144 }
145 /*****************************************************************************
146  *  main                                                                                                                                         *
147  *****************************************************************************/
148
149 const char nessie_str[]      PROGMEM = "nessie";
150 const char test_str[]        PROGMEM = "test";
151 const char direct_str[]      PROGMEM = "direct";
152 const char indirect_str[]    PROGMEM = "indirect";
153 const char performance_str[] PROGMEM = "performance";
154 const char echo_str[]        PROGMEM = "echo";
155
156 const cmdlist_entry_t cmdlist[] PROGMEM = {
157         { nessie_str,      NULL, testrun_nessie_noekeon},
158         { test_str,        NULL, testrun_stdtest_noekeon},
159 //      { direct_str,      NULL, testrun_nessie_noekeon_direct},
160 //      { indirect_str,    NULL, testrun_nessie_noekeon_indirect},
161         { performance_str, NULL, testrun_performance_noekeon},
162         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
163         { NULL,            NULL, NULL}
164 };
165
166 int main (void){
167         DEBUG_INIT();
168         
169         cli_rx = (cli_rx_fpt)uart0_getc;
170         cli_tx = (cli_tx_fpt)uart0_putc;                
171         for(;;){
172                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
173                 cli_putstr(algo_name);
174                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
175                 cmd_interface(cmdlist);
176         }
177 }