]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-md5-test.c
insereated GPLv3 stub
[avr-crypto-lib.git] / main-md5-test.c
1 /* main-md5-test.c */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-lib.
4     Copyright (C) 2008  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  * md5 test suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "md5.h"
30
31 #include <stdint.h>
32 #include <string.h>
33
34
35 /*****************************************************************************
36  *  additional validation-functions                                                                                      *
37  *****************************************************************************/
38
39 /*****************************************************************************
40  *  self tests                                                                                                                           *
41  *****************************************************************************/
42
43 /*
44  * MD5 test suite:
45  * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
46  * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
47  * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
48  * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
49  * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
50  * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
51  * d174ab98d277d9f5a5611c2c9f419d9f
52  * MD5 ("123456789012345678901234567890123456789012345678901234567890123456
53  * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
54  */
55
56 void testrun_md5(void){
57         md5_ctx_t s;
58         char* testv[]={"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", 
59                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
60                 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
61         uint8_t i;
62         
63         uart_putstr("\r\n=== MD5 test suit ===");
64         for(i=0; i<7; ++i){
65                 uart_putstr("\r\n MD5 (\"");
66                 uart_putstr(testv[i]);
67                 uart_putstr("\") = \r\n");
68                 md5_init(&s);
69                 md5_lastBlock(&s, testv[i], strlen(testv[i])*8);
70                 uart_hexdump(&s.a[0], 16);
71         }
72 }
73
74
75
76 /*****************************************************************************
77  *  main                                                                                                                                         *
78  *****************************************************************************/
79
80 int main (void){
81         char str[20];
82
83         
84         DEBUG_INIT();
85         uart_putstr("\r\n");
86
87         uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
88 restart:
89         while(1){ 
90                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
91                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
92                         testrun_md5();
93                 goto restart;           
94                 continue;
95         error:
96                 uart_putstr("ERROR\r\n");
97         } /* while (1) */
98 }
99