From 559158a3c932cbe20a842e4a8ea46aea42403c2f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 Aug 2006 11:26:58 +0000 Subject: r17492: add a test with the example values from rfc1321 (MD5) metze (This used to be commit bb1e4954f9aa60858a2c5b2f798f10fd75849b42) --- source4/lib/crypto/md5test.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 source4/lib/crypto/md5test.c (limited to 'source4/lib/crypto/md5test.c') diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c new file mode 100644 index 0000000000..6c2de9e675 --- /dev/null +++ b/source4/lib/crypto/md5test.c @@ -0,0 +1,87 @@ +/* + Unix SMB/CIFS implementation. + MD5 tests + Copyright (C) Stefan Metzmacher + + 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 rfc1321 +*/ +BOOL torture_local_crypto_md5(struct torture_context *torture) +{ + BOOL ret = True; + uint32_t i; + struct { + DATA_BLOB data; + DATA_BLOB md5; + } testarray[] = { + { + .data = data_blob_string_const(""), + .md5 = strhex_to_data_blob("d41d8cd98f00b204e9800998ecf8427e") + },{ + .data = data_blob_string_const("a"), + .md5 = strhex_to_data_blob("0cc175b9c0f1b6a831c399e269772661") + },{ + .data = data_blob_string_const("abc"), + .md5 = strhex_to_data_blob("900150983cd24fb0d6963f7d28e17f72") + },{ + .data = data_blob_string_const("message digest"), + .md5 = strhex_to_data_blob("f96b697d7cb7938d525a2f31aaf161d0") + },{ + .data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), + .md5 = strhex_to_data_blob("c3fcd3d76192e4007dfb496cca67e13b") + },{ + .data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"), + .md5 = strhex_to_data_blob("d174ab98d277d9f5a5611c2c9f419d9f") + },{ + .data = data_blob_string_const("123456789012345678901234567890" + "123456789012345678901234567890" + "12345678901234567890"), + .md5 = strhex_to_data_blob("57edf4a22be3c955ac49da2e2107b67a") + } + }; + + for (i=0; i < ARRAY_SIZE(testarray); i++) { + struct MD5Context ctx; + uint8_t md5[16]; + int e; + + MD5Init(&ctx); + MD5Update(&ctx, testarray[i].data.data, testarray[i].data.length); + MD5Final(md5, &ctx); + + e = memcmp(testarray[i].md5.data, + md5, + MIN(testarray[i].md5.length, sizeof(md5))); + if (e != 0) { + printf("hmacsha1 test[%u]: failed\n", i); + 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; +} -- cgit From a889fef4b1632812da9be805f3eb82552581ab35 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 Aug 2006 11:47:11 +0000 Subject: r17493: fix typo metze (This used to be commit 785c46ed375b99f5765c2d8a2c7c1aaf400119f8) --- source4/lib/crypto/md5test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/crypto/md5test.c') diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c index 6c2de9e675..89b0e55876 100644 --- a/source4/lib/crypto/md5test.c +++ b/source4/lib/crypto/md5test.c @@ -75,7 +75,7 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) md5, MIN(testarray[i].md5.length, sizeof(md5))); if (e != 0) { - printf("hmacsha1 test[%u]: failed\n", i); + printf("md5 test[%u]: failed\n", i); 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)); -- 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/md5test.c | 53 +++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'source4/lib/crypto/md5test.c') diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c index 89b0e55876..f16eabf75c 100644 --- a/source4/lib/crypto/md5test.c +++ b/source4/lib/crypto/md5test.c @@ -31,34 +31,34 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) BOOL ret = True; uint32_t i; struct { - DATA_BLOB data; - DATA_BLOB md5; + const char *data; + const char *md5; } testarray[] = { { - .data = data_blob_string_const(""), - .md5 = strhex_to_data_blob("d41d8cd98f00b204e9800998ecf8427e") + .data = "", + .md5 = "d41d8cd98f00b204e9800998ecf8427e" },{ - .data = data_blob_string_const("a"), - .md5 = strhex_to_data_blob("0cc175b9c0f1b6a831c399e269772661") + .data = "a", + .md5 = "0cc175b9c0f1b6a831c399e269772661" },{ - .data = data_blob_string_const("abc"), - .md5 = strhex_to_data_blob("900150983cd24fb0d6963f7d28e17f72") + .data = "abc", + .md5 = "900150983cd24fb0d6963f7d28e17f72" },{ - .data = data_blob_string_const("message digest"), - .md5 = strhex_to_data_blob("f96b697d7cb7938d525a2f31aaf161d0") + .data = "message digest", + .md5 = "f96b697d7cb7938d525a2f31aaf161d0" },{ - .data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), - .md5 = strhex_to_data_blob("c3fcd3d76192e4007dfb496cca67e13b") + .data = "abcdefghijklmnopqrstuvwxyz", + .md5 = "c3fcd3d76192e4007dfb496cca67e13b" },{ - .data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" - "0123456789"), - .md5 = strhex_to_data_blob("d174ab98d277d9f5a5611c2c9f419d9f") + "0123456789", + .md5 = "d174ab98d277d9f5a5611c2c9f419d9f" },{ - .data = data_blob_string_const("123456789012345678901234567890" + .data = "123456789012345678901234567890" "123456789012345678901234567890" - "12345678901234567890"), - .md5 = strhex_to_data_blob("57edf4a22be3c955ac49da2e2107b67a") + "12345678901234567890", + .md5 = "57edf4a22be3c955ac49da2e2107b67a" } }; @@ -67,20 +67,27 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) uint8_t md5[16]; int e; + DATA_BLOB data; + DATA_BLOB md5blob; + + data = data_blob_string_const(testarray[i].data); + md5blob = strhex_to_data_blob(testarray[i].md5); + MD5Init(&ctx); - MD5Update(&ctx, testarray[i].data.data, testarray[i].data.length); + MD5Update(&ctx, data.data, data.length); MD5Final(md5, &ctx); - e = memcmp(testarray[i].md5.data, + e = memcmp(md5blob.data, md5, - MIN(testarray[i].md5.length, sizeof(md5))); + MIN(md5blob.length, sizeof(md5))); if (e != 0) { printf("md5 test[%u]: failed\n", i); - 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, data.data, data.length); + dump_data(0, md5blob.data, md5blob.length); dump_data(0, md5, sizeof(md5)); ret = False; } + talloc_free(md5blob.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/md5test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/crypto/md5test.c') diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c index f16eabf75c..12645dc045 100644 --- a/source4/lib/crypto/md5test.c +++ b/source4/lib/crypto/md5test.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/md5test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/crypto/md5test.c') diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c index 12645dc045..702e0fcf41 100644 --- a/source4/lib/crypto/md5test.c +++ b/source4/lib/crypto/md5test.c @@ -25,9 +25,9 @@ struct torture_context; /* This uses the test values from rfc1321 */ -BOOL torture_local_crypto_md5(struct torture_context *torture) +bool torture_local_crypto_md5(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; uint32_t i; struct { const char *data; @@ -84,7 +84,7 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) dump_data(0, data.data, data.length); dump_data(0, md5blob.data, md5blob.length); dump_data(0, md5, sizeof(md5)); - ret = False; + ret = false; } talloc_free(md5blob.data); } -- cgit