1 /*********************************************************************
3 * Author: Brad Conte (brad AT bradconte.com)
5 * Disclaimer: This code is presented "as is" without any guarantees.
6 * Details: Performs known-answer tests on the corresponding MD2
7 implementation. These tests do not encompass the full
8 range of available test vectors, however, if the tests
9 pass it is very, very likely that the code is correct
10 and was compiled properly. This code also serves as
11 example usage of the functions.
12 *********************************************************************/
14 /*************************** HEADER FILES ***************************/
20 /*********************** FUNCTION DEFINITIONS ***********************/
23 BYTE text1[] = {"abc"};
24 BYTE text2[] = {"abcdefghijklmnopqrstuvwxyz"};
25 BYTE text3_1[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"};
26 BYTE text3_2[] = {"fghijklmnopqrstuvwxyz0123456789"};
27 BYTE hash1[MD2_BLOCK_SIZE] = {0xda,0x85,0x3b,0x0d,0x3f,0x88,0xd9,0x9b,0x30,0x28,0x3a,0x69,0xe6,0xde,0xd6,0xbb};
28 BYTE hash2[MD2_BLOCK_SIZE] = {0x4e,0x8d,0xdf,0xf3,0x65,0x02,0x92,0xab,0x5a,0x41,0x08,0xc3,0xaa,0x47,0x94,0x0b};
29 BYTE hash3[MD2_BLOCK_SIZE] = {0xda,0x33,0xde,0xf2,0xa4,0x2d,0xf1,0x39,0x75,0x35,0x28,0x46,0xc3,0x03,0x38,0xcd};
35 md2_update(&ctx, text1, strlen(text1));
37 pass = pass && !memcmp(hash1, buf, MD2_BLOCK_SIZE);
39 // Note that the MD2 object can be re-used.
41 md2_update(&ctx, text2, strlen(text2));
43 pass = pass && !memcmp(hash2, buf, MD2_BLOCK_SIZE);
45 // Note that the data is added in two chunks.
47 md2_update(&ctx, text3_1, strlen(text3_1));
48 md2_update(&ctx, text3_2, strlen(text3_2));
50 pass = pass && !memcmp(hash3, buf, MD2_BLOCK_SIZE);
57 printf("MD2 tests: %s\n", md2_test() ? "SUCCEEDED" : "FAILED");