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