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