]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-seed-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-seed-test.c
1 /* main-seed-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  * \file        main-seed-test.c
21  * \author      Daniel Otte
22  * \email       daniel.otte@rub.de
23  * \date        2007-06-01
24  * \brief       test suit for SEED
25  * \par License 
26  * GPLv3 or later
27  * 
28  */
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include "config.h"
33 #include "cli.h"
34 #include "dump.h"
35 #include "uart_lowlevel.h"
36 #include "sysclock.h"
37 #include "hw_gptm.h"
38
39 #include "seed.h"
40 #include "nessie_bc_test.h"
41 #include "performance_test.h"
42 #include "bcal-performance.h"
43 #include "bcal_seed.h"
44
45
46 char* algo_name = "Seed";
47
48 void uart0_putc(char byte){
49         uart_putc(UART_0, byte);
50 }
51
52 char uart0_getc(void){
53         return uart_getc(UART_0);
54 }
55
56 const bcdesc_t* algolist[] = {
57         (bcdesc_t*)&seed_desc,
58         NULL
59 };
60 /*****************************************************************************
61  *  additional validation-functions                                          *
62  *****************************************************************************/
63 void seed_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
64         seed_init(key, ctx);
65 }
66
67 void testrun_nessie_seed(void){
68         nessie_bc_ctx.blocksize_B =  16;
69         nessie_bc_ctx.keysize_b   = 128;
70         nessie_bc_ctx.name        = algo_name;
71         nessie_bc_ctx.ctx_size_B  = sizeof(seed_ctx_t);
72         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)seed_enc;
73         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)seed_dec;
74         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)seed_genctx_dummy;
75         
76         nessie_bc_run();
77         
78 }
79
80
81 void testrun_performance_seed(void){
82         bcal_performance_multiple(algolist);
83 }
84
85 /*****************************************************************************
86  *  self tests                                                               *
87  *****************************************************************************/
88
89 void testencrypt(uint8_t* block, uint8_t* key){
90         seed_ctx_t ctx;
91         cli_putstr("\r\n==testy-encrypt==\r\n key:   ");
92         cli_hexdump(key,16);
93         seed_init(key, &ctx);
94         cli_putstr("\r\n plain: ");
95         cli_hexdump(block,16);
96         seed_enc(block, &ctx);
97         cli_putstr("\r\n crypt: ");
98         cli_hexdump(block,16);
99 }
100
101 void testdecrypt(uint8_t* block, uint8_t* key){
102         seed_ctx_t ctx;
103         cli_putstr("\r\n==testy-decrypt==\r\n key:   ");
104         cli_hexdump(key,16);
105         seed_init(key, &ctx);
106         cli_putstr("\r\n crypt: ");
107         cli_hexdump(block,16);
108         seed_dec(block, &ctx);
109         cli_putstr("\r\n plain: ");
110         cli_hexdump(block,16);
111 }
112
113 void testrun_seed(void){
114         uint8_t keys[4][16]=
115                 { {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
116                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
117                   {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
118                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
119                   {     0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8,
120                         0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 },
121                   {     0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D,
122                         0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,}
123                 };
124         uint8_t datas[4][16]=
125                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
126                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
127                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
128                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
129                   {     0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
130                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
131                   {     0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
132                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
133                 };
134         uint8_t i=0;
135         for(i=0; i<4; ++i){
136                 testencrypt(datas[i],keys[i]);
137                 testdecrypt(datas[i],keys[i]);  
138         }
139 }
140
141
142
143 /*****************************************************************************
144  *  main                                                                     *
145  *****************************************************************************/
146
147 const char nessie_str[]      = "nessie";
148 const char test_str[]        = "test";
149 const char performance_str[] = "performance";
150 const char echo_str[]        = "echo";
151
152 cmdlist_entry_t cmdlist[] = {
153         { nessie_str,      NULL, testrun_nessie_seed},
154         { test_str,        NULL, testrun_seed},
155         { performance_str, NULL, testrun_performance_seed},
156         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
157         { NULL,            NULL, NULL}
158 };
159
160 int main (void){
161         sysclk_set_freq(SYS_FREQ);
162         sysclk_mosc_verify_enable();
163         uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
164         gptm_set_timer_32periodic(TIMER0);
165
166         cli_rx = uart0_getc;
167         cli_tx = uart0_putc;
168         
169         for(;;){
170                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
171                 cli_putstr(algo_name);
172                 cli_putstr("; ");
173                 cli_putstr(__DATE__);
174                 cli_putc(' ');
175                 cli_putstr(__TIME__);
176                 cli_putstr(")\r\nloaded and running\r\n");
177                 cmd_interface(cmdlist);
178         }
179 }