]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-bmw-test.c
2da30a0097576b1bd1737ddd9dae1e6f4f4d92e2
[avr-crypto-lib.git] / test_src / main-bmw-test.c
1 /* main-bmw-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  * BlueMidnightWish test-suit
21  *
22 */
23
24 #include "config.h"
25 #include "uart_i.h"
26 #include "debug.h"
27
28 #include "bmw_small.h"
29 #include "bmw_large.h"
30 #include "cli.h"
31 #include "hfal_bmw_small.h"
32 #include "hfal_bmw_large.h"
33 #include "shavs.h"
34 #include "nessie_hash_test.h"
35 #include "performance_test.h"
36 #include "hfal-nessie.h"
37 #include "hfal-performance.h"
38 #include "hfal-test.h"
39
40 #include <stdint.h>
41 #include <string.h>
42 #include <stdlib.h>
43
44 char* algo_name = "BlueMidnightWish";
45
46
47 const hfdesc_t* algolist[] PROGMEM = {
48         (hfdesc_t*)&bmw224_desc,
49         (hfdesc_t*)&bmw256_desc,
50         (hfdesc_t*)&bmw384_desc,
51         (hfdesc_t*)&bmw512_desc,
52         NULL
53 };
54
55 /*****************************************************************************
56  *  additional validation-functions                                                                                      *
57  *****************************************************************************/
58
59 void performance_bmw(void){
60         hfal_performance_multiple(algolist);
61 }
62
63 void testrun_nessie_bmw(void){
64         hfal_nessie_multiple(algolist);
65 }
66
67 void bmw224_test(void* msg, uint32_t length_b){
68         hfal_test(&bmw224_desc, msg, length_b);
69 }
70
71 void bmw256_test(void* msg, uint32_t length_b){
72         hfal_test(&bmw256_desc, msg, length_b);
73 }
74 void bmw384_test(void* msg, uint32_t length_b){
75         hfal_test(&bmw384_desc, msg, length_b);
76 }
77
78 void bmw512_test(void* msg, uint32_t length_b){
79         hfal_test(&bmw512_desc, msg, length_b);
80 }
81
82 void test506(void){
83         /* Testvector of length = 506 from short KAT */
84         uint8_t v[] = {
85                 0xB9, 0xE3, 0xE2, 0x75, 0x5E, 0xD1, 0x21, 0x53,
86                 0x81, 0xB2, 0x45, 0x57, 0xEE, 0x14, 0xF8, 0xCD,
87                 0x26, 0x87, 0xA0, 0x71, 0xAE, 0xB3, 0xC7, 0x4F,
88                 0x42, 0x1C, 0xFE, 0xA3, 0xCF, 0xF8, 0xA6, 0xEA,
89                 0x0D, 0x4B, 0xDA, 0x2A, 0xD4, 0xBD, 0x82, 0x43,
90                 0xCB, 0xA7, 0x2B, 0x48, 0x1C, 0xBD, 0x52, 0x6E,
91                 0x1E, 0xFA, 0x1D, 0x9F, 0xD4, 0x32, 0xB9, 0x87,
92                 0xE8, 0x12, 0x65, 0x82, 0x44, 0x29, 0xBA, 0xC0 };
93         bmw512_test(v, 506);
94 }
95
96 void test507(void){
97         /* Testvector of length = 506 from short KAT */
98         uint8_t v[] = {
99                 0xE8, 0x33, 0x25, 0x35, 0xE9, 0xA2, 0x05, 0x24,
100                 0x67, 0xA1, 0x02, 0x05, 0xC8, 0x70, 0x00, 0xBF,
101                 0xC6, 0xA6, 0x8D, 0x73, 0x96, 0x2E, 0x69, 0xE4,
102                 0xE5, 0x6F, 0x10, 0xBC, 0x79, 0xC6, 0x33, 0xC5,
103                 0x2F, 0x4D, 0x00, 0x74, 0xD6, 0x07, 0x75, 0x95,
104                 0xB6, 0x60, 0x07, 0x2E, 0x10, 0x74, 0x0D, 0xFA,
105                 0x66, 0xBC, 0x13, 0x20, 0x46, 0x9A, 0x31, 0x96,
106                 0xE0, 0x21, 0xE1, 0x32, 0x7C, 0xC0, 0x3A, 0xE0 };
107         bmw512_test(v, 507);
108 }
109
110 void testrun_stdtest_bmw(void){
111         char* msg0 = "abc";
112         char* msg1 = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
113         bmw224_test(msg0, strlen(msg0)*8);
114         bmw224_test(msg1, strlen(msg1)*8);
115         bmw256_test(msg0, strlen(msg0)*8);
116         bmw256_test(msg1, strlen(msg1)*8);
117         bmw384_test(msg0, strlen(msg0)*8);
118         bmw384_test(msg1, strlen(msg1)*8);
119         bmw512_test(msg0, strlen(msg0)*8);
120         bmw512_test(msg1, strlen(msg1)*8);
121 }
122
123 void bmw256_short_test(void* msg, uint32_t length_b){
124         bmw256_test("abc", 3*8);
125 }
126
127
128 void testshort(void){
129         char* msg0 = "abc";
130         bmw224_test(msg0, strlen(msg0)*8);
131 }
132
133 void testlshort(void){
134         char* msg0 = "abc";
135         bmw384_test(msg0, strlen(msg0)*8);
136 }
137
138 /*****************************************************************************
139  *  main                                                                                                                                         *
140  *****************************************************************************/
141
142 const char nessie_str[]      PROGMEM = "nessie";
143 const char test_str[]        PROGMEM = "test";
144 const char test224_str[]     PROGMEM = "test224";
145 const char test256_str[]     PROGMEM = "test256";
146 const char test384_str[]     PROGMEM = "test384";
147 const char test512_str[]     PROGMEM = "test512";
148 const char test506_str[]     PROGMEM = "506";
149 const char test507_str[]     PROGMEM = "507";
150 const char testshort_str[]   PROGMEM = "short";
151 const char testlshort_str[]  PROGMEM = "lshort";
152 const char performance_str[] PROGMEM = "performance";
153 const char echo_str[]        PROGMEM = "echo";
154 const char shavs_list_str[]  PROGMEM = "shavs_list";
155 const char shavs_set_str[]   PROGMEM = "shavs_set";
156 const char shavs_test1_str[] PROGMEM = "shavs_test1";
157 const char shavs_test3_str[] PROGMEM = "shavs_test3";
158
159 cmdlist_entry_t cmdlist[] PROGMEM = {
160         { nessie_str,                  NULL, testrun_nessie_bmw            },
161         { test_str,                    NULL, testrun_stdtest_bmw           },
162         { testshort_str,               NULL, testshort                     },
163         { testlshort_str,              NULL, testlshort                    },
164         { test506_str,                 NULL, test506                       },
165         { test507_str,                 NULL, test507                       },
166         { performance_str,             NULL, performance_bmw               },
167         { shavs_list_str,              NULL, shavs_listalgos               },
168         { shavs_set_str,           (void*)1, (void_fpt)shavs_setalgo       },
169         { shavs_test1_str,             NULL, shavs_test1                   },
170         { shavs_test3_str,             NULL, shavs_test3                   },
171         { echo_str,                (void*)1, (void_fpt)echo_ctrl           },
172         { NULL,                        NULL, NULL                          }
173 };
174
175 int main (void){
176         DEBUG_INIT();
177
178         cli_rx = (cli_rx_fpt)uart0_getc;
179         cli_tx = (cli_tx_fpt)uart0_putc;
180         shavs_algolist=(hfdesc_t**)algolist;
181         shavs_algo=(hfdesc_t*)&bmw256_desc;
182         for(;;){
183                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
184                 cli_putstr(algo_name);
185                 cli_putstr_P(PSTR("; "));
186                 cli_putstr(__DATE__);
187                 cli_putstr_P(PSTR(" "));
188                 cli_putstr(__TIME__);
189                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
190
191                 cmd_interface(cmdlist);
192         }
193 }