]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-seed-test.c
9ff4b3ff220e593123b839836634b13dfbaccec2
[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 "nessie_bc_test.h"
36 #include "cli.h"
37 #include "performance_test.h"
38 #include "bcal-performance.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* 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         nessie_bc_ctx.blocksize_B =  16;
60         nessie_bc_ctx.keysize_b   = 128;
61         nessie_bc_ctx.name        = algo_name;
62         nessie_bc_ctx.ctx_size_B  = sizeof(seed_ctx_t);
63         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)seed_enc;
64         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)seed_dec;
65         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)seed_genctx_dummy;
66         
67         nessie_bc_run();
68         
69 }
70
71
72 void testrun_performance_seed(void){
73         bcal_performance_multiple(algolist);
74 }
75
76 /*****************************************************************************
77  *  self tests                                                               *
78  *****************************************************************************/
79
80 void testencrypt(uint8_t* block, uint8_t* key){
81         seed_ctx_t ctx;
82         cli_putstr("\r\n==testy-encrypt==\r\n key:   ");
83         cli_hexdump(key,16);
84         seed_init(key, &ctx);
85         cli_putstr("\r\n plain: ");
86         cli_hexdump(block,16);
87         seed_enc(block, &ctx);
88         cli_putstr("\r\n crypt: ");
89         cli_hexdump(block,16);
90 }
91
92 void testdecrypt(uint8_t* block, uint8_t* key){
93         seed_ctx_t ctx;
94         cli_putstr("\r\n==testy-decrypt==\r\n key:   ");
95         cli_hexdump(key,16);
96         seed_init(key, &ctx);
97         cli_putstr("\r\n crypt: ");
98         cli_hexdump(block,16);
99         seed_dec(block, &ctx);
100         cli_putstr("\r\n plain: ");
101         cli_hexdump(block,16);
102 }
103
104 void testrun_seed(void){
105         uint8_t keys[4][16]=
106                 { {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
107                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
108                   {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
109                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
110                   {     0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8,
111                         0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 },
112                   {     0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D,
113                         0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,}
114                 };
115         uint8_t datas[4][16]=
116                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
117                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
118                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
119                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
120                   {     0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
121                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
122                   {     0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
123                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
124                 };
125         uint8_t i=0;
126         for(i=0; i<4; ++i){
127                 testencrypt(datas[i],keys[i]);
128                 testdecrypt(datas[i],keys[i]);  
129         }
130 }
131
132
133
134 /*****************************************************************************
135  *  main                                                                     *
136  *****************************************************************************/
137
138 const char nessie_str[]      PROGMEM = "nessie";
139 const char test_str[]        PROGMEM = "test";
140 const char performance_str[] PROGMEM = "performance";
141 const char echo_str[]        PROGMEM = "echo";
142
143 cmdlist_entry_t cmdlist[] PROGMEM = {
144         { nessie_str,      NULL, testrun_nessie_seed},
145         { test_str,        NULL, testrun_seed},
146         { performance_str, NULL, testrun_performance_seed},
147         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
148         { NULL,            NULL, NULL}
149 };
150
151 int main (void){
152         DEBUG_INIT();
153         
154         cli_rx = (cli_rx_fpt)uart0_getc;
155         cli_tx = (cli_tx_fpt)uart0_putc;                
156         for(;;){
157                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
158                 cli_putstr(algo_name);
159                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
160                 cmd_interface(cmdlist);
161         }
162 }