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