]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-keccak-test.c
optimized rotates for keccak
[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) 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  * Keccak test-suit
21  *
22 */
23
24 #include "config.h"
25 #include "uart_i.h"
26 #include "debug.h"
27
28 #include "keccak.h"
29 #include "cli.h"
30 #include "hfal_keccak.h"
31 #include "shavs.h"
32 #include "nessie_hash_test.h"
33 #include "performance_test.h"
34 #include "hfal-nessie.h"
35 #include "hfal-performance.h"
36 #include "hfal-test.h"
37
38 #include <stdint.h>
39 #include <string.h>
40 #include <stdlib.h>
41
42 char* algo_name = "Keccak";
43
44
45 const hfdesc_t* algolist[] PROGMEM = {
46         (hfdesc_t*)&keccak224_desc,
47         (hfdesc_t*)&keccak256_desc,
48         (hfdesc_t*)&keccak384_desc,
49         (hfdesc_t*)&keccak512_desc,
50         NULL
51 };
52
53 /*****************************************************************************
54  *  additional validation-functions                                                                                      *
55  *****************************************************************************/
56 void test_256(void){
57         uint8_t data[] = {0x53, 0x58, 0x7B,  0xC8 };
58         uint8_t hash[32];
59         uint8_t null[KECCAK256_BLOCKSIZE_B];
60         memset(null, 0, KECCAK256_BLOCKSIZE_B);
61         keccak_ctx_t ctx;
62         keccak256_init(&ctx);
63         keccak_nextBlock(&ctx, null);
64         //      keccak_lastBlock(&ctx, data, 29);
65         keccak256_ctx2hash(hash, &ctx);
66         cli_putstr_P(PSTR("\r\n testhash: "));
67         cli_hexdump(hash, 32);
68 }
69
70
71 void performance_keccak(void){
72         hfal_performance_multiple(algolist);
73 }
74
75 void testrun_nessie_keccak(void){
76         hfal_nessie_multiple(algolist);
77 }
78 /*****************************************************************************
79  *  main                                                                                                                                         *
80  *****************************************************************************/
81
82 const char nessie_str[]      PROGMEM = "nessie";
83 const char test256_str[]     PROGMEM = "test256";
84 const char performance_str[] PROGMEM = "performance";
85 const char echo_str[]        PROGMEM = "echo";
86 const char shavs_list_str[]  PROGMEM = "shavs_list";
87 const char shavs_set_str[]   PROGMEM = "shavs_set";
88 const char shavs_test1_str[] PROGMEM = "shavs_test1";
89 const char shavs_test3_str[] PROGMEM = "shavs_test3";
90
91 cmdlist_entry_t cmdlist[] PROGMEM = {
92         { nessie_str,                NULL, testrun_nessie_keccak     },
93         { performance_str,           NULL, performance_keccak        },
94         { test256_str,               NULL, test_256                  },
95         { shavs_list_str,            NULL, shavs_listalgos           },
96         { shavs_set_str,         (void*)1, (void_fpt)shavs_setalgo   },
97         { shavs_test1_str,           NULL, shavs_test1               },
98         { shavs_test3_str,           NULL, shavs_test3               },
99         { echo_str,              (void*)1, (void_fpt)echo_ctrl       },
100         { NULL,                      NULL, NULL                      }
101 };
102
103 int main (void){
104         DEBUG_INIT();
105
106         cli_rx = (cli_rx_fpt)uart0_getc;
107         cli_tx = (cli_tx_fpt)uart0_putc;
108         shavs_algolist=(hfdesc_t**)algolist;
109         shavs_algo=(hfdesc_t*)&keccak256_desc;
110         for(;;){
111                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
112                 cli_putstr(algo_name);
113                 cli_putstr_P(PSTR("; "));
114                 cli_putstr(__DATE__);
115                 cli_putstr_P(PSTR(" "));
116                 cli_putstr(__TIME__);
117                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
118
119                 cmd_interface(cmdlist);
120         }
121 }