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