]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-jh-test.c
48f41dc86d06fc2fd32a1e0196e70a9ecd3ed2b1
[avr-crypto-lib.git] / test_src / main-jh-test.c
1 /* main-jh-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2010 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  * JH test-suit
21  *
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "jh_simple.h"
30 #include "hfal_jh.h"
31 #include "hfal-nessie.h"
32 #include "hfal-test.h"
33 #include "hfal-performance.h"
34 #include "shavs.h"
35 #include "cli.h"
36 #include "nessie_hash_test.h"
37 #include "performance_test.h"
38
39 #include <stdint.h>
40 #include <string.h>
41 #include <stdlib.h>
42
43 char* algo_name = "JH";
44
45
46 const hfdesc_t* algolist[] PROGMEM = {
47         (hfdesc_t*)&jh224_desc,
48         (hfdesc_t*)&jh256_desc,
49         (hfdesc_t*)&jh384_desc,
50         (hfdesc_t*)&jh512_desc,
51         NULL
52 };
53
54 /*****************************************************************************
55  *  additional validation-functions                                                                                      *
56  *****************************************************************************/
57
58 void performance_jh(void){
59         hfal_performance_multiple(algolist);
60 }
61
62 void testrun_nessie_jh(void){
63         hfal_nessie_multiple(algolist);
64 }
65
66 void test256Null(void){
67         jh_ctx_t ctx;
68         uint8_t hash[32];
69         jh256_init(&ctx);
70         jh_lastBlock(&ctx, NULL, 0);
71         jh256_ctx2hash(hash, &ctx);
72         cli_putstr_P(PSTR("\r\nresult:\r\n"));
73         cli_hexdump_block(hash, 32, 4, 8);
74 }
75
76
77 void singleround_jh(void){
78         uint8_t data[] = {
79                 0x1,0,0,0,0,0,0,0x0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
80                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
81             0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
82             0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
83         jh_encrypt(data);
84         cli_putstr_P(PSTR("\r\nresult:\r\n"));
85         cli_hexdump_block(data, 128, 4, 16);
86 }
87
88 /*****************************************************************************
89  *  main                                                                                                                                         *
90  *****************************************************************************/
91
92
93 const char nessie_str[]       PROGMEM = "nessie";
94 const char test_str[]         PROGMEM = "test";
95 const char test256_str[]      PROGMEM = "test256";
96 const char performance_str[]  PROGMEM = "performance";
97 const char singleround_str[]  PROGMEM = "singleround";
98 const char echo_str[]         PROGMEM = "echo";
99 const char shavs_list_str[]   PROGMEM = "shavs_list";
100 const char shavs_set_str[]    PROGMEM = "shavs_set";
101 const char shavs_test1_str[]  PROGMEM = "shavs_test1";
102
103 cmdlist_entry_t cmdlist[] PROGMEM = {
104         { nessie_str,          NULL, testrun_nessie_jh},
105         { performance_str,     NULL, performance_jh},
106         { test256_str,         NULL, test256Null},
107         { singleround_str,     NULL, singleround_jh},
108         { shavs_list_str,      NULL, shavs_listalgos},
109         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
110         { shavs_test1_str,     NULL, shavs_test1},
111         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
112         { NULL,                NULL, NULL}
113 };
114
115 int main (void){
116         DEBUG_INIT();
117
118         cli_rx = (cli_rx_fpt)uart0_getc;
119         cli_tx = (cli_tx_fpt)uart0_putc;
120         shavs_algolist=(hfdesc_t**)algolist;
121         shavs_algo=(hfdesc_t*)&jh256_desc;
122         for(;;){
123                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
124                 cli_putstr(algo_name);
125                 cli_putstr_P(PSTR("; "));
126                 cli_putstr(__DATE__);
127                 cli_putstr_P(PSTR(" "));
128                 cli_putstr(__TIME__);
129                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
130
131                 cmd_interface(cmdlist);
132         }
133 }