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