]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-noekeon-test.c
changing performance measurment of blockciphers to bcal
[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 "cli.h"
32 #include "performance_test.h"
33 #include "bcal-performance.h"
34 #include "bcal_noekeon.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* algolist[] PROGMEM = {
43         (bcdesc_t*)&noekeon_direct_desc,
44         (bcdesc_t*)&noekeon_indirect_desc,
45         NULL
46 };
47 /*****************************************************************************
48  *  additional validation-functions                                                                                      *
49  *****************************************************************************/
50 void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
51         noekeon_init(key, ctx);
52 }
53
54 void testrun_nessie_noekeon_indirect(void){
55         char str[strlen(algo_name)+10];
56         strcpy(str, algo_name);
57         strcat(str, "-indirect");
58         
59         nessie_bc_ctx.blocksize_B =  16;
60         nessie_bc_ctx.keysize_b   = 128;
61         nessie_bc_ctx.name        = str;
62         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
63         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
64         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
65         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
66         
67         nessie_bc_run();
68 }
69
70 void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
71         memcpy(ctx, key, 16);
72 }
73
74 void testrun_nessie_noekeon_direct(void){
75         char str[strlen(algo_name)+10];
76         strcpy(str, algo_name);
77         strcat(str, "-Direct");
78         
79         nessie_bc_ctx.blocksize_B =  16;
80         nessie_bc_ctx.keysize_b   = 128;
81         nessie_bc_ctx.name        = str;
82         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
83         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
84         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
85         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
86         
87         nessie_bc_run();
88 }
89
90 void testrun_nessie_noekeon(void){
91         testrun_nessie_noekeon_direct();
92         testrun_nessie_noekeon_indirect();
93 }
94
95
96 void testrun_stdtest_rundirect(void* data, void* key){
97         cli_putstr_P(PSTR("\r\n                     "));
98         cli_putstr_P(PSTR("k = "));
99         cli_hexdump(key,16);
100         
101         cli_putstr_P(PSTR("\r\n                     "));
102         cli_putstr_P(PSTR("a = "));
103         cli_hexdump(data,16);
104         
105         noekeon_enc(data, key);
106         cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
107         cli_hexdump(data,16);
108         
109         noekeon_dec(data, key);
110         cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
111         cli_hexdump(data,16);
112         cli_putstr_P(PSTR("\r\n"));
113 }
114
115 void testrun_stdtest_runindirect(void* data, void* key){
116         noekeon_ctx_t ctx;
117         cli_putstr_P(PSTR("\r\n                     "));
118         cli_putstr_P(PSTR("k = "));
119         cli_hexdump(key,16);
120         
121         cli_putstr_P(PSTR("\r\n                     "));
122         cli_putstr_P(PSTR("a = "));
123         cli_hexdump(data,16);
124         noekeon_init(key, &ctx);
125         noekeon_enc(data, &ctx);
126         cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
127         cli_hexdump(data,16);
128         
129         noekeon_dec(data, &ctx);
130         cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
131         cli_hexdump(data,16);
132         cli_putstr_P(PSTR("\r\n"));
133 }
134
135 void testrun_stdtest_noekeon(void){
136         uint8_t key[16], data[16];
137         uint8_t key3[16];
138         noekeon_ctx_t ctx;
139         
140         cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n"));
141         
142         memset(key,  0, 16);
143         memset(data, 0, 16);
144         testrun_stdtest_runindirect(data, key);
145         
146         memset(key,  0xFF, 16);
147         memset(data, 0xFF, 16);
148         testrun_stdtest_runindirect(data, key);
149         
150         memset(key,  0, 16);
151         memset(data, 0, 16);
152         noekeon_init(key, &ctx);
153         noekeon_enc(data, &ctx);
154         memcpy(key3, data, 16);
155         memset(key,  0xFF, 16);
156         memset(data, 0xFF, 16);
157         noekeon_init(key, &ctx);
158         noekeon_enc(data, &ctx);
159         testrun_stdtest_runindirect(data, key3);
160         
161         cli_putstr_P(PSTR("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n"));
162         
163         memset(key,  0, 16);
164         memset(data, 0, 16);
165         testrun_stdtest_rundirect(data, key);
166         
167         memset(key,  0xFF, 16);
168         memset(data, 0xFF, 16);
169         testrun_stdtest_rundirect(data, key);
170         
171         memset(key,  0, 16);
172         memset(data, 0, 16);
173         noekeon_enc(data, key);
174         memcpy(key3, data, 16);
175         memset(key,  0xFF, 16);
176         memset(data, 0xFF, 16);
177         noekeon_enc(data, key);
178         testrun_stdtest_rundirect(data, key3);
179         
180 }
181
182 void testrun_performance_noekeon(void){
183         bcal_performance_multiple(algolist);
184 }
185 /*****************************************************************************
186  *  main                                                                                                                                         *
187  *****************************************************************************/
188
189 const char nessie_str[]      PROGMEM = "nessie";
190 const char test_str[]        PROGMEM = "test";
191 const char direct_str[]      PROGMEM = "direct";
192 const char indirect_str[]    PROGMEM = "indirect";
193 const char performance_str[] PROGMEM = "performance";
194 const char echo_str[]        PROGMEM = "echo";
195
196 cmdlist_entry_t cmdlist[] PROGMEM = {
197         { nessie_str,      NULL, testrun_nessie_noekeon},
198         { test_str,        NULL, testrun_stdtest_noekeon},
199         { direct_str,      NULL, testrun_nessie_noekeon_direct},
200         { indirect_str,    NULL, testrun_nessie_noekeon_indirect},
201         { performance_str, NULL, testrun_performance_noekeon},
202         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
203         { NULL,            NULL, NULL}
204 };
205
206 int main (void){
207         DEBUG_INIT();
208         
209         cli_rx = (cli_rx_fpt)uart0_getc;
210         cli_tx = (cli_tx_fpt)uart0_putc;                
211         for(;;){
212                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
213                 cli_putstr(algo_name);
214                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
215                 cmd_interface(cmdlist);
216         }
217 }