bcrypt: Make BCryptHashData behave more like Windows with empty input

Patrick Armstrong pat at triplefox.com
Tue Mar 8 22:42:45 CST 2016


This behavior is undocumented in MSDN, but is how this function
actually behaves on Windows.

Tested on OS X 10.11, Ubuntu 14.04, and Windows 10.

Signed-off-by: Patrick Armstrong <pat at oldpatricka.com>
---
 dlls/bcrypt/bcrypt_main.c  |  2 +-
 dlls/bcrypt/tests/bcrypt.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 957efdd..c919c1d 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -632,7 +632,7 @@ NTSTATUS WINAPI BCryptHashData( BCRYPT_HASH_HANDLE handle, UCHAR *input, ULONG s
     TRACE( "%p, %p, %u, %08x\n", handle, input, size, flags );
 
     if (!hash || hash->hdr.magic != MAGIC_HASH) return STATUS_INVALID_HANDLE;
-    if (!input) return STATUS_INVALID_PARAMETER;
+    if (!input) return STATUS_SUCCESS;
 
     return hash_update( hash, input, size );
 }
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c
index bcb287b..f1f0002 100644
--- a/dlls/bcrypt/tests/bcrypt.c
+++ b/dlls/bcrypt/tests/bcrypt.c
@@ -165,6 +165,9 @@ static void test_sha1(void)
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
     ok(hash != NULL, "hash not set\n");
 
+    ret = BCryptHashData(hash, NULL, 0, 0);
+    ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
+
     ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
 
@@ -238,6 +241,9 @@ static void test_sha256(void)
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
     ok(hash != NULL, "hash not set\n");
 
+    ret = BCryptHashData(hash, NULL, 0, 0);
+    ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
+
     ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
 
@@ -311,6 +317,9 @@ static void test_sha384(void)
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
     ok(hash != NULL, "hash not set\n");
 
+    ret = BCryptHashData(hash, NULL, 0, 0);
+    ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
+
     ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
 
@@ -385,6 +394,9 @@ static void test_sha512(void)
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
     ok(hash != NULL, "hash not set\n");
 
+    ret = BCryptHashData(hash, NULL, 0, 0);
+    ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
+
     ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
 
@@ -458,6 +470,9 @@ static void test_md5(void)
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
     ok(hash != NULL, "hash not set\n");
 
+    ret = BCryptHashData(hash, NULL, 0, 0);
+    ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
+
     ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
     ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
 
-- 
2.5.4 (Apple Git-61)




More information about the wine-patches mailing list