]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-keccak-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-keccak-test.c
1 /* main-keccak-test.c */
2 /*
3     This file is part of the ARM-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  * Keccak test-suit
21  *
22 */
23
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "config.h"
28 #include "cli.h"
29 #include "dump.h"
30 #include "uart_lowlevel.h"
31 #include "sysclock.h"
32 #include "hw_gptm.h"
33
34 #include "shavs.h"
35 #include "nessie_hash_test.h"
36 #include "performance_test.h"
37 #include "hfal-nessie.h"
38 #include "hfal-performance.h"
39 #include "hfal-test.h"
40
41 #include "keccak.h"
42 #include "hfal_keccak.h"
43
44 void uart0_putc(char byte){
45         uart_putc(UART_0, byte);
46 }
47
48 char uart0_getc(void){
49         return uart_getc(UART_0);
50 }
51
52 const char* algo_name = "Keccak";
53
54
55 const hfdesc_t* algolist[] = {
56         (hfdesc_t*)&keccak224_desc,
57         (hfdesc_t*)&keccak256_desc,
58         (hfdesc_t*)&keccak384_desc,
59         (hfdesc_t*)&keccak512_desc,
60         NULL
61 };
62
63 /*****************************************************************************
64  *  additional validation-functions                                                                                      *
65  *****************************************************************************/
66 void test_256(void){
67         uint8_t data[] = {0x53, 0x58, 0x7B,  0xC8 };
68         uint8_t hash[32];
69         uint8_t null[KECCAK256_BLOCKSIZE_B];
70         memset(null, 0, KECCAK256_BLOCKSIZE_B);
71         keccak_ctx_t ctx;
72         keccak256_init(&ctx);
73         keccak_lastBlock(&ctx, data, 29);
74         keccak256_ctx2hash(hash, &ctx);
75         cli_putstr("\r\n testhash: ");
76         cli_hexdump(hash, 32);
77 }
78
79
80 void performance_keccak(void){
81         hfal_performance_multiple(algolist);
82 }
83
84 void testrun_nessie_keccak(void){
85         hfal_nessie_multiple(algolist);
86 }
87 /*****************************************************************************
88  *  main                                                                                                                                         *
89  *****************************************************************************/
90
91 const char nessie_str[]       = "nessie";
92 const char test256_str[]      = "test256";
93 const char performance_str[]  = "performance";
94 const char echo_str[]         = "echo";
95 const char shavs_list_str[]   = "shavs_list";
96 const char shavs_set_str[]    = "shavs_set";
97 const char shavs_test1_str[]  = "shavs_test1";
98 const char shavs_test3_str[]  = "shavs_test3";
99
100 cmdlist_entry_t cmdlist[]  = {
101         { nessie_str,                NULL, testrun_nessie_keccak     },
102         { performance_str,           NULL, performance_keccak        },
103         { test256_str,               NULL, test_256                  },
104         { shavs_list_str,            NULL, shavs_listalgos           },
105         { shavs_set_str,         (void*)1, (void_fpt)shavs_setalgo   },
106         { shavs_test1_str,           NULL, shavs_test1               },
107         { shavs_test3_str,           NULL, shavs_test3               },
108         { echo_str,              (void*)1, (void_fpt)echo_ctrl       },
109         { NULL,                      NULL, NULL                      }
110 };
111
112 int main(void) {
113         sysclk_set_freq(SYS_FREQ);
114         sysclk_mosc_verify_enable();
115     uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
116     gptm_set_timer_32periodic(TIMER0);
117
118         cli_rx = uart0_getc;
119     cli_tx = uart0_putc;
120
121         shavs_algolist=(hfdesc_t**)algolist;
122         shavs_algo=(hfdesc_t*)&keccak256_desc;
123
124         for(;;){
125                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
126                 cli_putstr(algo_name);
127                 cli_putstr("; ");
128                 cli_putstr(__DATE__);
129                 cli_putc(' ');
130                 cli_putstr(__TIME__);
131                 cli_putstr(")\r\nloaded and running\r\n");
132         cmd_interface(cmdlist);
133     }
134
135 }