Home | History | Annotate | Download | only in tests
      1 /*
      2  * Test program for MD4 (test vectors from RFC 1320)
      3  * Copyright (c) 2006, Jouni Malinen <j (at) w1.fi>
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License version 2 as
      7  * published by the Free Software Foundation.
      8  *
      9  * Alternatively, this software may be distributed under the terms of BSD
     10  * license.
     11  *
     12  * See README and COPYING for more details.
     13  */
     14 
     15 #include "includes.h"
     16 
     17 #include "common.h"
     18 #include "crypto.h"
     19 
     20 int main(int argc, char *argv[])
     21 {
     22 	struct {
     23 		char *data;
     24 		u8 *hash;
     25 	} tests[] = {
     26 		{
     27 			"",
     28 			"\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
     29 			"\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"
     30 		},
     31 		{
     32 			"a",
     33 			"\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46"
     34 			"\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"
     35 		},
     36 		{
     37 			"abc",
     38 			"\xa4\x48\x01\x7a\xaf\x21\xd8\x52"
     39 			"\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"
     40 		},
     41 		{
     42 			"message digest",
     43 			"\xd9\x13\x0a\x81\x64\x54\x9f\xe8"
     44 			"\x18\x87\x48\x06\xe1\xc7\x01\x4b"
     45 		},
     46 		{
     47 			"abcdefghijklmnopqrstuvwxyz",
     48 			"\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd"
     49 			"\xee\xa8\xed\x63\xdf\x41\x2d\xa9"
     50 		},
     51 		{
     52 			"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
     53 			"0123456789",
     54 			"\x04\x3f\x85\x82\xf2\x41\xdb\x35"
     55 			"\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"
     56 		},
     57 		{
     58 			"12345678901234567890123456789012345678901234567890"
     59 			"123456789012345678901234567890",
     60 			"\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19"
     61 			"\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"
     62 		}
     63 	};
     64 	unsigned int i;
     65 	u8 hash[16];
     66 	const u8 *addr[2];
     67 	size_t len[2];
     68 	int errors = 0;
     69 
     70 	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
     71 		printf("MD4 test case %d:", i);
     72 
     73 		addr[0] = tests[i].data;
     74 		len[0] = strlen(tests[i].data);
     75 		md4_vector(1, addr, len, hash);
     76 		if (memcmp(hash, tests[i].hash, 16) != 0) {
     77 			printf(" FAIL");
     78 			errors++;
     79 		} else
     80 			printf(" OK");
     81 
     82 		if (len[0]) {
     83 			addr[0] = tests[i].data;
     84 			len[0] = strlen(tests[i].data);
     85 			addr[1] = tests[i].data + 1;
     86 			len[1] = strlen(tests[i].data) - 1;
     87 			md4_vector(1, addr, len, hash);
     88 			if (memcmp(hash, tests[i].hash, 16) != 0) {
     89 				printf(" FAIL");
     90 				errors++;
     91 			} else
     92 				printf(" OK");
     93 		}
     94 
     95 		printf("\n");
     96 	}
     97 
     98 	return errors;
     99 }
    100