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