]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-md5-test.c
+RC5 +size-statistics tool +small modification to nessie_bc_test (optional free(...
[avr-crypto-lib.git] / main-md5-test.c
1 /*
2  * md5 test suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "md5.h"
12
13 #include <stdint.h>
14 #include <string.h>
15
16
17 /*****************************************************************************
18  *  additional validation-functions                                                                                      *
19  *****************************************************************************/
20
21 /*****************************************************************************
22  *  self tests                                                                                                                           *
23  *****************************************************************************/
24
25 /*
26  * MD5 test suite:
27  * MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
28  * MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
29  * MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
30  * MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
31  * MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
32  * MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
33  * d174ab98d277d9f5a5611c2c9f419d9f
34  * MD5 ("123456789012345678901234567890123456789012345678901234567890123456
35  * 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
36  */
37
38 void testrun_md5(void){
39         md5_ctx_t s;
40         char* testv[]={"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", 
41                 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
42                 "12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
43         uint8_t i;
44         
45         uart_putstr("\r\n=== MD5 test suit ===");
46         for(i=0; i<7; ++i){
47                 uart_putstr("\r\n MD5 (\"");
48                 uart_putstr(testv[i]);
49                 uart_putstr("\") = \r\n");
50                 md5_init(&s);
51                 md5_lastBlock(&s, testv[i], strlen(testv[i])*8);
52                 uart_hexdump(&s.a[0], 16);
53         }
54 }
55
56
57
58 /*****************************************************************************
59  *  main                                                                                                                                         *
60  *****************************************************************************/
61
62 int main (void){
63         char str[20];
64
65         
66         DEBUG_INIT();
67         uart_putstr("\r\n");
68
69         uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
70 restart:
71         while(1){ 
72                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
73                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
74                         testrun_md5();
75                 goto restart;           
76                 continue;
77         error:
78                 uart_putstr("ERROR\r\n");
79         } /* while (1) */
80 }
81