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