Browse Source

tests: Move MD5 test cases into hwsim framework

Signed-off-by: Jouni Malinen <j@w1.fi>
Jouni Malinen 10 years ago
parent
commit
896e1b836f
3 changed files with 86 additions and 98 deletions
  1. 85 0
      src/crypto/crypto_module_tests.c
  2. 1 5
      tests/Makefile
  3. 0 93
      tests/test-md5.c

+ 85 - 0
src/crypto/crypto_module_tests.c

@@ -13,6 +13,7 @@
 #include "crypto/aes_wrap.h"
 #include "crypto/aes_wrap.h"
 #include "crypto/aes.h"
 #include "crypto/aes.h"
 #include "crypto/ms_funcs.h"
 #include "crypto/ms_funcs.h"
+#include "crypto/crypto.h"
 
 
 
 
 static int test_siv(void)
 static int test_siv(void)
@@ -727,6 +728,89 @@ static int test_key_wrap(void)
 }
 }
 
 
 
 
+static int test_md5(void)
+{
+	struct {
+		char *data;
+		char *hash;
+	} tests[] = {
+		{
+			"",
+			"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
+			"\xe9\x80\x09\x98\xec\xf8\x42\x7e"
+		},
+		{
+			"a",
+			"\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8"
+			"\x31\xc3\x99\xe2\x69\x77\x26\x61"
+		},
+		{
+			"abc",
+			"\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
+			"\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
+		},
+		{
+			"message digest",
+			"\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d"
+			"\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
+		},
+		{
+			"abcdefghijklmnopqrstuvwxyz",
+			"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00"
+			"\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
+		},
+		{
+			"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+			"0123456789",
+			"\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
+			"\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
+		},
+		{
+			"12345678901234567890123456789012345678901234567890"
+			"123456789012345678901234567890",
+			"\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
+			"\xac\x49\xda\x2e\x21\x07\xb6\x7a"
+		}
+	};
+	unsigned int i;
+	u8 hash[16];
+	const u8 *addr[2];
+	size_t len[2];
+	int errors = 0;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		wpa_printf(MSG_INFO, "MD5 test case %d", i);
+
+		addr[0] = (u8 *) tests[i].data;
+		len[0] = strlen(tests[i].data);
+		if (md5_vector(1, addr, len, hash) < 0 ||
+		    os_memcmp(hash, tests[i].hash, 16) != 0) {
+			wpa_printf(MSG_INFO, " FAIL");
+			errors++;
+		} else
+			wpa_printf(MSG_INFO, " OK");
+
+		if (len[0]) {
+			addr[0] = (u8 *) tests[i].data;
+			len[0] = strlen(tests[i].data);
+			addr[1] = (u8 *) tests[i].data + 1;
+			len[1] = strlen(tests[i].data) - 1;
+			if (md5_vector(1, addr, len, hash) < 0 ||
+			    os_memcmp(hash, tests[i].hash, 16) != 0) {
+				wpa_printf(MSG_INFO, " FAIL");
+				errors++;
+			} else
+				wpa_printf(MSG_INFO, " OK");
+		}
+	}
+
+	if (!errors)
+		wpa_printf(MSG_INFO, "MD5 test cases passed");
+
+	return errors;
+}
+
+
 static int test_ms_funcs(void)
 static int test_ms_funcs(void)
 {
 {
 	/* Test vector from RFC2759 example */
 	/* Test vector from RFC2759 example */
@@ -835,6 +919,7 @@ int crypto_module_tests(void)
 	    test_cbc() ||
 	    test_cbc() ||
 	    test_ecb() ||
 	    test_ecb() ||
 	    test_key_wrap() ||
 	    test_key_wrap() ||
+	    test_md5() ||
 	    test_ms_funcs())
 	    test_ms_funcs())
 		ret = -1;
 		ret = -1;
 
 

+ 1 - 5
tests/Makefile

@@ -1,4 +1,4 @@
-TESTS=test-base64 test-md4 test-md5 test-milenage \
+TESTS=test-base64 test-md4 test-milenage \
 	test-rsa-sig-ver \
 	test-rsa-sig-ver \
 	test-sha1 \
 	test-sha1 \
 	test-sha256 test-aes test-asn1 test-x509 test-x509v3 test-list test-rc4
 	test-sha256 test-aes test-asn1 test-x509 test-x509v3 test-list test-rc4
@@ -59,9 +59,6 @@ test-list: test-list.o $(LIBS)
 test-md4: test-md4.o $(LIBS)
 test-md4: test-md4.o $(LIBS)
 	$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
 	$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
 
 
-test-md5: test-md5.o $(LIBS)
-	$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
-
 test-milenage: test-milenage.o $(LIBS)
 test-milenage: test-milenage.o $(LIBS)
 	$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
 	$(LDO) $(LDFLAGS) -o $@ $^ $(LLIBS)
 
 
@@ -88,7 +85,6 @@ run-tests: $(TESTS)
 	./test-aes
 	./test-aes
 	./test-list
 	./test-list
 	./test-md4
 	./test-md4
-	./test-md5
 	./test-milenage
 	./test-milenage
 	./test-rsa-sig-ver
 	./test-rsa-sig-ver
 	./test-sha1
 	./test-sha1

+ 0 - 93
tests/test-md5.c

@@ -1,93 +0,0 @@
-/*
- * Test program for MD5 (test vectors from RFC 1321)
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
- *
- * This software may be distributed under the terms of the BSD license.
- * See README for more details.
- */
-
-#include "includes.h"
-
-#include "common.h"
-#include "crypto/crypto.h"
-
-int main(int argc, char *argv[])
-{
-	struct {
-		char *data;
-		char *hash;
-	} tests[] = {
-		{
-			"",
-			"\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
-			"\xe9\x80\x09\x98\xec\xf8\x42\x7e"
-		},
-		{
-			"a",
-			"\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8"
-			"\x31\xc3\x99\xe2\x69\x77\x26\x61"
-		},
-		{
-			"abc",
-			"\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
-			"\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
-		},
-		{
-			"message digest",
-			"\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d"
-			"\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
-		},
-		{
-			"abcdefghijklmnopqrstuvwxyz",
-			"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00"
-			"\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
-		},
-		{
-			"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-			"0123456789",
-			"\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
-			"\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
-		},
-		{
-			"12345678901234567890123456789012345678901234567890"
-			"123456789012345678901234567890",
-			"\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
-			"\xac\x49\xda\x2e\x21\x07\xb6\x7a"
-		}
-	};
-	unsigned int i;
-	u8 hash[16];
-	const u8 *addr[2];
-	size_t len[2];
-	int errors = 0;
-
-	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		printf("MD5 test case %d:", i);
-
-		addr[0] = (u8 *) tests[i].data;
-		len[0] = strlen(tests[i].data);
-		md5_vector(1, addr, len, hash);
-		if (memcmp(hash, tests[i].hash, 16) != 0) {
-			printf(" FAIL");
-			errors++;
-		} else
-			printf(" OK");
-
-		if (len[0]) {
-			addr[0] = (u8 *) tests[i].data;
-			len[0] = strlen(tests[i].data);
-			addr[1] = (u8 *) tests[i].data + 1;
-			len[1] = strlen(tests[i].data) - 1;
-			md5_vector(1, addr, len, hash);
-			if (memcmp(hash, tests[i].hash, 16) != 0) {
-				printf(" FAIL");
-				errors++;
-			} else
-				printf(" OK");
-		}
-
-		printf("\n");
-	}
-
-	return errors;
-}