]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-sha256-test.c
bigint looks good but needs more testing
[arm-crypto-lib.git] / test_src / main-sha256-test.c
1 /* main-sha256-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  * SHA-256 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 "sha256.h"
42 #include "hfal_sha256.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 = "SHA-256";
53
54 const hfdesc_t* algolist[] = {
55         (hfdesc_t*)&sha256_desc,
56         NULL
57 };
58
59 /*****************************************************************************
60  *  additional validation-functions                                                                                      *
61  *****************************************************************************/
62
63 void testrun_nessie_sha256(void){
64         hfal_nessie_multiple(algolist);
65 }
66
67 void testrun_performance_sha256(void){
68         hfal_performance_multiple(algolist);
69 }
70
71 void test_monte(void){
72         uint8_t data1[] = {
73      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
74      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
75          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
76          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
77      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
78      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
79          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
80          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
81      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
82      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
83          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
84          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7 };
85
86    uint8_t data2[] = {
87      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
88      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
89          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
90          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
91      0xF4, 0x1E, 0xCE, 0x26, 0x13, 0xE4, 0x57, 0x39,
92      0x15, 0x69, 0x6B, 0x5A, 0xDC, 0xD5, 0x1C, 0xA3,
93          0x28, 0xBE, 0x3B, 0xF5, 0x66, 0xA9, 0xCA, 0x99,
94          0xC9, 0xCE, 0xB0, 0x27, 0x9C, 0x1C, 0xB0, 0xA7,
95      0xFD, 0xDF, 0x1B, 0x37, 0xDD, 0x34, 0xB3, 0xB2,
96      0x01, 0xD4, 0x3C, 0x57, 0xBC, 0xDE, 0x11, 0x58,
97      0x38, 0xF0, 0xDF, 0x70, 0x1D, 0xA9, 0x3C, 0x3B,
98      0xF2, 0xC9, 0xC8, 0x68, 0x96, 0xE7, 0xE6, 0xC7 };
99    uint8_t hash[SHA256_HASH_BYTES];
100    sha256((sha256_hash_t*)hash, data1, 3*32*8);
101    cli_putstr("\r\n hash(data1) = ");
102    cli_hexdump(hash, 32);
103    sha256((sha256_hash_t*)hash, data2, 3*32*8);
104    cli_putstr("\r\n hash(data2) = ");
105    cli_hexdump(hash, 32);
106 }
107
108 void test_monte2(void){
109         uint8_t data[] = {
110         0x6c, 0xd4, 0xc0, 0xc5, 0xcb, 0x2c, 0xa2, 0xa0,
111         0xf1, 0xd1, 0xae, 0xce, 0xba, 0xc0, 0x3b, 0x52,
112         0xe6, 0x4e, 0xa0, 0x3d, 0x1a, 0x16, 0x54, 0x37,
113         0x29, 0x36, 0x54, 0x5b, 0x92, 0xbb, 0xc5, 0x48,
114         0x4a, 0x59, 0xdb, 0x74, 0xbb, 0x60, 0xf9, 0xc4,
115         0x0c, 0xeb, 0x1a, 0x5a, 0xa3, 0x5a, 0x6f, 0xaf,
116         0xe8, 0x03, 0x49, 0xe1, 0x4c, 0x25, 0x3a, 0x4e,
117         0x8b, 0x1d, 0x77, 0x61, 0x2d, 0xdd, 0x81, 0xac,
118         0xe9, 0x26, 0xae, 0x8b, 0x0a, 0xf6, 0xe5, 0x31,
119         0x76, 0xdb, 0xff, 0xcc, 0x2a, 0x6b, 0x88, 0xc6,
120         0xbd, 0x76, 0x5f, 0x93, 0x9d, 0x3d, 0x17, 0x8a,
121         0x9b, 0xde, 0x9e, 0xf3, 0xaa, 0x13, 0x1c, 0x61,
122         0xe3, 0x1c, 0x1e, 0x42, 0xcd, 0xfa, 0xf4, 0xb4,
123         0xdc, 0xde, 0x57, 0x9a, 0x37, 0xe1, 0x50, 0xef,
124         0xbe, 0xf5, 0x55, 0x5b, 0x4c, 0x1c, 0xb4, 0x04,
125         0x39, 0xd8, 0x35, 0xa7, 0x24, 0xe2, 0xfa, 0xe7 };
126
127    uint8_t hash[SHA256_HASH_BYTES];
128    sha256((sha256_hash_t*)hash, data, 1024);
129    cli_putstr("\r\n hash(data) = ");
130    cli_hexdump(hash, 32);
131 }
132
133 /*****************************************************************************
134  *  main                                                                                                                                         *
135  *****************************************************************************/
136
137 const char nessie_str[]       = "nessie";
138 const char test_str[]         = "test";
139 const char monte_str[]        = "monte";
140 const char monte2_str[]       = "monte2";
141 const char performance_str[]  = "performance";
142 const char echo_str[]         = "echo";
143 const char shavs_list_str[]   = "shavs_list";
144 const char shavs_set_str[]    = "shavs_set";
145 const char shavs_test1_str[]  = "shavs_test1";
146 const char shavs_test2_str[]  = "shavs_test2";
147 const char shavs_test3_str[]  = "shavs_test3";
148 const char dump_str[]         = "dump";
149
150 const cmdlist_entry_t cmdlist[]  = {
151         { nessie_str,          NULL, testrun_nessie_sha256          },
152         { test_str,            NULL, testrun_nessie_sha256          },
153         { monte_str,           NULL, test_monte                     },
154         { monte2_str,          NULL, test_monte2                    },
155         { performance_str,     NULL, testrun_performance_sha256     },
156         { echo_str,        (void*)1, (void_fpt)echo_ctrl            },
157         { shavs_list_str,      NULL, shavs_listalgos                },
158         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo        },
159         { shavs_test1_str,     NULL, shavs_test1                    },
160         { shavs_test2_str,     NULL, shavs_test2                    },
161         { shavs_test3_str,     NULL, shavs_test3                    },
162         { dump_str,        (void*)1, (void_fpt)dump                 },
163         { NULL,                NULL, NULL                           }
164 };
165
166 int main(void) {
167         sysclk_set_freq(SYS_FREQ);
168         sysclk_mosc_verify_enable();
169     uart_init(UART_0, 115200, 8, UART_PARATY_NONE, UART_STOPBITS_ONE);
170     gptm_set_timer_32periodic(TIMER0);
171
172         cli_rx = uart0_getc;
173     cli_tx = uart0_putc;
174
175         shavs_algolist=(hfdesc_t**)algolist;
176         shavs_algo=(hfdesc_t*)&sha256_desc;
177
178         for(;;){
179                 cli_putstr("\r\n\r\nARM-Crypto-Lib VS (");
180                 cli_putstr(algo_name);
181                 cli_putstr("; ");
182                 cli_putstr(__DATE__);
183                 cli_putc(' ');
184                 cli_putstr(__TIME__);
185                 cli_putstr(")\r\nloaded and running\r\n");
186         cmd_interface(cmdlist);
187     }
188
189 }