]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-skipjack-test.c
skipjack testvectors seem broken
[avr-crypto-lib.git] / main-skipjack-test.c
1 /* main-skipjack-test.c */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-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 #include "serial-tools.h"
26 #include "uart.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
34 #include <stdint.h>
35 #include <string.h>
36 #include <stdlib.h>
37
38
39 char* cipher_name = "Skipjack";
40
41 /*****************************************************************************
42  *  additional validation-functions                                                                                      *
43  *****************************************************************************/
44 void skipjack_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
45         memcpy(ctx, key, 10);
46 }
47
48 void testrun_nessie_skipjack(void){
49         nessie_bc_ctx.blocksize_B =   8;
50         nessie_bc_ctx.keysize_b   =  80;
51         nessie_bc_ctx.name        = cipher_name;
52         nessie_bc_ctx.ctx_size_B  = 10;
53         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)skipjack_enc;
54         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)skipjack_dec;
55         nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)skipjack_genctx_dummy;
56         
57         nessie_bc_run();
58 }
59
60
61 void testrun_performance_skipjack(void){
62         uint16_t i,c;
63         uint64_t t;
64         char str[16];
65         uint8_t key[10], data[8];
66         
67         calibrateTimer();
68         getOverhead(&c, &i);
69         uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
70         utoa(c, str, 10);
71         uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
72         uart_putstr(str);
73         utoa(i, str, 10);
74         uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
75         uart_putstr(str);
76         
77         memset(key,  0, 10);
78         memset(data, 0,  8);
79         
80         startTimer(1);
81         skipjack_enc(data, key);
82         t = stopTimer();
83         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
84         ultoa((unsigned long)t, str, 10);
85         uart_putstr(str);
86         
87         
88         startTimer(1);
89         skipjack_dec(data, key);
90         t = stopTimer();
91         uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
92         ultoa((unsigned long)t, str, 10);
93         uart_putstr(str);
94         
95         uart_putstr_P(PSTR("\r\n"));
96 }
97
98 /*****************************************************************************
99  *  self tests                                                                                                                           *
100  *****************************************************************************/
101
102 void testencrypt(uint8_t* block, uint8_t* key){
103         uart_putstr("\r\n==testy-encrypt==\r\n key: ");
104         uart_hexdump(key,10);
105         uart_putstr("\r\n plain: ");
106         uart_hexdump(block,8);
107         skipjack_enc(block,key);
108         uart_putstr("\r\n crypt: ");
109         uart_hexdump(block,8);
110 }
111
112 void testdecrypt(uint8_t* block, uint8_t* key){
113         uart_putstr("\r\n==testy-decrypt==\r\n key: ");
114         uart_hexdump(key,10);
115         uart_putstr("\r\n crypt: ");
116         uart_hexdump(block,8);
117         skipjack_dec(block,key);
118         uart_putstr("\r\n plain: ");
119         uart_hexdump(block,8);
120 }
121
122 void testrun_skipjack(void){
123         uint8_t key[]={ 0x00, 0x99, 0x88, 0x77, 0x66,
124                                         0x55, 0x44, 0x33, 0x22, 0x11};
125         uint8_t data[]={ 0x33, 0x22, 0x11, 0x00, 0xdd, 0xcc, 0xbb, 0xaa};
126         testencrypt(data,key);
127         testdecrypt(data,key);  
128 }
129
130
131
132 /*****************************************************************************
133  *  main                                                                                                                                         *
134  *****************************************************************************/
135
136 int main (void){
137         char str[20];
138
139         DEBUG_INIT();
140         uart_putstr("\r\n");
141
142         uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n");
143
144         PGM_P    u   = PSTR("nessie\0test\0performance\0");
145         void_fpt v[] = {testrun_nessie_skipjack, testrun_skipjack, testrun_performance_skipjack};
146
147         while(1){ 
148                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
149                 if(execcommand_d0_P(str, u, v)<0){
150                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
151                 }
152                 continue;
153         error:
154                 uart_putstr("ERROR\r\n");
155         }
156         
157 }
158