]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-blake-test.c
JH and Blake updated for round 3
[avr-crypto-lib.git] / test_src / main-blake-test.c
1 /* main-blake-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  * blake test-suit
21  *
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "blake_small.h"
30 #include "blake_large.h"
31 #include "hfal_blake_small.h"
32 #include "hfal_blake_large.h"
33 #include "hfal-nessie.h"
34 #include "hfal-test.h"
35 #include "hfal-performance.h"
36 #include "shavs.h"
37 #include "cli.h"
38 #include "nessie_hash_test.h"
39 #include "performance_test.h"
40
41 #include <stdint.h>
42 #include <string.h>
43 #include <stdlib.h>
44
45 char* algo_name = "Blake";
46
47
48 const hfdesc_t* algolist[] PROGMEM = {
49         (hfdesc_t*)&blake224_desc,
50         (hfdesc_t*)&blake256_desc,
51         (hfdesc_t*)&blake384_desc,
52         (hfdesc_t*)&blake512_desc,
53         NULL
54 };
55
56 /*****************************************************************************
57  *  additional validation-functions                                                                                      *
58  *****************************************************************************/
59
60 void testrun_nessie_blake(void){
61         hfal_nessie_multiple(algolist);
62 }
63 void blake224_test(void* msg, uint32_t length_b){
64         hfal_test(&blake224_desc, msg, length_b);
65 }
66
67 void blake256_test(void* msg, uint32_t length_b){
68         hfal_test(&blake256_desc, msg, length_b);
69 }
70
71 void blake384_test(void* msg, uint32_t length_b){
72         hfal_test(&blake384_desc, msg, length_b);
73 }
74
75 void blake512_test(void* msg, uint32_t length_b){
76         hfal_test(&blake512_desc, msg, length_b);
77 }
78 void testrun_stdtest_blake(void){
79         uint8_t msg1[144];
80         memset(msg1, 0, 144);
81         blake224_test("", 0);
82         blake224_test("", 8);
83         blake224_test(msg1, 576);
84         blake256_test("", 0);
85         blake256_test("", 8);
86         blake256_test(msg1, 576);
87         blake384_test("", 0);
88         blake384_test("", 8);
89         blake384_test(msg1, 1152);
90         blake512_test("", 0);
91         blake512_test("", 8);
92         blake512_test(msg1, 1152);
93 }
94
95 void testshort(void){
96         blake256_test("", 8);
97 }
98
99 void testlshort(void){
100         blake512_test("", 8);
101 }
102
103 void test512_32(void){
104   uint8_t d[] = { 0xE9, 0x26, 0xAE, 0x8B, 0x0A, 0xF6, 0xE5, 0x31,
105                                  0x76, 0xDB, 0xFF, 0xCC, 0x2A, 0x6B, 0x88, 0xC6,
106                                  0xBD, 0x76, 0x5F, 0x93, 0x9D, 0x3D, 0x17, 0x8A,
107                                  0x9B, 0xDE, 0x9E, 0xF3, 0xAA, 0x13, 0x1C, 0x61,
108                                  0xE3, 0x1C, 0x1E, 0x42, 0xCD, 0xFA, 0xF4, 0xB4,
109                                  0xDC, 0xDE, 0x57, 0x9A, 0x37, 0xE1, 0x50, 0xEF,
110                                  0xBE, 0xF5, 0x55, 0x5B, 0x4C, 0x1C, 0xB4, 0x04,
111                                  0x39, 0xD8, 0x35, 0xA7, 0x24, 0xE2, 0xFA, 0xE7 };
112         blake256_test(d, 512);
113 }
114
115 void performance_blake(void){
116         hfal_performance_multiple(algolist);
117 }
118
119 /*****************************************************************************
120  *  main                                                                                                                                         *
121  *****************************************************************************/
122
123
124 const char nessie_str[]       PROGMEM = "nessie";
125 const char test_str[]         PROGMEM = "test";
126 const char testshort_str[]    PROGMEM = "short";
127 const char testlshort_str[]   PROGMEM = "lshort";
128 const char test512_str[]      PROGMEM = "test512";
129 const char performance_str[]  PROGMEM = "performance";
130 const char echo_str[]         PROGMEM = "echo";
131 const char shavs_list_str[]   PROGMEM = "shavs_list";
132 const char shavs_set_str[]    PROGMEM = "shavs_set";
133 const char shavs_test1_str[]  PROGMEM = "shavs_test1";
134 const char shavs_test3_str[]  PROGMEM = "shavs_test3";
135
136 cmdlist_entry_t cmdlist[] PROGMEM = {
137         { nessie_str,          NULL, testrun_nessie_blake},
138         { test_str,            NULL, testrun_stdtest_blake},
139         { testshort_str,       NULL, testshort},
140         { testlshort_str,      NULL, testlshort},
141         { test512_str,         NULL, test512_32},
142         { performance_str,     NULL, performance_blake},
143         { shavs_list_str,      NULL, shavs_listalgos},
144         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
145         { shavs_test1_str,     NULL, shavs_test1},
146         { shavs_test3_str,     NULL, shavs_test3},
147         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
148         { NULL,                NULL, NULL}
149 };
150
151 int main (void){
152         DEBUG_INIT();
153
154         cli_rx = (cli_rx_fpt)uart0_getc;
155         cli_tx = (cli_tx_fpt)uart0_putc;
156         shavs_algolist=(hfdesc_t**)algolist;
157         shavs_algo=(hfdesc_t*)&blake256_desc;
158         for(;;){
159                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
160                 cli_putstr(algo_name);
161                 cli_putstr_P(PSTR("; "));
162                 cli_putstr(__DATE__);
163                 cli_putstr_P(PSTR(" "));
164                 cli_putstr(__TIME__);
165                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
166
167                 cmd_interface(cmdlist);
168         }
169 }