]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-serpent-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-serpent-test.c
1 /* main-serpent-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  * serpent test-suit
21  * 
22 */
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "config.h"
27 #include "cli.h"
28 #include "dump.h"
29 #include "uart_lowlevel.h"
30 #include "sysclock.h"
31 #include "hw_gptm.h"
32
33
34 #include "serpent.h"
35 #include "nessie_bc_test.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal_serpent.h"
39
40 char* algo_name = "Serpent";
41
42 void uart0_putc(char byte){
43         uart_putc(UART_0, byte);
44 }
45
46 char uart0_getc(void){
47         return uart_getc(UART_0);
48 }
49
50 const bcdesc_t* algolist[] = {
51         (bcdesc_t*)&serpent_desc,
52         NULL
53 };
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58
59 void testrun_nessie_serpent(void){
60         nessie_bc_ctx.blocksize_B =  16;
61         nessie_bc_ctx.keysize_b   = 128;
62         nessie_bc_ctx.name        = algo_name;
63         nessie_bc_ctx.ctx_size_B  = sizeof(serpent_ctx_t);
64         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)serpent_enc;
65         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)serpent_dec;
66         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)serpent_init;
67         
68         nessie_bc_run();
69         
70         nessie_bc_ctx.keysize_b   = 192;
71         nessie_bc_run();
72         
73         nessie_bc_ctx.keysize_b   = 256;
74         nessie_bc_run();
75 }
76
77 void testrun_test_serpent(void){
78         uint8_t key[32];
79         serpent_ctx_t ctx;
80         uint8_t i;
81         memset(key, 0, 16);
82         serpent_init(key, 128, &ctx);
83         for(i=0; i<33; ++i){
84                 cli_putstr("\r\n subkekey ");
85                 cli_hexdump(&i, 1);
86                 cli_putstr(" : ");
87                 cli_hexdump(ctx.k[i], 16);
88         }
89 }
90
91 void testrun_serpent256(void){
92         uint8_t key[32];
93         uint8_t data[16];
94         serpent_ctx_t ctx;
95         memset(key, 0, 32);
96         memset(data, 0, 16);
97         key[0] = 0x80;
98         cli_putstr("\r\n== small test Serpent-256 ==");
99         cli_putstr("\r\n  key    = ");
100         cli_hexdump(key, 32);
101         cli_putstr("\r\n  plain  = ");
102         cli_hexdump(data, 16);
103         serpent_init(key, 256, &ctx);
104         serpent_enc(data, &ctx);
105         cli_putstr("\r\n  cipher = ");
106         cli_hexdump(data, 16);
107 }
108
109 void testrun_performance_serpent(void){
110         bcal_performance_multiple(algolist);
111 }
112 /*****************************************************************************
113  *  main                                                                                                                                         *
114  *****************************************************************************/
115
116 const char nessie_str[]      = "nessie";
117 const char test_str[]        = "test";
118 const char test256_str[]     = "test256";
119 const char performance_str[] = "performance";
120 const char echo_str[]        = "echo";
121
122 const cmdlist_entry_t cmdlist[] = {
123         { nessie_str,      NULL, testrun_nessie_serpent},
124         { test_str,        NULL, testrun_test_serpent},
125         { test256_str,     NULL, testrun_serpent256},
126         { performance_str, NULL, testrun_performance_serpent},
127         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
128         { NULL,            NULL, NULL}
129 };
130
131 int main (void){
132         sysclk_set_freq(SYS_FREQ);
133         sysclk_mosc_verify_enable();
134         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
135         gptm_set_timer_32periodic(TIMER0);
136
137         cli_rx = uart0_getc;
138         cli_tx = uart0_putc;
139         
140         for(;;){
141                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
142                 cli_putstr(algo_name);
143                 cli_putstr("; ");
144                 cli_putstr(__DATE__);
145                 cli_putc(' ');
146                 cli_putstr(__TIME__);
147                 cli_putstr(")\r\nloaded and running\r\n");
148                 cmd_interface(cmdlist);
149         }
150 }