]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-seed-test.c
a lot of fixes
[avr-crypto-lib.git] / test_src / main-seed-test.c
1 /* main-seed-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  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 "config.h"
30
31 #include "uart_i.h"
32 #include "debug.h"
33
34 #include "seed.h"
35 #include "cli.h"
36 #include "performance_test.h"
37 #include "bcal-performance.h"
38 #include "bcal-nessie.h"
39 #include "bcal_seed.h"
40
41 #include <stdint.h>
42 #include <string.h>
43 #include <stdlib.h>
44
45 char* algo_name = "Seed";
46
47 const bcdesc_t* const algolist[] PROGMEM = {
48         (bcdesc_t*)&seed_desc,
49         NULL
50 };
51 /*****************************************************************************
52  *  additional validation-functions                                          *
53  *****************************************************************************/
54 void seed_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
55         seed_init(key, ctx);
56 }
57
58 void testrun_nessie_seed(void){
59         bcal_nessie_multiple(algolist);
60 }
61
62
63 void testrun_performance_seed(void){
64         bcal_performance_multiple(algolist);
65 }
66
67 /*****************************************************************************
68  *  self tests                                                               *
69  *****************************************************************************/
70
71 void testencrypt(uint8_t* block, uint8_t* key){
72         seed_ctx_t ctx;
73         cli_putstr("\r\n==testy-encrypt==\r\n key:   ");
74         cli_hexdump(key,16);
75         seed_init(key, &ctx);
76         cli_putstr("\r\n plain: ");
77         cli_hexdump(block,16);
78         seed_enc(block, &ctx);
79         cli_putstr("\r\n crypt: ");
80         cli_hexdump(block,16);
81 }
82
83 void testdecrypt(uint8_t* block, uint8_t* key){
84         seed_ctx_t ctx;
85         cli_putstr("\r\n==testy-decrypt==\r\n key:   ");
86         cli_hexdump(key,16);
87         seed_init(key, &ctx);
88         cli_putstr("\r\n crypt: ");
89         cli_hexdump(block,16);
90         seed_dec(block, &ctx);
91         cli_putstr("\r\n plain: ");
92         cli_hexdump(block,16);
93 }
94
95 void testrun_seed(void){
96         uint8_t keys[4][16]=
97                 { {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
98                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
99                   {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
100                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
101                   {     0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8,
102                         0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 },
103                   {     0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D,
104                         0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,}
105                 };
106         uint8_t datas[4][16]=
107                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
108                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
109                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
110                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
111                   {     0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
112                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
113                   {     0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
114                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
115                 };
116         uint8_t i=0;
117         for(i=0; i<4; ++i){
118                 testencrypt(datas[i],keys[i]);
119                 testdecrypt(datas[i],keys[i]);  
120         }
121 }
122
123
124
125 /*****************************************************************************
126  *  main                                                                     *
127  *****************************************************************************/
128
129 const char nessie_str[]      PROGMEM = "nessie";
130 const char test_str[]        PROGMEM = "test";
131 const char performance_str[] PROGMEM = "performance";
132 const char echo_str[]        PROGMEM = "echo";
133
134 const cmdlist_entry_t cmdlist[] PROGMEM = {
135         { nessie_str,      NULL, testrun_nessie_seed},
136         { test_str,        NULL, testrun_seed},
137         { performance_str, NULL, testrun_performance_seed},
138         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
139         { NULL,            NULL, NULL}
140 };
141
142 int main (void){
143         DEBUG_INIT();
144         
145         cli_rx = (cli_rx_fpt)uart0_getc;
146         cli_tx = (cli_tx_fpt)uart0_putc;                
147         for(;;){
148                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
149                 cli_putstr(algo_name);
150                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
151                 cmd_interface(cmdlist);
152         }
153 }