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