]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-omac-noekeon-test.c
forgot a file
[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 Crypto-avr-lib/microcrypt-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 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "noekeon.h"
30 #include "omac_noekeon.h"
31
32 #include "cli.h"
33 #include "nessie_mac_test.h"
34
35 #include <stdint.h>
36 #include <string.h>
37
38 char* algo_name = "OMAC-Noekeon";
39
40 /*****************************************************************************
41  *  additional validation-functions                                                                                      *
42  *****************************************************************************/
43
44 void test_mac(void* key, void* data, uint16_t datalength_b){
45         uint8_t mac[16];
46         uart_putstr_P(PSTR("\r\n-----------\r\n msg length (bit): 0x"));
47         uart_hexdump(((uint8_t*)&datalength_b)+1, 1);
48         uart_hexdump(((uint8_t*)&datalength_b)+0, 1);   
49         uart_putstr_P(PSTR("\r\n msg: "));
50         uart_hexdump(data, (datalength_b+7)/8);
51         uart_putstr_P(PSTR("\r\n key: "));
52         uart_hexdump(key, 16);
53         omac_noekeon(mac, data, datalength_b, key, (uint8_t)-1);
54         uart_putstr_P(PSTR("\r\n mac: "));
55         uart_hexdump(mac, 16);
56         
57 }
58
59 void testrun_test_noekeonomac(void){
60         uint8_t key[16], data[64];
61         uint16_t i;
62         memset(key,  0xAA, 16);
63         memset(data, 0x00, 64);
64         for(i=1;i<64*8; ++i){
65                 test_mac(key, data, i);
66         }
67 }
68
69 /******************************************************************************/
70
71 uint8_t stat_key[16];
72
73 void noekeonomac_next_dummy(void* buffer, void* ctx){
74         omac_noekeon_next(buffer, stat_key, ctx);
75 }
76
77 void noekeonomac_init_dummy(void* key, uint16_t keysize_b, void* ctx){
78         omac_noekeon_init(ctx);
79         memcpy(stat_key, key, 16);
80 }
81
82 void noekeonomac_last_dummy(void* buffer, uint16_t size_b, void* key, uint16_t keysize_b, void* ctx){
83         while(size_b>128){
84                 omac_noekeon_next(buffer, key, ctx);
85                 size_b -= 128;
86                 buffer = (uint8_t*)buffer +16;
87         }
88         omac_noekeon_last(buffer, size_b, key, ctx);
89 }
90
91 void noekeonomac_conv_dummy(void* buffer, void* ctx){
92         memcpy(buffer, ctx, 16);
93 }
94
95 void testrun_nessie_noekeonomac(void){
96         nessie_mac_ctx.macsize_b   = 128;
97         nessie_mac_ctx.keysize_b   = 128;
98         nessie_mac_ctx.blocksize_B = 16;
99         nessie_mac_ctx.ctx_size_B  = sizeof(noekeon_omac_ctx_t);
100         nessie_mac_ctx.name = algo_name;
101         nessie_mac_ctx.mac_init = noekeonomac_init_dummy;
102         nessie_mac_ctx.mac_next = noekeonomac_next_dummy;
103         nessie_mac_ctx.mac_last = noekeonomac_last_dummy;
104         nessie_mac_ctx.mac_conv = noekeonomac_conv_dummy;
105         
106         nessie_mac_run();
107 }
108
109
110
111
112 /*****************************************************************************
113  *  main                                                                                                                                         *
114  *****************************************************************************/
115
116 int main (void){
117         char  str[20];
118         DEBUG_INIT();
119         uart_putstr("\r\n");
120
121         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
122         uart_putstr(algo_name);
123         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
124
125         PGM_P    u   = PSTR("nessie\0test\0");
126         void_fpt v[] = {testrun_nessie_noekeonomac, testrun_test_noekeonomac};
127
128         while(1){ 
129                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
130                 if(execcommand_d0_P(str, u, v)<0){
131                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
132                 }
133                 continue;
134         error:
135                 uart_putstr("ERROR\r\n");
136         }
137         
138 }
139