]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-sha256-test.c
important fix for SHA1 (Asm) & SHA256 (Asm) and new MonteCarlo tests for hashes
[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
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "sha256.h"
30 #include "nessie_hash_test.h"
31 #include "performance_test.h"
32 #include "hfal-performance.h"
33 #include "hfal-nessie.h"
34
35 #include <stdint.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include "cli.h"
39 #include "shavs.h"
40 #include "hfal_sha256.h"
41 #include "dump.h"
42
43 char* algo_name = "SHA-256";
44
45 const hfdesc_t* algolist[] PROGMEM = {
46         (hfdesc_t*)&sha256_desc,
47         NULL
48 };
49
50 /*****************************************************************************
51  *  additional validation-functions                                                                                      *
52  *****************************************************************************/
53
54 void testrun_nessie_sha256(void){
55         hfal_nessie_multiple(algolist);
56 }
57
58 void testrun_performance_sha256(void){
59         hfal_performance_multiple(algolist);
60 }
61
62 void test_monte(void){
63         uint8_t data1[] = {
64      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
65      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
66          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
67          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
68      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
69      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
70          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
71          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
72      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
73      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
74          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
75          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7 };
76
77    uint8_t data2[] = {
78      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
79      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
80          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
81          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
82      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
83      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
84          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
85          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
86      0xFD, 0xDF, 0x1B, 0x37, 0xDD, 0x34, 0xB3, 0xB2,
87      0x01, 0xD4, 0x3C, 0x57, 0xBC, 0xDE, 0x11, 0x58,
88      0x38, 0xF0, 0xDF, 0x70, 0x1D, 0xA9, 0x3C, 0x3B,
89      0xF2, 0xC9, 0xC8, 0x68, 0x96, 0xE7, 0xE6, 0xC7 };
90    uint8_t hash[SHA256_HASH_BYTES];
91    sha256(hash, data1, 3*32*8);
92    cli_putstr_P(PSTR("\r\n hash(data1) = "));
93    cli_hexdump(hash, 32);
94    sha256(hash, data2, 3*32*8);
95    cli_putstr_P(PSTR("\r\n hash(data2) = "));
96    cli_hexdump(hash, 32);
97 }
98
99 /*****************************************************************************
100  *  main                                                                                                                                         *
101  *****************************************************************************/
102
103 const char nessie_str[]      PROGMEM = "nessie";
104 const char test_str[]        PROGMEM = "test";
105 const char monte_str[]       PROGMEM = "monte";
106 const char performance_str[] PROGMEM = "performance";
107 const char echo_str[]        PROGMEM = "echo";
108 const char shavs_list_str[]  PROGMEM = "shavs_list";
109 const char shavs_set_str[]   PROGMEM = "shavs_set";
110 const char shavs_test1_str[] PROGMEM = "shavs_test1";
111 const char shavs_test2_str[] PROGMEM = "shavs_test2";
112 const char dump_str[]        PROGMEM = "dump";
113
114 cmdlist_entry_t cmdlist[] PROGMEM = {
115         { nessie_str,          NULL, testrun_nessie_sha256},
116         { test_str,            NULL, testrun_nessie_sha256},
117         { monte_str,           NULL, test_monte},
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         { shavs_test2_str,     NULL, shavs_test2},
124         { dump_str,        (void*)1, (void_fpt)dump},
125         { NULL,                NULL, NULL}
126 };
127
128 int main (void){
129         DEBUG_INIT();
130
131         cli_rx = (cli_rx_fpt)uart0_getc;
132         cli_tx = (cli_tx_fpt)uart0_putc;
133         shavs_algolist=(hfdesc_t**)algolist;
134         shavs_algo=(hfdesc_t*)&sha256_desc;
135         for(;;){
136                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
137                 cli_putstr(algo_name);
138                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
139                 cmd_interface(cmdlist);
140         }
141 }