]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-khazad-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-khazad-test.c
1 /* main-khazad-test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2011  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  * khazad 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 #include "khazad.h"
34 #include "performance_test.h"
35 #include "bcal-performance.h"
36 #include "bcal-nessie.h"
37 #include "bcal_khazad.h"
38
39 char* algo_name = "Khazad";
40
41 void uart0_putc(char byte){
42         uart_putc(UART_0, byte);
43 }
44
45 char uart0_getc(void){
46         return uart_getc(UART_0);
47 }
48
49 const bcdesc_t* algolist[] = {
50         (bcdesc_t*)&khazad_desc,
51         NULL
52 };
53
54 /*****************************************************************************
55  *  additional validation-functions                                                                                      *
56  *****************************************************************************/
57
58 void testrun_nessie_khazad(void){
59         bcal_nessie(&khazad_desc);
60 }
61
62 void testrun_performance_khazad(void){
63         bcal_performance_multiple(algolist);
64 }
65
66 void test_khazad(void){
67         uint8_t key[16];
68         uint8_t data[8];
69         khazad_ctx_t ctx;
70
71         memset(key, 0, 16);
72         memset(data, 0, 8);
73         key[0] = 0x80;
74         cli_putstr("\r\nkey:   ");
75         cli_hexdump(key, 16);
76         khazad_init(key, &ctx);
77         cli_putstr("\r\nround keys:");
78         cli_hexdump_block(&ctx, 8*8, 4, 8);
79         cli_putstr("\r\nplain:  ");
80         cli_hexdump(data, 8);
81         khazad_enc(data, &ctx);
82         cli_putstr("\r\nencrypt:");
83         cli_hexdump(data, 8);
84         khazad_dec(data, &ctx);
85         cli_putstr("\r\ndecrypt:");
86         cli_hexdump(data, 8);
87 }
88
89 void test_sbox(void){
90         uint8_t i=0,x;
91         cli_putstr("\r\nKhazad Sbox:\r\n\t");
92         do{
93                 x = khazad_sbox(i);
94                 cli_hexdump_byte(x);
95                 cli_putc(' ');
96                 if(i%16==15){
97                         cli_putstr("\r\n\t");
98                 }
99                 ++i;
100         }while(i);
101 }
102
103 /*****************************************************************************
104  *  main                                                                                                                                         *
105  *****************************************************************************/
106
107 const char nessie_str[]      = "nessie";
108 const char test_str[]        = "test";
109 const char test_sbox_str[]   = "test_sbox";
110 const char performance_str[] = "performance";
111 const char echo_str[]        = "echo";
112
113 cmdlist_entry_t cmdlist[] = {
114         { nessie_str,      NULL, testrun_nessie_khazad},
115         { test_str,        NULL, test_khazad},
116         { test_sbox_str,   NULL, test_sbox},
117         { performance_str, NULL, testrun_performance_khazad},
118         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
119         { NULL,            NULL, NULL}
120 };
121
122 int main (void){
123         sysclk_set_freq(SYS_FREQ);
124         sysclk_mosc_verify_enable();
125         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
126         gptm_set_timer_32periodic(TIMER0);
127
128         cli_rx = uart0_getc;
129         cli_tx = uart0_putc;
130         
131         for(;;){
132                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
133                 cli_putstr(algo_name);
134                 cli_putstr("; ");
135                 cli_putstr(__DATE__);
136                 cli_putc(' ');
137                 cli_putstr(__TIME__);
138                 cli_putstr(")\r\nloaded and running\r\n");
139                 cmd_interface(cmdlist);
140         }
141 }