From 11279badf212e4cec7211662aea8b44d206f2f55 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 20 Jan 2016 14:51:44 +0100 Subject: [PATCH] bcrypt: Support retrieving hash length from algorithm handles. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/bcrypt/bcrypt_main.c | 20 ++++++++++++++++++++ dlls/bcrypt/tests/bcrypt.c | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c index 6393d59f299..4871f204c43 100644 --- a/dlls/bcrypt/bcrypt_main.c +++ b/dlls/bcrypt/bcrypt_main.c @@ -438,6 +438,11 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, value = OBJECT_LENGTH_SHA1; break; } + else if (!strcmpW( prop, BCRYPT_HASH_LENGTH )) + { + value = HASH_DIGEST_LENGTH_SHA1; + break; + } FIXME( "unsupported sha1 algorithm property %s\n", debugstr_w(prop) ); return STATUS_NOT_IMPLEMENTED; @@ -447,6 +452,11 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, value = OBJECT_LENGTH_SHA256; break; } + else if (!strcmpW( prop, BCRYPT_HASH_LENGTH )) + { + value = HASH_DIGEST_LENGTH_SHA256; + break; + } FIXME( "unsupported sha256 algorithm property %s\n", debugstr_w(prop) ); return STATUS_NOT_IMPLEMENTED; @@ -456,6 +466,11 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, value = OBJECT_LENGTH_SHA384; break; } + else if (!strcmpW( prop, BCRYPT_HASH_LENGTH )) + { + value = HASH_DIGEST_LENGTH_SHA384; + break; + } FIXME( "unsupported sha384 algorithm property %s\n", debugstr_w(prop) ); return STATUS_NOT_IMPLEMENTED; @@ -465,6 +480,11 @@ static NTSTATUS get_alg_property( enum alg_id id, const WCHAR *prop, UCHAR *buf, value = OBJECT_LENGTH_SHA512; break; } + else if (!strcmpW( prop, BCRYPT_HASH_LENGTH )) + { + value = HASH_DIGEST_LENGTH_SHA512; + break; + } FIXME( "unsupported sha512 algorithm property %s\n", debugstr_w(prop) ); return STATUS_NOT_IMPLEMENTED; diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c index 2e45600a3c3..721221c83b5 100644 --- a/dlls/bcrypt/tests/bcrypt.c +++ b/dlls/bcrypt/tests/bcrypt.c @@ -123,6 +123,12 @@ static void test_sha1(void) ok(len != 0xdeadbeef, "len not set\n"); ok(size == sizeof(len), "got %u\n", size); + len = size = 0xdeadbeef; + ret = BCryptGetProperty(alg, BCRYPT_HASH_LENGTH, (UCHAR *)&len , sizeof(len), &size, 0); + ok(ret == STATUS_SUCCESS, "got %08x\n", ret); + ok(len == 20, "got %u\n", len); + ok(size == sizeof(len), "got %u\n", size); + hash = NULL; len = sizeof(buf); ret = BCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0); @@ -196,6 +202,12 @@ static void test_sha256(void) ok(len != 0xdeadbeef, "len not set\n"); ok(size == sizeof(len), "got %u\n", size); + len = size = 0xdeadbeef; + ret = BCryptGetProperty(alg, BCRYPT_HASH_LENGTH, (UCHAR *)&len , sizeof(len), &size, 0); + ok(ret == STATUS_SUCCESS, "got %08x\n", ret); + ok(len == 32, "got %u\n", len); + ok(size == sizeof(len), "got %u\n", size); + hash = NULL; len = sizeof(buf); ret = BCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0); @@ -269,6 +281,12 @@ static void test_sha384(void) ok(len != 0xdeadbeef, "len not set\n"); ok(size == sizeof(len), "got %u\n", size); + len = size = 0xdeadbeef; + ret = BCryptGetProperty(alg, BCRYPT_HASH_LENGTH, (UCHAR *)&len , sizeof(len), &size, 0); + ok(ret == STATUS_SUCCESS, "got %08x\n", ret); + ok(len == 48, "got %u\n", len); + ok(size == sizeof(len), "got %u\n", size); + hash = NULL; len = sizeof(buf); ret = BCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0); @@ -343,6 +361,12 @@ static void test_sha512(void) ok(len != 0xdeadbeef, "len not set\n"); ok(size == sizeof(len), "got %u\n", size); + len = size = 0xdeadbeef; + ret = BCryptGetProperty(alg, BCRYPT_HASH_LENGTH, (UCHAR *)&len , sizeof(len), &size, 0); + ok(ret == STATUS_SUCCESS, "got %08x\n", ret); + ok(len == 64, "got %u\n", len); + ok(size == sizeof(len), "got %u\n", size); + hash = NULL; len = sizeof(buf); ret = BCryptCreateHash(alg, &hash, buf, len, NULL, 0, 0);