]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-skipjack-test.c
modification to the build system
[avr-crypto-lib.git] / test_src / 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         uint64_t t;
63         char str[16];
64         uint8_t key[10], data[8];
65         
66         calibrateTimer();
67         print_overhead();
68         
69         memset(key,  0, 10);
70         memset(data, 0,  8);
71         
72         startTimer(1);
73         skipjack_enc(data, key);
74         t = stopTimer();
75         uart_putstr_P(PSTR("\r\n\tencrypt time: "));
76         ultoa((unsigned long)t, str, 10);
77         uart_putstr(str);
78         
79         
80         startTimer(1);
81         skipjack_dec(data, key);
82         t = stopTimer();
83         uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
84         ultoa((unsigned long)t, str, 10);
85         uart_putstr(str);
86         
87         uart_putstr_P(PSTR("\r\n"));
88 }
89
90 /*****************************************************************************
91  *  self tests                                                                                                                           *
92  *****************************************************************************/
93
94 void testencrypt(uint8_t* block, uint8_t* key){
95         uart_putstr("\r\n==testy-encrypt==\r\n key: ");
96         uart_hexdump(key,10);
97         uart_putstr("\r\n plain: ");
98         uart_hexdump(block,8);
99         skipjack_enc(block,key);
100         uart_putstr("\r\n crypt: ");
101         uart_hexdump(block,8);
102 }
103
104 void testdecrypt(uint8_t* block, uint8_t* key){
105         uart_putstr("\r\n==testy-decrypt==\r\n key: ");
106         uart_hexdump(key,10);
107         uart_putstr("\r\n crypt: ");
108         uart_hexdump(block,8);
109         skipjack_dec(block,key);
110         uart_putstr("\r\n plain: ");
111         uart_hexdump(block,8);
112 }
113
114 void testrun_skipjack(void){
115         uint8_t key[]={ 0x00, 0x99, 0x88, 0x77, 0x66,
116                                         0x55, 0x44, 0x33, 0x22, 0x11};
117         uint8_t data[]={ 0x33, 0x22, 0x11, 0x00, 0xdd, 0xcc, 0xbb, 0xaa};
118         testencrypt(data,key);
119         testdecrypt(data,key);  
120 }
121
122
123
124 /*****************************************************************************
125  *  main                                                                                                                                         *
126  *****************************************************************************/
127
128 int main (void){
129         char str[20];
130
131         DEBUG_INIT();
132         uart_putstr("\r\n");
133
134         uart_putstr("\r\n\r\nCrypto-VS (skipjack)\r\nloaded and running\r\n");
135
136         PGM_P    u   = PSTR("nessie\0test\0performance\0");
137         void_fpt v[] = {testrun_nessie_skipjack, testrun_skipjack, testrun_performance_skipjack};
138
139         while(1){ 
140                 if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
141                 if(execcommand_d0_P(str, u, v)<0){
142                         uart_putstr_P(PSTR("\r\nunknown command\r\n"));
143                 }
144                 continue;
145         error:
146                 uart_putstr("ERROR\r\n");
147         }
148         
149 }
150