]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-keccak-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-keccak-test.c
1 /* main-keccak-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  * Keccak test-suit
21  *
22 */
23
24 #include "main-test-common.h"
25
26 #include "keccak.h"
27 #include "hfal_keccak.h"
28 #include "shavs.h"
29 #include "nessie_hash_test.h"
30 #include "performance_test.h"
31 #include "hfal-nessie.h"
32 #include "hfal-performance.h"
33 #include "hfal-test.h"
34
35 char *algo_name = "Keccak";
36
37
38 const hfdesc_t *const algolist[] PROGMEM = {
39         (hfdesc_t*)&keccak224_desc,
40         (hfdesc_t*)&keccak256_desc,
41         (hfdesc_t*)&keccak384_desc,
42         (hfdesc_t*)&keccak512_desc,
43         NULL
44 };
45
46 /*****************************************************************************
47  *  additional validation-functions                                                                                      *
48  *****************************************************************************/
49 void test_256(void){
50         uint8_t hash[32];
51         uint8_t null[KECCAK256_BLOCKSIZE_B];
52         memset(null, 0, KECCAK256_BLOCKSIZE_B);
53         keccak_ctx_t ctx;
54         keccak256_init(&ctx);
55         keccak_nextBlock(&ctx, null);
56         keccak_lastBlock(&ctx, null, 29);
57         keccak256_ctx2hash(hash, &ctx);
58         cli_putstr_P(PSTR("\r\n testhash: "));
59         cli_hexdump(hash, 32);
60 }
61
62
63 void performance_keccak(void){
64         hfal_performance_multiple(algolist);
65 }
66
67 void testrun_nessie_keccak(void){
68         hfal_nessie_multiple(algolist);
69 }
70 /*****************************************************************************
71  *  main                                                                                                                                         *
72  *****************************************************************************/
73
74 const char nessie_str[]      PROGMEM = "nessie";
75 const char test256_str[]     PROGMEM = "test256";
76 const char performance_str[] PROGMEM = "performance";
77 const char echo_str[]        PROGMEM = "echo";
78 const char shavs_list_str[]  PROGMEM = "shavs_list";
79 const char shavs_set_str[]   PROGMEM = "shavs_set";
80 const char shavs_test1_str[] PROGMEM = "shavs_test1";
81 const char shavs_test3_str[] PROGMEM = "shavs_test3";
82
83 const cmdlist_entry_t cmdlist[] PROGMEM = {
84         { nessie_str,                NULL, testrun_nessie_keccak     },
85         { performance_str,           NULL, performance_keccak        },
86         { test256_str,               NULL, test_256                  },
87         { shavs_list_str,            NULL, shavs_listalgos           },
88         { shavs_set_str,         (void*)1, (void_fpt)shavs_setalgo   },
89         { shavs_test1_str,           NULL, shavs_test1               },
90         { shavs_test3_str,           NULL, shavs_test3               },
91         { echo_str,              (void*)1, (void_fpt)echo_ctrl       },
92         { NULL,                      NULL, NULL                      }
93 };
94
95 int main(void){
96     main_setup();
97
98     shavs_algolist=(hfdesc_t**)algolist;
99         shavs_algo=(hfdesc_t*)&keccak256_desc;
100         for(;;){
101             welcome_msg(algo_name);
102             cmd_interface(cmdlist);
103         }
104 }