From b165e48b3e6023a21dc39acd883d56b274cd5d5f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 Aug 2006 13:13:03 +0000 Subject: r17494: add tests for the example values from rfc 1320 (MD4) metze (This used to be commit 5609ab2116e3568e4f1a82b3ae781f17a6ffb645) --- source4/lib/crypto/md4test.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 source4/lib/crypto/md4test.c (limited to 'source4/lib/crypto/md4test.c') diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c new file mode 100644 index 0000000000..a8c5ff9f8f --- /dev/null +++ b/source4/lib/crypto/md4test.c @@ -0,0 +1,84 @@ +/* + Unix SMB/CIFS implementation. + MD4 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; + +/* + This uses the test values from rfc1320 +*/ +BOOL torture_local_crypto_md4(struct torture_context *torture) +{ + BOOL ret = True; + uint32_t i; + struct { + DATA_BLOB data; + DATA_BLOB md4; + } testarray[] = { + { + .data = data_blob_string_const(""), + .md4 = strhex_to_data_blob("31d6cfe0d16ae931b73c59d7e0c089c0") + },{ + .data = data_blob_string_const("a"), + .md4 = strhex_to_data_blob("bde52cb31de33e46245e05fbdbd6fb24") + },{ + .data = data_blob_string_const("abc"), + .md4 = strhex_to_data_blob("a448017aaf21d8525fc10ae87aa6729d") + },{ + .data = data_blob_string_const("message digest"), + .md4 = strhex_to_data_blob("d9130a8164549fe818874806e1c7014b") + },{ + .data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), + .md4 = strhex_to_data_blob("d79e1c308aa5bbcdeea8ed63df412da9") + },{ + .data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"), + .md4 = strhex_to_data_blob("043f8582f241db351ce627e153e7f0e4") + },{ + .data = data_blob_string_const("123456789012345678901234567890" + "123456789012345678901234567890" + "12345678901234567890"), + .md4 = strhex_to_data_blob("e33b4ddc9c38f2199c3e7b164fcc0536") + } + }; + + for (i=0; i < ARRAY_SIZE(testarray); i++) { + uint8_t md4[16]; + int e; + + mdfour(md4, testarray[i].data.data, testarray[i].data.length); + + e = memcmp(testarray[i].md4.data, + md4, + MIN(testarray[i].md4.length, sizeof(md4))); + if (e != 0) { + printf("md4 test[%u]: failed\n", i); + dump_data(0, testarray[i].data.data, testarray[i].data.length); + dump_data(0, testarray[i].md4.data, testarray[i].md4.length); + dump_data(0, md4, sizeof(md4)); + ret = False; + } + } + + return ret; +} -- cgit From db96ce03e99e657c4590d576d99f95da70cef5d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2006 00:59:31 +0000 Subject: r18351: functions as initialisers in structures doesn't work on some compilers (This used to be commit db694a7c82e4b5071aa7f609de6ecde90a8d42dd) --- source4/lib/crypto/md4test.c | 51 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'source4/lib/crypto/md4test.c') diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c index a8c5ff9f8f..747d374396 100644 --- a/source4/lib/crypto/md4test.c +++ b/source4/lib/crypto/md4test.c @@ -31,50 +31,49 @@ BOOL torture_local_crypto_md4(struct torture_context *torture) BOOL ret = True; uint32_t i; struct { - DATA_BLOB data; - DATA_BLOB md4; + const char *data; + const char *md4; } testarray[] = { { - .data = data_blob_string_const(""), - .md4 = strhex_to_data_blob("31d6cfe0d16ae931b73c59d7e0c089c0") + .data = "", + .md4 = "31d6cfe0d16ae931b73c59d7e0c089c0" },{ - .data = data_blob_string_const("a"), - .md4 = strhex_to_data_blob("bde52cb31de33e46245e05fbdbd6fb24") + .data = "a", + .md4 = "bde52cb31de33e46245e05fbdbd6fb24" },{ - .data = data_blob_string_const("abc"), - .md4 = strhex_to_data_blob("a448017aaf21d8525fc10ae87aa6729d") + .data = "abc", + .md4 = "a448017aaf21d8525fc10ae87aa6729d" },{ - .data = data_blob_string_const("message digest"), - .md4 = strhex_to_data_blob("d9130a8164549fe818874806e1c7014b") + .data = "message digest", + .md4 = "d9130a8164549fe818874806e1c7014b" },{ - .data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), - .md4 = strhex_to_data_blob("d79e1c308aa5bbcdeea8ed63df412da9") + .data = "abcdefghijklmnopqrstuvwxyz", + .md4 = "d79e1c308aa5bbcdeea8ed63df412da9" },{ - .data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789"), - .md4 = strhex_to_data_blob("043f8582f241db351ce627e153e7f0e4") + .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + .md4 = "043f8582f241db351ce627e153e7f0e4" },{ - .data = data_blob_string_const("123456789012345678901234567890" - "123456789012345678901234567890" - "12345678901234567890"), - .md4 = strhex_to_data_blob("e33b4ddc9c38f2199c3e7b164fcc0536") + .data = "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + .md4 = "e33b4ddc9c38f2199c3e7b164fcc0536" } }; for (i=0; i < ARRAY_SIZE(testarray); i++) { uint8_t md4[16]; int e; + DATA_BLOB data; + DATA_BLOB md4blob; + + data = data_blob_string_const(testarray[i].data); + md4blob = strhex_to_data_blob(testarray[i].md4); - mdfour(md4, testarray[i].data.data, testarray[i].data.length); + mdfour(md4, data.data, data.length); - e = memcmp(testarray[i].md4.data, - md4, - MIN(testarray[i].md4.length, sizeof(md4))); + e = memcmp(md4blob.data, md4, MIN(md4blob.length, sizeof(md4))); if (e != 0) { printf("md4 test[%u]: failed\n", i); - dump_data(0, testarray[i].data.data, testarray[i].data.length); - dump_data(0, testarray[i].md4.data, testarray[i].md4.length); + dump_data(0, data.data, data.length); + dump_data(0, md4blob.data, md4blob.length); dump_data(0, md4, sizeof(md4)); ret = False; } -- cgit From 2059aa0949b831c362b30d82ccba8a7c8cb1c601 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 11 Sep 2006 04:18:16 +0000 Subject: r18357: Convert more crypto tests from using function results as initialisers. (Fails on older Unix C compilers) Andrew Bartlett (This used to be commit a4cc13a93fc2f18bfb266603617e14d1cc7ceecf) --- source4/lib/crypto/md4test.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/crypto/md4test.c') diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c index 747d374396..1c98fe0846 100644 --- a/source4/lib/crypto/md4test.c +++ b/source4/lib/crypto/md4test.c @@ -77,6 +77,7 @@ BOOL torture_local_crypto_md4(struct torture_context *torture) dump_data(0, md4, sizeof(md4)); ret = False; } + talloc_free(md4blob.data); } return ret; -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/crypto/md4test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/crypto/md4test.c') diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c index 1c98fe0846..fa92668f84 100644 --- a/source4/lib/crypto/md4test.c +++ b/source4/lib/crypto/md4test.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" -- cgit From 719a4ae0d32ab9ba817fd01f2b8f4cba220a8c60 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Oct 2007 18:03:01 +0000 Subject: r25522: Convert to standard bool types. (This used to be commit 5e814287ba475e12f8cc934fdd09b199dcdfdb86) --- source4/lib/crypto/md4test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/crypto/md4test.c') diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c index fa92668f84..5e0451973c 100644 --- a/source4/lib/crypto/md4test.c +++ b/source4/lib/crypto/md4test.c @@ -25,9 +25,9 @@ struct torture_context; /* This uses the test values from rfc1320 */ -BOOL torture_local_crypto_md4(struct torture_context *torture) +bool torture_local_crypto_md4(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; uint32_t i; struct { const char *data; @@ -74,7 +74,7 @@ BOOL torture_local_crypto_md4(struct torture_context *torture) dump_data(0, data.data, data.length); dump_data(0, md4blob.data, md4blob.length); dump_data(0, md4, sizeof(md4)); - ret = False; + ret = false; } talloc_free(md4blob.data); } -- cgit