]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-md5-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-md5-test.c
1 /* main-md5-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  * md5 test suit
21  * 
22 */
23
24 #include "main-test-common.h"
25
26 #include "md5.h"
27 #include "nessie_hash_test.h"
28 #include "performance_test.h"
29 #include "hfal_md5.h"
30 #include "hfal-performance.h"
31
32 char *algo_name = "MD5";
33
34 const hfdesc_t *const algolist[] PROGMEM = {
35         (hfdesc_t*)&md5_desc,
36         NULL
37 };
38
39 /*****************************************************************************
40  *  additional validation-functions                                                                                      *
41  *****************************************************************************/
42
43 void md5_ctx2hash_dummy(void *buffer, void *ctx){
44         memcpy(buffer, ctx, 16);
45 }
46
47
48 void testrun_nessie_md5(void){
49         nessie_hash_ctx.hashsize_b  = 128;
50         nessie_hash_ctx.blocksize_B = 512/8;
51         nessie_hash_ctx.ctx_size_B  = sizeof(md5_ctx_t);
52         nessie_hash_ctx.name = algo_name;
53         nessie_hash_ctx.hash_init = (nessie_hash_init_fpt)md5_init;
54         nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)md5_nextBlock;
55         nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)md5_lastBlock;
56         nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)md5_ctx2hash_dummy;
57         
58         nessie_hash_run();
59 }
60
61 /*****************************************************************************
62  *  self tests                                                                                                                           *
63  *****************************************************************************/
64
65 /*
66  * MD5 test suite:
67  * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
68  * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
69  * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
70  * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
71  * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
72  * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
73  * d174ab98d277d9f5a5611c2c9f419d9f
74  * MD5 ("123456789012345678901234567890123456789012345678901234567890123456
75  * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
76  */
77
78 void testrun_md5(void){
79         md5_hash_t hash;
80         char *testv[]={
81                 "", 
82                 "a", 
83                 "abc", 
84                 "message digest", 
85                 "abcdefghijklmnopqrstuvwxyz", 
86                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
87                 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
88         uint16_t i;
89         
90         cli_putstr("\r\n=== MD5 test suit ===");
91         for(i=0; i<7; ++i){
92                 cli_putstr("\r\n MD5 (\"");
93                 cli_putstr(testv[i]);
94                 cli_putstr("\") = \r\n\t");
95                 md5(&hash, testv[i], strlen(testv[i])*8);
96                 cli_hexdump(hash, 16);
97         }
98         uint8_t buffer[512/8];
99         char str[5];
100         for(i=505; i<512; ++i){
101                 memset(buffer, 0, 512/8);
102                 cli_putstr_P(PSTR("\r\nMD5("));
103                 utoa(i, str, 10);
104                 cli_putstr(str);
105                 cli_putstr_P(PSTR(" zero bits) = "));
106                 md5(&hash, buffer, i);
107                 cli_hexdump(hash, 16);
108         }
109 }
110
111
112 void testrun_performance_md5(void){
113         hfal_performance_multiple(algolist);
114 }
115
116
117 /*****************************************************************************
118  * main                                                                                                                                  *
119  *****************************************************************************/
120
121 const char nessie_str[]      PROGMEM = "nessie";
122 const char test_str[]        PROGMEM = "test";
123 const char performance_str[] PROGMEM = "performance";
124 const char echo_str[]        PROGMEM = "echo";
125
126 const cmdlist_entry_t cmdlist[] PROGMEM = {
127         { nessie_str,      NULL, testrun_nessie_md5},
128         { test_str,        NULL, testrun_md5},
129         { performance_str, NULL, testrun_performance_md5},
130         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
131         { NULL,            NULL, NULL}
132 };
133
134 int main (void){
135     main_setup();
136
137     for(;;){
138         welcome_msg(algo_name);
139         cmd_interface(cmdlist);
140         }
141 }