]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-skipjack-test.c
fixing E-Mail-Address & Copyright
[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) 2006-2015 Daniel Otte (bg@nerilex.org)
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 "main-test-common.h"
25
26 #include "skipjack.h"
27 #include "nessie_bc_test.h"
28 #include "performance_test.h"
29 #include "bcal-performance.h"
30 #include "bcal-nessie.h"
31 #include "bcal_skipjack.h"
32
33 char *algo_name = "Skipjack";
34
35 const bcdesc_t *const algolist[] PROGMEM = {
36         (bcdesc_t*)&skipjack_desc,
37         NULL
38 };
39 /*****************************************************************************
40  *  additional validation-functions                                                                                      *
41  *****************************************************************************/
42 void skipjack_genctx_dummy(uint8_t *key, uint16_t keysize, void *ctx){
43         memcpy(ctx, key, 10);
44 }
45
46 void testrun_nessie_skipjack(void){
47         bcal_nessie_multiple(algolist);
48 }
49
50
51 void testrun_performance_skipjack(void){
52         bcal_performance_multiple(algolist);
53 }
54
55 int test_enc(const void *buffer, void *key){
56         uint8_t data[8];
57         int r;
58         memcpy(data, buffer, 8);
59         skipjack_enc(data, key);
60         cli_putstr_P(PSTR("  key = "));
61         cli_hexdump(key, 10);
62         cli_putstr_P(PSTR(" plaintext = "));
63         cli_hexdump(buffer, 8);
64         cli_putstr_P(PSTR(" ciphertext = "));
65         cli_hexdump(data, 8);
66         skipjack_dec(data, key);
67         r = memcmp(data, buffer, 8);
68         cli_putstr_P(PSTR(" decrypt: "));
69         if(r){
70                 cli_putstr_P(PSTR("fail"));
71         }else{
72                 cli_putstr_P(PSTR("ok"));
73         }
74         return r;
75 }
76
77 void testrun_nist_vectors(void){
78         uint8_t key[10];
79         uint8_t data[8];
80         uint8_t i;
81
82         cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 1 ==="));
83         memset(key, 0, 10);
84         for(i=0; i<64; ++i){
85                 memset(data, 0, 8);
86                 data[i>>3] |= 0x80 >> (i & 7);
87                 cli_putstr_P(PSTR("\r\n round: 0x"));
88                 cli_hexdump_byte(i);
89                 test_enc(data, key);
90         }
91
92         cli_putstr_P(PSTR("\r\n\r\n=== NIST vectors run 2 ==="));
93         memset(data, 0, 8);
94         for(i=0; i<80; ++i){
95                 memset(key, 0, 10);
96                 key[i>>3] |= 0x80 >> (i & 7);
97                 cli_putstr_P(PSTR("\r\n round: 0x"));
98                 cli_hexdump_byte(i);
99                 test_enc(data, key);
100         }
101 }
102
103 /*****************************************************************************
104  *  self tests                                                                                                                           *
105  *****************************************************************************/
106
107 void testencrypt(uint8_t *block, uint8_t *key){
108         cli_putstr("\r\n==testy-encrypt==\r\n key: ");
109         cli_hexdump(key,10);
110         cli_putstr("\r\n plain: ");
111         cli_hexdump(block,8);
112         skipjack_enc(block,key);
113         cli_putstr("\r\n crypt: ");
114         cli_hexdump(block,8);
115 }
116
117 void testdecrypt(uint8_t *block, uint8_t *key){
118         cli_putstr("\r\n==testy-decrypt==\r\n key: ");
119         cli_hexdump(key,10);
120         cli_putstr("\r\n crypt: ");
121         cli_hexdump(block,8);
122         skipjack_dec(block,key);
123         cli_putstr("\r\n plain: ");
124         cli_hexdump(block,8);
125 }
126
127 void testrun_skipjack(void){
128         uint8_t key[2][10]={
129                              { 0x00, 0x99, 0x88, 0x77, 0x66,
130                                0x55, 0x44, 0x33, 0x22, 0x11 },
131                              { 0x11, 0x22, 0x33, 0x44, 0x55,
132                                0x66, 0x77, 0x88, 0x99, 0x00 }
133                                            };   
134                          
135         uint8_t data[2][8]={
136                                  { 0x33, 0x22, 0x11, 0x00, 
137                                    0xdd, 0xcc, 0xbb, 0xaa },
138                                  { 0xaa, 0xbb, 0xcc, 0xdd,
139                                    0x00, 0x11, 0x22, 0x33 }
140                                            };
141         testencrypt(data[0],key[0]);
142         testdecrypt(data[0],key[0]);
143         testencrypt(data[1],key[1]);
144         testdecrypt(data[1],key[1]);    
145 }
146
147
148
149 /*****************************************************************************
150  *  main                                                                                                                                         *
151  *****************************************************************************/
152
153 const char nessie_str[]      PROGMEM = "nessie";
154 const char test_str[]        PROGMEM = "test";
155 const char nist_str[]        PROGMEM = "nist";
156 const char performance_str[] PROGMEM = "performance";
157 const char echo_str[]        PROGMEM = "echo";
158
159 const cmdlist_entry_t cmdlist[] PROGMEM = {
160         { nessie_str,      NULL, testrun_nessie_skipjack},
161         { test_str,        NULL, testrun_skipjack},
162         { nist_str,        NULL, testrun_nist_vectors},
163         { performance_str, NULL, testrun_performance_skipjack},
164         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
165         { NULL,            NULL, NULL}
166 };
167
168 int main (void){
169     main_setup();
170
171     for(;;){
172         welcome_msg(algo_name);
173         cmd_interface(cmdlist);
174         }
175 }