]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-skipjack-test.c
a lot of fixes
[avr-crypto-lib.git] / test_src / main-skipjack-test.c
1 /* main-skipjack-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  * skipjack test-suit
21  * 
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "skipjack.h"
30 #include "nessie_bc_test.h"
31 #include "cli.h"
32 #include "performance_test.h"
33 #include "bcal-performance.h"
34 #include "bcal-nessie.h"
35 #include "bcal_skipjack.h"
36
37 #include <stdint.h>
38 #include <string.h>
39 #include <stdlib.h>
40
41
42 char* algo_name = "Skipjack";
43
44 const bcdesc_t* const algolist[] PROGMEM = {
45         (bcdesc_t*)&skipjack_desc,
46         NULL
47 };
48 /*****************************************************************************
49  *  additional validation-functions                                                                                      *
50  *****************************************************************************/
51 void skipjack_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
52         memcpy(ctx, key, 10);
53 }
54
55 void testrun_nessie_skipjack(void){
56         bcal_nessie_multiple(algolist);
57 }
58
59
60 void testrun_performance_skipjack(void){
61         bcal_performance_multiple(algolist);
62 }
63
64 /*****************************************************************************
65  *  self tests                                                                                                                           *
66  *****************************************************************************/
67
68 void testencrypt(uint8_t* block, uint8_t* key){
69         cli_putstr("\r\n==testy-encrypt==\r\n key: ");
70         cli_hexdump(key,10);
71         cli_putstr("\r\n plain: ");
72         cli_hexdump(block,8);
73         skipjack_enc(block,key);
74         cli_putstr("\r\n crypt: ");
75         cli_hexdump(block,8);
76 }
77
78 void testdecrypt(uint8_t* block, uint8_t* key){
79         cli_putstr("\r\n==testy-decrypt==\r\n key: ");
80         cli_hexdump(key,10);
81         cli_putstr("\r\n crypt: ");
82         cli_hexdump(block,8);
83         skipjack_dec(block,key);
84         cli_putstr("\r\n plain: ");
85         cli_hexdump(block,8);
86 }
87
88 void testrun_skipjack(void){
89         uint8_t key[2][10]={
90                              { 0x00, 0x99, 0x88, 0x77, 0x66,
91                                0x55, 0x44, 0x33, 0x22, 0x11 },
92                              { 0x11, 0x22, 0x33, 0x44, 0x55,
93                                0x66, 0x77, 0x88, 0x99, 0x00 }
94                                            };   
95                          
96         uint8_t data[2][8]={
97                                  { 0x33, 0x22, 0x11, 0x00, 
98                                    0xdd, 0xcc, 0xbb, 0xaa },
99                                  { 0xaa, 0xbb, 0xcc, 0xdd,
100                                    0x00, 0x11, 0x22, 0x33 }
101                                            };
102         testencrypt(data[0],key[0]);
103         testdecrypt(data[0],key[0]);
104         testencrypt(data[1],key[1]);
105         testdecrypt(data[1],key[1]);    
106 }
107
108
109
110 /*****************************************************************************
111  *  main                                                                                                                                         *
112  *****************************************************************************/
113
114 const char nessie_str[]      PROGMEM = "nessie";
115 const char test_str[]        PROGMEM = "test";
116 const char performance_str[] PROGMEM = "performance";
117 const char echo_str[]        PROGMEM = "echo";
118
119 const cmdlist_entry_t cmdlist[] PROGMEM = {
120         { nessie_str,      NULL, testrun_nessie_skipjack},
121         { test_str,        NULL, testrun_skipjack},
122         { performance_str, NULL, testrun_performance_skipjack},
123         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
124         { NULL,            NULL, NULL}
125 };
126
127 int main (void){
128         DEBUG_INIT();
129         
130         cli_rx = (cli_rx_fpt)uart0_getc;
131         cli_tx = (cli_tx_fpt)uart0_putc;                
132         for(;;){
133                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
134                 cli_putstr(algo_name);
135                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
136                 cmd_interface(cmdlist);
137         }
138 }