Commit 08d2b8ef authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

bcrypt: Make BCRYPT_HASH_LENGTH tests more generic.

parent c1dd2289
......@@ -79,6 +79,18 @@ static void format_hash(const UCHAR *bytes, ULONG size, char *buf)
return;
}
#define test_hash_length(a,b) _test_hash_length(__LINE__,a,b)
static void _test_hash_length(unsigned line, void *handle, ULONG exlen)
{
ULONG len = 0xdeadbeef, size = 0xdeadbeef;
NTSTATUS status;
status = BCryptGetProperty(handle, BCRYPT_HASH_LENGTH, (UCHAR *)&len, sizeof(len), &size, 0);
ok_(__FILE__,line)(status == STATUS_SUCCESS, "BCryptGetProperty failed: %08x\n", status);
ok_(__FILE__,line)(size == sizeof(len), "got %u\n", size);
ok_(__FILE__,line)(len == exlen, "len = %u, expected %u\n", len, exlen);
}
static void test_sha1(void)
{
static const char expected[] = "961fa64958818f767707072755d7018dcd278e94";
......@@ -123,11 +135,7 @@ 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);
test_hash_length(alg, 20);
hash = NULL;
len = sizeof(buf);
......@@ -138,11 +146,7 @@ static void test_sha1(void)
ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
len = size = 0xdeadbeef;
ret = BCryptGetProperty(hash, 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);
test_hash_length(hash, 20);
memset(sha1, 0, sizeof(sha1));
ret = BCryptFinishHash(hash, sha1, sizeof(sha1), 0);
......@@ -202,11 +206,7 @@ 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);
test_hash_length(alg, 32);
hash = NULL;
len = sizeof(buf);
......@@ -217,11 +217,7 @@ static void test_sha256(void)
ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
len = size = 0xdeadbeef;
ret = BCryptGetProperty(hash, 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);
test_hash_length(hash, 32);
memset(sha256, 0, sizeof(sha256));
ret = BCryptFinishHash(hash, sha256, sizeof(sha256), 0);
......@@ -281,11 +277,7 @@ 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);
test_hash_length(alg, 48);
hash = NULL;
len = sizeof(buf);
......@@ -296,11 +288,7 @@ static void test_sha384(void)
ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
len = size = 0xdeadbeef;
ret = BCryptGetProperty(hash, 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);
test_hash_length(hash, 48);
memset(sha384, 0, sizeof(sha384));
ret = BCryptFinishHash(hash, sha384, sizeof(sha384), 0);
......@@ -361,11 +349,7 @@ 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);
test_hash_length(alg, 64);
hash = NULL;
len = sizeof(buf);
......@@ -376,11 +360,7 @@ static void test_sha512(void)
ret = BCryptHashData(hash, (UCHAR *)"test", sizeof("test"), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
len = size = 0xdeadbeef;
ret = BCryptGetProperty(hash, 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);
test_hash_length(hash, 64);
memset(sha512, 0, sizeof(sha512));
ret = BCryptFinishHash(hash, sha512, sizeof(sha512), 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment