]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-sha256-test.c
b1ea95d043a998f46ee7552d888f75838cb2c5af
[avr-crypto-lib.git] / main-sha256-test.c
1 /*
2  * SHA-256 test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "sha256.h"
12 #include "nessie_hash_test.h"
13
14 #include <stdint.h>
15 #include <string.h>
16
17 char* algo_name = "SHA-256";
18
19 /*****************************************************************************
20  *  additional validation-functions                                                                                      *
21  *****************************************************************************/
22 void sha256_next_dummy(void* buffer, void* ctx){
23         sha256_nextBlock(ctx, buffer);
24 }
25
26 void sha256_last_dummy(void* buffer, uint16_t size_b, void* ctx){
27         sha256_lastBlock(ctx, buffer, size_b);
28 }
29
30 void testrun_nessie_sha256(void){
31         nessie_hash_ctx.hashsize_b  = 256;
32         nessie_hash_ctx.blocksize_B = 512/8;
33         nessie_hash_ctx.ctx_size_B  = sizeof(sha256_ctx_t);
34         nessie_hash_ctx.name = algo_name;
35         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)sha256_init;
36         nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha256_next_dummy;
37         nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha256_last_dummy;
38         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha256_ctx2hash;
39         
40         nessie_hash_run();
41 }
42
43
44
45 /*****************************************************************************
46  *  main                                                                                                                                         *
47  *****************************************************************************/
48
49 int main (void){
50         char  str[20];
51         DEBUG_INIT();
52         uart_putstr("\r\n");
53
54         uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
55         uart_putstr(algo_name);
56         uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
57
58 restart:
59         while(1){ 
60                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
61                 if (strcmp(str, "nessie")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
62                         testrun_nessie_sha256();
63                 goto restart;           
64                 continue;
65         error:
66                 uart_putstr("ERROR\r\n");
67         }
68         
69 }
70