]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-trivium-test.c
new cli system
[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 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28 #include "cli.h"
29
30 #include "trivium.h"
31 #include "nessie_stream_test.h"
32 #include "performance_test.h"
33
34 #include <stdlib.h>
35 #include <stdint.h>
36 #include <string.h>
37
38 char* algo_name = "Trivium";
39
40 /*****************************************************************************
41  *  additional validation-functions                                                                                      *
42  *****************************************************************************/
43 void trivium_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
44         uint32_t iv=0;
45         trivium_init(key, 80, &iv, 32, ctx);
46 }
47
48 uint8_t trivium_getbyte_dummy(trivium_ctx_t* ctx){
49         uint8_t i,ret=0;
50         for(i=0; i<8; ++i){
51                 ret<<=1;
52                 ret |= trivium_enc(ctx);
53         }
54         return ret;
55 }
56
57 void testrun_nessie_trivium(void){
58         nessie_stream_ctx.outsize_b =   8; /* actually unused */
59         nessie_stream_ctx.keysize_b =  80; /* this is the one we have refrence vectors for */
60         nessie_stream_ctx.ivsize_b  =  32;
61         nessie_stream_ctx.name = algo_name;
62         nessie_stream_ctx.ctx_size_B = sizeof(trivium_ctx_t);
63         nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)trivium_genctx_dummy;
64         nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)trivium_getbyte_dummy;
65         
66         nessie_stream_run();    
67 }
68
69 void testrun_performance_trivium(void){
70         uint64_t t;
71         char str[16];
72         uint8_t key[10], iv[10];
73         trivium_ctx_t ctx;
74         
75         calibrateTimer();
76         print_overhead();
77         
78         memset(key,  0, 10);
79         memset(iv,  0, 10);
80         
81         startTimer(1);
82         trivium_init(key, 80, iv, 80, &ctx);
83         t = stopTimer();
84         uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
85         ultoa((unsigned long)t, str, 10);
86         uart_putstr(str);       
87         
88         startTimer(1);
89         trivium_enc(&ctx);
90         t = stopTimer();
91         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
92         ultoa((unsigned long)t, str, 10);
93         uart_putstr(str);       
94         
95         uart_putstr_P(PSTR("\r\n"));
96 }
97
98 /*****************************************************************************
99  *  main                                                                                                                                         *
100  *****************************************************************************/
101
102 const char nessie_str[]      PROGMEM = "nessie";
103 const char test_str[]        PROGMEM = "test";
104 const char performance_str[] PROGMEM = "performance";
105 const char echo_str[]        PROGMEM = "echo";
106
107 cmdlist_entry_t cmdlist[] PROGMEM = {
108         { nessie_str,      NULL, testrun_nessie_trivium},
109         { test_str,        NULL, testrun_nessie_trivium},
110         { performance_str, NULL, testrun_performance_trivium},
111         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
112         { NULL,            NULL, NULL}
113 };
114
115 int main (void){
116         DEBUG_INIT();
117         uart_putstr("\r\n");
118         cli_rx = uart_getc;
119         cli_tx = uart_putc;             
120         for(;;){
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                 cmd_interface(cmdlist);
125         }
126 }