summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-08-14 14:56:21 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:15:35 -0500
commit1935ef0d5446bf372ee570ee20da703eaab65718 (patch)
tree94f4510be7d096ea543ae4ba312f191a144d4651
parent8c6cb8f09b02a599891c97028a28be0336f1e05c (diff)
downloadsamba-1935ef0d5446bf372ee570ee20da703eaab65718.tar.gz
samba-1935ef0d5446bf372ee570ee20da703eaab65718.tar.bz2
samba-1935ef0d5446bf372ee570ee20da703eaab65718.zip
r17539: add HMAC-MD5 test code based on the example values from rfc 2104, 2202
metze (This used to be commit 200b1a5c81bd61320ac6b7e79880411920e3f432)
-rw-r--r--source4/lib/crypto/hmacmd5test.c99
-rwxr-xr-xsource4/script/tests/test_local.sh3
-rw-r--r--source4/torture/local/config.mk1
-rw-r--r--source4/torture/local/local.c1
4 files changed, 103 insertions, 1 deletions
diff --git a/source4/lib/crypto/hmacmd5test.c b/source4/lib/crypto/hmacmd5test.c
new file mode 100644
index 0000000000..a1d3ff0ee1
--- /dev/null
+++ b/source4/lib/crypto/hmacmd5test.c
@@ -0,0 +1,99 @@
+/*
+ Unix SMB/CIFS implementation.
+ HMAC MD5 tests
+ Copyright (C) Stefan Metzmacher 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+#include "includes.h"
+#include "lib/crypto/crypto.h"
+
+struct torture_context;
+
+static DATA_BLOB data_blob_repeat_byte(uint8_t byte, size_t length)
+{
+ DATA_BLOB b = data_blob(NULL, length);
+ memset(b.data, byte, length);
+ return b;
+}
+
+/*
+ This uses the test values from rfc 2104, 2202
+*/
+BOOL torture_local_crypto_hmacmd5(struct torture_context *torture)
+{
+ BOOL ret = True;
+ uint32_t i;
+ struct {
+ DATA_BLOB key;
+ DATA_BLOB data;
+ DATA_BLOB md5;
+ } testarray[] = {
+ {
+ .key = data_blob_repeat_byte(0x0b, 16),
+ .data = data_blob_string_const("Hi There"),
+ .md5 = strhex_to_data_blob("9294727a3638bb1c13f48ef8158bfc9d")
+ },{
+ .key = data_blob_string_const("Jefe"),
+ .data = data_blob_string_const("what do ya want for nothing?"),
+ .md5 = strhex_to_data_blob("750c783e6ab0b503eaa86e310a5db738")
+ },{
+ .key = data_blob_repeat_byte(0xaa, 16),
+ .data = data_blob_repeat_byte(0xdd, 50),
+ .md5 = strhex_to_data_blob("56be34521d144c88dbb8c733f0e8b3f6")
+ },{
+ .key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"),
+ .data = data_blob_repeat_byte(0xcd, 50),
+ .md5 = strhex_to_data_blob("697eaf0aca3a3aea3a75164746ffaa79")
+ },{
+ .key = data_blob_repeat_byte(0x0c, 16),
+ .data = data_blob_string_const("Test With Truncation"),
+ .md5 = strhex_to_data_blob("56461ef2342edc00f9bab995690efd4c")
+ },{
+ .key = data_blob_repeat_byte(0xaa, 80),
+ .data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"),
+ .md5 = strhex_to_data_blob("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd")
+ },{
+ .key = data_blob_repeat_byte(0xaa, 80),
+ .data = data_blob_string_const("Test Using Larger Than Block-Size Key "
+ "and Larger Than One Block-Size Data"),
+ .md5 = strhex_to_data_blob("6f630fad67cda0ee1fb1f562db3aa53e")
+ }
+ };
+
+ for (i=0; i < ARRAY_SIZE(testarray); i++) {
+ HMACMD5Context ctx;
+ uint8_t md5[16];
+ int e;
+
+ hmac_md5_init_rfc2104(testarray[i].key.data, testarray[i].key.length, &ctx);
+ hmac_md5_update(testarray[i].data.data, testarray[i].data.length, &ctx);
+ hmac_md5_final(md5, &ctx);
+
+ e = memcmp(testarray[i].md5.data,
+ md5,
+ MIN(testarray[i].md5.length, sizeof(md5)));
+ if (e != 0) {
+ printf("hmacmd5 test[%u]: failed\n", i);
+ dump_data(0, testarray[i].key.data, testarray[i].key.length);
+ dump_data(0, testarray[i].data.data, testarray[i].data.length);
+ dump_data(0, testarray[i].md5.data, testarray[i].md5.length);
+ dump_data(0, md5, sizeof(md5));
+ ret = False;
+ }
+ }
+
+ return ret;
+}
diff --git a/source4/script/tests/test_local.sh b/source4/script/tests/test_local.sh
index e2035211c9..8503b0d96a 100755
--- a/source4/script/tests/test_local.sh
+++ b/source4/script/tests/test_local.sh
@@ -3,7 +3,8 @@
local_tests="LOCAL-NTLMSSP LOCAL-TALLOC LOCAL-MESSAGING LOCAL-IRPC"
local_tests="$local_tests LOCAL-BINDING LOCAL-IDTREE LOCAL-SOCKET"
local_tests="$local_tests LOCAL-PAC LOCAL-STRLIST LOCAL-SDDL LOCAL-NDR"
-local_tests="$local_tests LOCAL-EVENT LOCAL-CRYPTO-MD4 LOCAL-CRYPTO-MD5"
+local_tests="$local_tests LOCAL-EVENT LOCAL-CRYPTO-MD4"
+local_tests="$local_tests LOCAL-CRYPTO-MD5 LOCAL-CRYPTO-HMACMD5"
local_tests="$local_tests LOCAL-CRYPTO-SHA1 LOCAL-CRYPTO-HMACSHA1"
if [ $# -lt 0 ]; then
diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk
index 4165de4b56..85bf715632 100644
--- a/source4/torture/local/config.mk
+++ b/source4/torture/local/config.mk
@@ -10,6 +10,7 @@ OBJ_FILES = \
../../lib/talloc/testsuite.o \
../../lib/crypto/md4test.o \
../../lib/crypto/md5test.o \
+ ../../lib/crypto/hmacmd5test.o \
../../lib/crypto/sha1test.o \
../../lib/crypto/hmacsha1test.o \
messaging.o \
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index 455d29d2ee..4c18803d23 100644
--- a/source4/torture/local/local.c
+++ b/source4/torture/local/local.c
@@ -53,6 +53,7 @@ NTSTATUS torture_local_init(void)
register_torture_op("LOCAL-TALLOC", torture_local_talloc);
register_torture_op("LOCAL-CRYPTO-MD4", torture_local_crypto_md4);
register_torture_op("LOCAL-CRYPTO-MD5", torture_local_crypto_md5);
+ register_torture_op("LOCAL-CRYPTO-HMACMD5", torture_local_crypto_hmacmd5);
register_torture_op("LOCAL-CRYPTO-SHA1", torture_local_crypto_sha1);
register_torture_op("LOCAL-CRYPTO-HMACSHA1", torture_local_crypto_hmacsha1);
for (i = 0; suite_generators[i]; i++)