]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-omac-noekeon-test.c
clean up
[avr-crypto-lib.git] / test_src / main-omac-noekeon-test.c
1 /* main-omac-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  * OMAC-Noekeon test-suit
21  * 
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "noekeon/noekeon.h"
30 #include "omac_noekeon.h"
31
32 #include "cli.h"
33 #include "nessie_mac_test.h"
34 #include "performance_test.h"
35
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <string.h>
39
40 char* algo_name = "OMAC-Noekeon";
41
42 /*****************************************************************************
43  *  additional validation-functions                                                                                      *
44  *****************************************************************************/
45
46 void test_mac(void* key, void* data, uint16_t datalength_b){
47         uint8_t mac[16];
48         cli_putstr_P(PSTR("\r\n-----------\r\n msg length (bit): 0x"));
49         cli_hexdump(((uint8_t*)&datalength_b)+1, 1);
50         cli_hexdump(((uint8_t*)&datalength_b)+0, 1);    
51         cli_putstr_P(PSTR("\r\n msg: "));
52         cli_hexdump(data, (datalength_b+7)/8);
53         cli_putstr_P(PSTR("\r\n key: "));
54         cli_hexdump(key, 16);
55         omac_noekeon(mac, data, datalength_b, key, (uint8_t)-1);
56         cli_putstr_P(PSTR("\r\n mac: "));
57         cli_hexdump(mac, 16);
58         
59 }
60
61 void testrun_test_omac_noekeon(void){
62         uint8_t key[16], data[64];
63         uint16_t i;
64         memset(key,  0xAA, 16);
65         memset(data, 0x00, 64);
66         for(i=1;i<64*8; ++i){
67                 test_mac(key, data, i);
68         }
69 }
70
71 /******************************************************************************/
72
73 uint8_t stat_key[16];
74
75 void omac_noekeon_next_dummy(void* ctx, const void* buffer){
76         omac_noekeon_next(buffer, stat_key, ctx);
77 }
78
79 void omac_noekeon_init_dummy(void* ctx, const void* key, uint16_t keysize_b){
80         omac_noekeon_init(ctx);
81         memcpy(stat_key, key, 16);
82 }
83
84 void omac_noekeon_last_dummy(void* ctx, const void* buffer, uint16_t size_b){
85         while(size_b>128){
86                 omac_noekeon_next(buffer, stat_key, ctx);
87                 size_b -= 128;
88                 buffer = (uint8_t*)buffer +16;
89         }
90         omac_noekeon_last(buffer, size_b, stat_key, ctx);
91 }
92
93 void omac_noekeon_conv_dummy(void* buffer, void* ctx){
94         memcpy(buffer, ctx, 16);
95 }
96
97 void testrun_nessie_omac_noekeon(void){
98         nessie_mac_ctx.macsize_b   = 128;
99         nessie_mac_ctx.keysize_b   = 128;
100         nessie_mac_ctx.blocksize_B = 16;
101         nessie_mac_ctx.ctx_size_B  = sizeof(omac_noekeon_ctx_t);
102         nessie_mac_ctx.name = algo_name;
103         nessie_mac_ctx.mac_init = omac_noekeon_init_dummy;
104         nessie_mac_ctx.mac_next = omac_noekeon_next_dummy;
105         nessie_mac_ctx.mac_last = omac_noekeon_last_dummy;
106         nessie_mac_ctx.mac_conv = omac_noekeon_conv_dummy;
107         
108         nessie_mac_run();
109 }
110
111 /******************************************************************************/
112
113 void testrun_performance_omac_noekeon(void){
114         uint64_t t;
115         char str[16];
116         uint8_t data[16], key[16];
117         omac_noekeon_ctx_t ctx;
118         
119         calibrateTimer();
120         print_overhead();
121         
122         memset(data, 0, 16);
123         memset(key,  0, 16);
124         
125         startTimer(1);
126         omac_noekeon_init(&ctx);
127         t = stopTimer();
128         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
129         ultoa((unsigned long)t, str, 10);
130         cli_putstr(str);
131         
132         
133         startTimer(1);
134         omac_noekeon_next(data, key, &ctx);
135         t = stopTimer();
136         cli_putstr_P(PSTR("\r\n\tone-block time: "));
137         ultoa((unsigned long)t, str, 10);
138         cli_putstr(str);
139         
140         
141         startTimer(1);
142         omac_noekeon_last(data, 128, key, &ctx);
143         t = stopTimer();
144         cli_putstr_P(PSTR("\r\n\tlast block time: "));
145         ultoa((unsigned long)t, str, 10);
146         cli_putstr(str);
147         
148         cli_putstr_P(PSTR("\r\n"));
149 }
150
151 /*****************************************************************************
152  *  main                                                                                                                                         *
153  *****************************************************************************/
154
155 const char nessie_str[]      PROGMEM = "nessie";
156 const char test_str[]        PROGMEM = "test";
157 const char performance_str[] PROGMEM = "performance";
158 const char echo_str[]        PROGMEM = "echo";
159
160 cmdlist_entry_t cmdlist[] PROGMEM = {
161         { nessie_str,      NULL, testrun_nessie_omac_noekeon },
162         { test_str,        NULL, testrun_test_omac_noekeon},
163         { performance_str, NULL, testrun_performance_omac_noekeon},
164         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
165         { NULL,            NULL, NULL}
166 };
167
168 int main (void){
169         DEBUG_INIT();
170         
171         cli_rx = (cli_rx_fpt)uart0_getc;
172         cli_tx = (cli_tx_fpt)uart0_putc;                
173         for(;;){
174                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
175                 cli_putstr(algo_name);
176                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
177                 cmd_interface(cmdlist);
178         }
179 }