]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-sha256-test.c
+Shabal
[avr-crypto-lib.git] / test_src / main-sha256-test.c
1 /* main-sha256-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  * SHA-256 test-suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "sha256.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
32
33 #include <stdint.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include "cli.h"
37 #include "shavs.h"
38 #include "hfal_sha256.h"
39 #include "dump.h"
40
41 char* algo_name = "SHA-256";
42
43 /*****************************************************************************
44  *  additional validation-functions                                                                                      *
45  *****************************************************************************/
46
47 void testrun_nessie_sha256(void){
48         nessie_hash_ctx.hashsize_b  = 256;
49         nessie_hash_ctx.blocksize_B = 512/8;
50         nessie_hash_ctx.ctx_size_B  = sizeof(sha256_ctx_t);
51         nessie_hash_ctx.name = algo_name;
52         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha256_init;
53         nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha256_nextBlock;
54         nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha256_lastBlock;
55         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha256_ctx2hash;
56         
57         nessie_hash_run();
58 }
59
60 void testrun_performance_sha256(void){
61         uint64_t t;
62         char str[16];
63         uint8_t data[32];
64         sha256_ctx_t ctx;
65         
66         calibrateTimer();
67         print_overhead();
68         
69         memset(data, 0, 32);
70         
71         startTimer(1);
72         sha256_init(&ctx);
73         t = stopTimer();
74         cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
75         ultoa((unsigned long)t, str, 10);
76         cli_putstr(str);
77         
78         
79         startTimer(1);
80         sha256_nextBlock(&ctx, data);
81         t = stopTimer();
82         cli_putstr_P(PSTR("\r\n\tone-block time: "));
83         ultoa((unsigned long)t, str, 10);
84         cli_putstr(str);
85         
86         
87         startTimer(1);
88         sha256_lastBlock(&ctx, data, 0);
89         t = stopTimer();
90         cli_putstr_P(PSTR("\r\n\tlast block time: "));
91         ultoa((unsigned long)t, str, 10);
92         cli_putstr(str);
93         
94         cli_putstr_P(PSTR("\r\n"));
95 }
96
97 /*****************************************************************************
98  *  main                                                                                                                                         *
99  *****************************************************************************/
100
101 const char nessie_str[]      PROGMEM = "nessie";
102 const char test_str[]        PROGMEM = "test";
103 const char performance_str[] PROGMEM = "performance";
104 const char echo_str[]        PROGMEM = "echo";
105 const char shavs_list_str[]  PROGMEM = "shavs_list";
106 const char shavs_set_str[]   PROGMEM = "shavs_set";
107 const char shavs_test1_str[] PROGMEM = "shavs_test1";
108 const char dump_str[]        PROGMEM = "dump";
109
110 const hfdesc_t* algolist[] PROGMEM = {
111         (hfdesc_t*)&sha256_desc,
112         NULL
113 };
114
115 cmdlist_entry_t cmdlist[] PROGMEM = {
116         { nessie_str,          NULL, testrun_nessie_sha256},
117         { test_str,            NULL, testrun_nessie_sha256},
118         { performance_str,     NULL, testrun_performance_sha256},
119         { echo_str,        (void*)1, (void_fpt)echo_ctrl},
120         { shavs_list_str,      NULL, shavs_listalgos},
121         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
122         { shavs_test1_str,     NULL, shavs_test1},
123         { dump_str,        (void*)1, (void_fpt)dump},
124         { NULL,                NULL, NULL}
125 };
126
127 int main (void){
128         DEBUG_INIT();
129         
130         cli_rx = uart_getc;
131         cli_tx = uart_putc;             
132         shavs_algolist=(hfdesc_t**)algolist;
133         shavs_algo=(hfdesc_t*)&sha256_desc;
134         for(;;){
135                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
136                 cli_putstr(algo_name);
137                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
138                 cmd_interface(cmdlist);
139         }
140 }