]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-whirlpool-0-test.c
added Whirlpool-0 and Whirlpool-T
[avr-crypto-lib.git] / test_src / main-whirlpool-0-test.c
1 /* main-whirlpool-0-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2011  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  * Whirlpool-0 test-suit
21  *
22 */
23
24 #include "config.h"
25
26 #include "uart_i.h"
27 #include "debug.h"
28
29 #include "whirlpool.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_whirlpool_0.h"
41 #include "dump.h"
42
43 char* algo_name = "Whirlpool-0";
44
45 const hfdesc_t* algolist[] PROGMEM = {
46         (hfdesc_t*)&whirlpool_0_desc,
47         NULL
48 };
49
50 /*****************************************************************************
51  *  additional validation-functions                                                                                      *
52  *****************************************************************************/
53
54 void testrun_nessie_whirlpool(void){
55         hfal_nessie_multiple(algolist);
56 }
57
58 void testrun_whirlpool(void){
59         whirlpool_ctx_t ctx;
60         uint8_t hash[64];
61         uint8_t data[64];
62         memset(data, 0, 64);
63         data[0] = 'a';
64         data[1] = 'b';
65         data[2] = 'c';
66         whirlpool_init(&ctx);
67         whirlpool_lastBlock(&ctx, data, 3*8);
68         whirlpool_ctx2hash(hash, &ctx);
69         cli_putstr_P(PSTR("\r\nEmpty message hash:"));
70         cli_hexdump_block(hash, 64, 4, 16);
71 }
72
73 void testrun_performance_whirlpool(void){
74         hfal_performance_multiple(algolist);
75 }
76
77 void testrun_nessie2(void){
78         uint16_t i;
79         uint8_t j;
80         uint8_t data[128], hash[64];
81         whirlpool_ctx_t ctx;
82         char str[8];
83         memset(data, 0, 128);
84         cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
85         for(i=0; i<1024; ++i){
86                 cli_putstr_P(PSTR("\r\n    L = "));
87                 itoa(i, str, 10);
88                 j=4;
89                 j-= strlen(str);
90                 if(j>3){
91                         j=0;
92                 }
93                 while(j--){
94                         cli_putc(' ');
95                 }
96                 cli_putstr(str);
97                 cli_putstr_P(PSTR(": "));
98                 whirlpool_init(&ctx);
99                 whirlpool_lastBlock(&ctx, data, i);
100                 whirlpool_ctx2hash(hash, &ctx);
101                 cli_hexdump(hash, 64);
102         }
103         cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
104         for(i=0; i<512; ++i){
105                 cli_putstr_P(PSTR("\r\n    S = "));
106                 data[i/8] = 0x80>>(i&7);
107                 cli_hexdump(data, 64);
108                 cli_putstr_P(PSTR(": "));
109                 whirlpool_init(&ctx);
110                 whirlpool_lastBlock(&ctx, data, 512);
111                 whirlpool_ctx2hash(hash, &ctx);
112                 data[i/8] = 0x00;
113                 cli_hexdump(hash, 64);
114         }
115         cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
116         uint32_t c;
117         memset(hash, 0, 64);
118         for(c=0; c<1000000; ++c){
119                 whirlpool_init(&ctx);
120                 whirlpool_lastBlock(&ctx, hash, 512);
121                 whirlpool_ctx2hash(hash, &ctx);
122         }
123         cli_hexdump(hash, 64);
124         cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
125 }
126
127 /*****************************************************************************
128  *  main                                                                                                                                         *
129  *****************************************************************************/
130
131 const char nessie_str[]      PROGMEM = "nessie";
132 const char nessie2_str[]     PROGMEM = "nessie2";
133 const char test_str[]        PROGMEM = "test";
134 const char performance_str[] PROGMEM = "performance";
135 const char echo_str[]        PROGMEM = "echo";
136 const char shavs_list_str[]  PROGMEM = "shavs_list";
137 const char shavs_set_str[]   PROGMEM = "shavs_set";
138 const char shavs_test1_str[] PROGMEM = "shavs_test1";
139 const char shavs_test2_str[] PROGMEM = "shavs_test2";
140 const char shavs_test3_str[] PROGMEM = "shavs_test3";
141 const char dump_str[]        PROGMEM = "dump";
142
143 cmdlist_entry_t cmdlist[] PROGMEM = {
144         { nessie_str,          NULL, testrun_nessie_whirlpool       },
145         { nessie2_str,         NULL, testrun_nessie2                },
146         { test_str,            NULL, testrun_whirlpool              },
147         { performance_str,     NULL, testrun_performance_whirlpool  },
148         { echo_str,        (void*)1, (void_fpt)echo_ctrl            },
149         { shavs_list_str,      NULL, shavs_listalgos                },
150         { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo        },
151         { shavs_test1_str,     NULL, shavs_test1                    },
152         { shavs_test2_str,     NULL, shavs_test2                    },
153         { shavs_test3_str,     NULL, shavs_test3                    },
154         { dump_str,        (void*)1, (void_fpt)dump                 },
155         { NULL,                NULL, NULL                           }
156 };
157
158 int main (void){
159         DEBUG_INIT();
160
161         cli_rx = (cli_rx_fpt)uart0_getc;
162         cli_tx = (cli_tx_fpt)uart0_putc;
163         shavs_algolist=(hfdesc_t**)algolist;
164         shavs_algo=(hfdesc_t*)&whirlpool_0_desc;
165         for(;;){
166                 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
167                 cli_putstr(algo_name);
168                 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
169                 cmd_interface(cmdlist);
170         }
171 }