]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-trivium-test.c
a lot of fixes
[avr-crypto-lib.git] / test_src / main-trivium-test.c
1 /* main-trivium-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  * Mickey128 test-suit
21  * 
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28 #include "cli.h"
29
30 #include "trivium.h"
31 #include "scal_trivium.h"
32 #include "scal-basic.h"
33 #include "scal-nessie.h"
34 #include "performance_test.h"
35
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <string.h>
39
40 char* algo_name = "Trivium";
41
42 /*****************************************************************************
43  *  additional validation-functions                                                                                      *
44  *****************************************************************************/
45
46 void testrun_nessie_trivium(void){
47         scal_nessie_run(&trivium_desc);
48 }
49
50 void testrun_trivium(void){
51         uint8_t key[10];
52         uint8_t iv[4];
53         uint8_t buffer[64];
54         scgen_ctx_t ctx;
55         memset(key, 0, 10);
56         memset(iv, 0, 4);
57         key[0] = 0x80;
58         scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
59         scal_cipher_gen_fillblock(buffer, 64, &ctx);
60         cli_putstr_P(PSTR("\r\nTest:\r\n  Key     = "));
61         cli_hexdump(key, 10);
62         cli_putstr_P(PSTR("\r\n  IV      = "));
63         cli_hexdump(iv, 4);
64         cli_putstr_P(PSTR("\r\n  Cipher  = "));
65         cli_hexdump_block(buffer, 64, 4, 16);
66         scal_cipher_free(&ctx);
67         key[0] = 0x40;
68         scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
69         scal_cipher_gen_fillblock(buffer, 64, &ctx);
70         cli_putstr_P(PSTR("\r\nTest:\r\n  Key     = "));
71         cli_hexdump(key, 10);
72         cli_putstr_P(PSTR("\r\n  IV      = "));
73         cli_hexdump(iv, 4);
74         cli_putstr_P(PSTR("\r\n  Cipher  = "));
75         cli_hexdump_block(buffer, 64, 4, 16);
76         scal_cipher_free(&ctx);
77         key[0] = 0x20;
78         scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
79         scal_cipher_gen_fillblock(buffer, 64, &ctx);
80         cli_putstr_P(PSTR("\r\nTest:\r\n  Key     = "));
81         cli_hexdump(key, 10);
82         cli_putstr_P(PSTR("\r\n  IV      = "));
83         cli_hexdump(iv, 4);
84         cli_putstr_P(PSTR("\r\n  Cipher  = "));
85         cli_hexdump_block(buffer, 64, 4, 16);
86         scal_cipher_free(&ctx);
87         key[0] = 0x10;
88         scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
89         scal_cipher_gen_fillblock(buffer, 64, &ctx);
90         cli_putstr_P(PSTR("\r\nTest:\r\n  Key     = "));
91         cli_hexdump(key, 10);
92         cli_putstr_P(PSTR("\r\n  IV      = "));
93         cli_hexdump(iv, 4);
94         cli_putstr_P(PSTR("\r\n  Cipher  = "));
95         cli_hexdump_block(buffer, 64, 4, 16);
96         scal_cipher_free(&ctx);
97 }
98
99 void testrun_performance_trivium(void){
100         uint64_t t;
101         char str[16];
102         uint8_t key[10], iv[10];
103         trivium_ctx_t ctx;
104         
105         calibrateTimer();
106         print_overhead();
107         
108         memset(key,  0, 10);
109         memset(iv,  0, 10);
110         
111         startTimer(1);
112         trivium_init(key, 80, iv, 80, &ctx);
113         t = stopTimer();
114         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
115         ultoa((unsigned long)t, str, 10);
116         cli_putstr(str);        
117         
118         startTimer(1);
119         trivium_enc(&ctx);
120         t = stopTimer();
121         cli_putstr_P(PSTR("\r\n\tencrypt time: "));
122         ultoa((unsigned long)t, str, 10);
123         cli_putstr(str);        
124         
125         cli_putstr_P(PSTR("\r\n"));
126 }
127
128 /*****************************************************************************
129  *  main                                                                                                                                         *
130  *****************************************************************************/
131
132 const char nessie_str[]      PROGMEM = "nessie";
133 const char test_str[]        PROGMEM = "test";
134 const char performance_str[] PROGMEM = "performance";
135 const char echo_str[]        PROGMEM = "echo";
136
137 const cmdlist_entry_t cmdlist[] PROGMEM = {
138         { nessie_str,      NULL, testrun_nessie_trivium},
139         { test_str,        NULL, testrun_trivium},
140         { performance_str, NULL, testrun_performance_trivium},
141         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
142         { NULL,            NULL, NULL}
143 };
144
145 int main (void){
146         DEBUG_INIT();
147         
148         cli_rx = (cli_rx_fpt)uart0_getc;
149         cli_tx = (cli_tx_fpt)uart0_putc;                
150         for(;;){
151                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
152                 cli_putstr(algo_name);
153                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
154                 cmd_interface(cmdlist);
155         }
156 }