]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-noekeon-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-noekeon-test.c
1 /* main-noekeon-test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  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 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "config.h"
27 #include "cli.h"
28 #include "dump.h"
29 #include "uart_lowlevel.h"
30 #include "sysclock.h"
31 #include "hw_gptm.h"
32
33 #include <noekeon/noekeon.h>
34 #include "nessie_bc_test.h"
35 #include "performance_test.h"
36 #include "bcal-performance.h"
37 #include "bcal_noekeon.h"
38
39 const char* algo_name = "Noekeon";
40
41 void uart0_putc(char byte){
42         uart_putc(UART_0, byte);
43 }
44
45 char uart0_getc(void){
46         return uart_getc(UART_0);
47 }
48
49 const bcdesc_t* algolist[] = {
50         (bcdesc_t*)&noekeon_direct_desc,
51         (bcdesc_t*)&noekeon_indirect_desc,
52         NULL
53 };
54 /*****************************************************************************
55  *  additional validation-functions                                                                                      *
56  *****************************************************************************/
57 void noekeon_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
58         noekeon_init(key, ctx);
59 }
60
61 void testrun_nessie_noekeon_indirect(void){
62         char str[strlen(algo_name)+10];
63         strcpy(str, algo_name);
64         strcat(str, "-indirect");
65         
66         nessie_bc_ctx.blocksize_B =  16;
67         nessie_bc_ctx.keysize_b   = 128;
68         nessie_bc_ctx.name        = str;
69         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
70         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
71         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
72         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy;
73         
74         nessie_bc_run();
75 }
76
77 void noekeon_genctx_dummy_direct(uint8_t* key, uint16_t keysize, void* ctx){
78         memcpy(ctx, key, 16);
79 }
80
81 void testrun_nessie_noekeon_direct(void){
82         char str[strlen(algo_name)+10];
83         strcpy(str, algo_name);
84         strcat(str, "-Direct");
85         
86         nessie_bc_ctx.blocksize_B =  16;
87         nessie_bc_ctx.keysize_b   = 128;
88         nessie_bc_ctx.name        = str;
89         nessie_bc_ctx.ctx_size_B  = sizeof(noekeon_ctx_t);
90         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)noekeon_enc;
91         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)noekeon_dec;
92         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)noekeon_genctx_dummy_direct;
93         
94         nessie_bc_run();
95 }
96
97 void testrun_nessie_noekeon(void){
98         testrun_nessie_noekeon_direct();
99         testrun_nessie_noekeon_indirect();
100 }
101
102
103 void testrun_stdtest_rundirect(void* data, void* key){
104         cli_putstr("\r\n                     ");
105         cli_putstr("k = ");
106         cli_hexdump(key,16);
107         
108         cli_putstr("\r\n                     ");
109         cli_putstr("a = ");
110         cli_hexdump(data,16);
111         
112         noekeon_enc(data, key);
113         cli_putstr("\r\nafter NESSIEencrypt, b = ");
114         cli_hexdump(data,16);
115         
116         noekeon_dec(data, key);
117         cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
118         cli_hexdump(data,16);
119         cli_putstr("\r\n");
120 }
121
122 void testrun_stdtest_runindirect(void* data, void* key){
123         noekeon_ctx_t ctx;
124         cli_putstr("\r\n                     ");
125         cli_putstr("k = ");
126         cli_hexdump(key,16);
127         
128         cli_putstr("\r\n                     ");
129         cli_putstr("a = ");
130         cli_hexdump(data,16);
131         noekeon_init(key, &ctx);
132         noekeon_enc(data, &ctx);
133         cli_putstr("\r\nafter NESSIEencrypt, b = ");
134         cli_hexdump(data,16);
135         
136         noekeon_dec(data, &ctx);
137         cli_putstr("\r\nafter NESSIEdecrypt, a?= ");
138         cli_hexdump(data,16);
139         cli_putstr("\r\n");
140 }
141
142 void testrun_stdtest_noekeon(void){
143         uint8_t key[16], data[16];
144         uint8_t key3[16];
145         noekeon_ctx_t ctx;
146         
147         cli_putstr("\r\nTest vectors for block cipher Noekeon in Indirect-Key Mode:\r\n");
148         
149         memset(key,  0, 16);
150         memset(data, 0, 16);
151         testrun_stdtest_runindirect(data, key);
152         
153         memset(key,  0xFF, 16);
154         memset(data, 0xFF, 16);
155         testrun_stdtest_runindirect(data, key);
156         
157         memset(key,  0, 16);
158         memset(data, 0, 16);
159         noekeon_init(key, &ctx);
160         noekeon_enc(data, &ctx);
161         memcpy(key3, data, 16);
162         memset(key,  0xFF, 16);
163         memset(data, 0xFF, 16);
164         noekeon_init(key, &ctx);
165         noekeon_enc(data, &ctx);
166         testrun_stdtest_runindirect(data, key3);
167         
168         cli_putstr("\r\nTest vectors for block cipher Noekeon in Direct-Key Mode:\r\n");
169         
170         memset(key,  0, 16);
171         memset(data, 0, 16);
172         testrun_stdtest_rundirect(data, key);
173         
174         memset(key,  0xFF, 16);
175         memset(data, 0xFF, 16);
176         testrun_stdtest_rundirect(data, key);
177         
178         memset(key,  0, 16);
179         memset(data, 0, 16);
180         noekeon_enc(data, key);
181         memcpy(key3, data, 16);
182         memset(key,  0xFF, 16);
183         memset(data, 0xFF, 16);
184         noekeon_enc(data, key);
185         testrun_stdtest_rundirect(data, key3);
186         
187 }
188
189 void testrun_performance_noekeon(void){
190         bcal_performance_multiple(algolist);
191 }
192 /*****************************************************************************
193  *  main                                                                                                                                         *
194  *****************************************************************************/
195
196 const char nessie_str[]      = "nessie";
197 const char test_str[]        = "test";
198 const char direct_str[]      = "direct";
199 const char indirect_str[]    = "indirect";
200 const char performance_str[] = "performance";
201 const char echo_str[]        = "echo";
202
203 cmdlist_entry_t cmdlist[] = {
204         { nessie_str,      NULL, testrun_nessie_noekeon},
205         { test_str,        NULL, testrun_stdtest_noekeon},
206         { direct_str,      NULL, testrun_nessie_noekeon_direct},
207         { indirect_str,    NULL, testrun_nessie_noekeon_indirect},
208         { performance_str, NULL, testrun_performance_noekeon},
209         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
210         { NULL,            NULL, NULL}
211 };
212
213 int main (void){
214         sysclk_set_freq(SYS_FREQ);
215         sysclk_mosc_verify_enable();
216         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
217         gptm_set_timer_32periodic(TIMER0);
218
219         cli_rx = uart0_getc;
220         cli_tx = uart0_putc;
221         
222         for(;;){
223                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
224                 cli_putstr(algo_name);
225                 cli_putstr("; ");
226                 cli_putstr(__DATE__);
227                 cli_putc(' ');
228                 cli_putstr(__TIME__);
229                 cli_putstr(")\r\nloaded and running\r\n");
230                 cmd_interface(cmdlist);
231         }
232 }