]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-trivium-test.c
trivium broken :-(
[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-nessie.h"
33 #include "performance_test.h"
34
35 #include <stdlib.h>
36 #include <stdint.h>
37 #include <string.h>
38
39 char* algo_name = "Trivium";
40
41 /*****************************************************************************
42  *  additional validation-functions                                                                                      *
43  *****************************************************************************/
44
45 void testrun_nessie_trivium(void){
46         scal_nessie_run(&trivium_desc);
47 }
48
49 void testrun_trivium(void){
50         uint8_t key[10];
51         uint8_t iv[4];
52         uint8_t buffer[64];
53         scgen_ctx_t ctx;
54         memset(key, 0, 10);
55         memset(iv, 0, 4);
56         key[0] = 0x80;
57         scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
58         scal_cipher_gen_fillblock(buffer, 64, &ctx);
59         cli_putstr_P(PSTR("\r\nTest:\r\n  Key     = "));
60         cli_hexdump(key, 10);
61         cli_putstr_P(PSTR("\r\n  IV      = "));
62         cli_hexdump(iv, 4);
63         cli_putstr_P(PSTR("\r\n  Cipher  = "));
64         cli_hexdump_block(buffer, 64, 4, 8);
65         scal_cipher_free(&ctx);
66         key[0] = 0x00;
67         key[9] = 0x80;
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, 8);
76         scal_cipher_free(&ctx);
77 }
78
79 void testrun_performance_trivium(void){
80         uint64_t t;
81         char str[16];
82         uint8_t key[10], iv[10];
83         trivium_ctx_t ctx;
84         
85         calibrateTimer();
86         print_overhead();
87         
88         memset(key,  0, 10);
89         memset(iv,  0, 10);
90         
91         startTimer(1);
92         trivium_init(key, 80, iv, 80, &ctx);
93         t = stopTimer();
94         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
95         ultoa((unsigned long)t, str, 10);
96         cli_putstr(str);        
97         
98         startTimer(1);
99         trivium_enc(&ctx);
100         t = stopTimer();
101         cli_putstr_P(PSTR("\r\n\tencrypt time: "));
102         ultoa((unsigned long)t, str, 10);
103         cli_putstr(str);        
104         
105         cli_putstr_P(PSTR("\r\n"));
106 }
107
108 /*****************************************************************************
109  *  main                                                                                                                                         *
110  *****************************************************************************/
111
112 const char nessie_str[]      PROGMEM = "nessie";
113 const char test_str[]        PROGMEM = "test";
114 const char performance_str[] PROGMEM = "performance";
115 const char echo_str[]        PROGMEM = "echo";
116
117 cmdlist_entry_t cmdlist[] PROGMEM = {
118         { nessie_str,      NULL, testrun_nessie_trivium},
119         { test_str,        NULL, testrun_trivium},
120         { performance_str, NULL, testrun_performance_trivium},
121         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
122         { NULL,            NULL, NULL}
123 };
124
125 int main (void){
126         DEBUG_INIT();
127         
128         cli_rx = (cli_rx_fpt)uart0_getc;
129         cli_tx = (cli_tx_fpt)uart0_putc;                
130         for(;;){
131                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
132                 cli_putstr(algo_name);
133                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
134                 cmd_interface(cmdlist);
135         }
136 }