]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-mugi-test.c
verification seems to work now...
[avr-crypto-lib.git] / test_src / main-mugi-test.c
1 /* main-mugi-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  * MUGI test-suit
21  * 
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "mugi.h"
30 #include "nessie_stream_test.h"
31 #include "cli.h"
32 #include "performance_test.h"
33
34 #include <stdlib.h>
35 #include <stdint.h>
36 #include <string.h>
37
38 char* algo_name = "MUGI";
39
40 /*****************************************************************************
41  *  additional validation-functions                                                                                      *
42  *****************************************************************************/
43
44 void testrun_performance_mugi(void){
45         uint64_t t;
46         char str[16];
47         uint8_t key[16];
48         uint8_t iv[16];
49         mugi_ctx_t ctx;
50         
51         calibrateTimer();
52         print_overhead();       
53         
54         memset(key, 0, 16);
55         memset(iv,  0, 16);
56         
57         startTimer(1);
58         mugi_init(key, iv, &ctx);
59         t = stopTimer();
60         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
61         ultoa((unsigned long)t, str, 10);
62         cli_putstr(str);        
63         
64         startTimer(1);
65         mugi_gen(&ctx);
66         t = stopTimer();
67         cli_putstr_P(PSTR("\r\n\tencrypt time: "));
68         ultoa((unsigned long)t, str, 10);
69         cli_putstr(str);        
70         
71         cli_putstr_P(PSTR("\r\n"));     
72 }
73
74
75 void testrun_mugi(void){
76         uint8_t key[]={  0x00, 0x01, 0x02, 0x03,
77                          0x04, 0x05, 0x06, 0x07,
78                                          0x08, 0x09, 0x0a, 0x0b,
79                                          0x0c, 0x0d, 0x0e, 0x0f };
80         uint8_t iv[]= {  0xf0, 0xe0, 0xd0, 0xc0,
81                          0xb0, 0xa0, 0x90, 0x80,
82                                          0x70, 0x60, 0x50, 0x40,
83                                          0x30, 0x20, 0x10, 0x00 };
84         mugi_ctx_t ctx;
85         uint64_t output;
86         uint8_t i;
87         mugi_init(key, iv, &ctx);
88         cli_putstr_P(PSTR("\r\nkey = "));
89         cli_hexdump2(key, 16);
90         cli_putstr_P(PSTR("\r\niv  = "));
91         cli_hexdump2(iv, 16);
92         for(i=0; i<8; ++i){
93                 output = mugi_gen(&ctx);
94                 cli_putstr_P(PSTR("\r\nMUGI output: "));
95                 cli_hexdump(&output, 8);                                 
96         }                
97         
98         memset(key, 0, 16);
99         memset(iv,  0, 16);
100         mugi_init(key, iv, &ctx);
101         cli_putstr_P(PSTR("\r\nkey = "));
102         cli_hexdump2(key, 16);
103         cli_putstr_P(PSTR("\r\niv  = "));
104         cli_hexdump2(iv, 16);
105         for(i=0; i<8; ++i){
106                 output = mugi_gen(&ctx);
107                 cli_putstr_P(PSTR("\r\nMUGI output: "));
108                 cli_hexdump(&output, 8);                                 
109         }                
110 }
111
112 /*****************************************************************************
113  *  main                                                                                                                                         *
114  *****************************************************************************/
115
116 const char nessie_str[]      PROGMEM = "nessie";
117 const char test_str[]        PROGMEM = "test";
118 const char performance_str[] PROGMEM = "performance";
119 const char echo_str[]        PROGMEM = "echo";
120
121 cmdlist_entry_t cmdlist[] PROGMEM = {
122 //      { nessie_str,      NULL, testrun_nessie_arcfour },
123         { test_str,        NULL, testrun_mugi},
124         { performance_str, NULL, testrun_performance_mugi},
125         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
126         { NULL,            NULL, NULL}
127 };
128
129 int main (void){
130         DEBUG_INIT();
131         
132         cli_rx = (cli_rx_fpt)uart0_getc;
133         cli_tx = (cli_tx_fpt)uart0_putc;                
134         for(;;){
135                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
136                 cli_putstr(algo_name);
137                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
138                 cmd_interface(cmdlist);
139         }
140 }
141