Commit bc20b546 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

bcrypt/tests: Add basic tests for BCryptDuplicateHash.

parent da8853f0
...@@ -33,6 +33,7 @@ static NTSTATUS (WINAPI *pBCryptCreateHash)(BCRYPT_ALG_HANDLE, BCRYPT_HASH_HANDL ...@@ -33,6 +33,7 @@ static NTSTATUS (WINAPI *pBCryptCreateHash)(BCRYPT_ALG_HANDLE, BCRYPT_HASH_HANDL
ULONG, ULONG); ULONG, ULONG);
static NTSTATUS (WINAPI *pBCryptHash)(BCRYPT_ALG_HANDLE, UCHAR *, ULONG, UCHAR *, ULONG, UCHAR *, ULONG); static NTSTATUS (WINAPI *pBCryptHash)(BCRYPT_ALG_HANDLE, UCHAR *, ULONG, UCHAR *, ULONG, UCHAR *, ULONG);
static NTSTATUS (WINAPI *pBCryptHashData)(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG); static NTSTATUS (WINAPI *pBCryptHashData)(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG);
static NTSTATUS (WINAPI *pBCryptDuplicateHash)(BCRYPT_HASH_HANDLE, BCRYPT_HASH_HANDLE *, UCHAR *, ULONG, ULONG);
static NTSTATUS (WINAPI *pBCryptFinishHash)(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG); static NTSTATUS (WINAPI *pBCryptFinishHash)(BCRYPT_HASH_HANDLE, PUCHAR, ULONG, ULONG);
static NTSTATUS (WINAPI *pBCryptDestroyHash)(BCRYPT_HASH_HANDLE); static NTSTATUS (WINAPI *pBCryptDestroyHash)(BCRYPT_HASH_HANDLE);
static NTSTATUS (WINAPI *pBCryptGenRandom)(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, ULONG); static NTSTATUS (WINAPI *pBCryptGenRandom)(BCRYPT_ALG_HANDLE, PUCHAR, ULONG, ULONG);
...@@ -208,9 +209,9 @@ static void test_sha1(void) ...@@ -208,9 +209,9 @@ static void test_sha1(void)
{ {
static const char expected[] = "961fa64958818f767707072755d7018dcd278e94"; static const char expected[] = "961fa64958818f767707072755d7018dcd278e94";
static const char expected_hmac[] = "2472cf65d0e090618d769d3e46f0d9446cf212da"; static const char expected_hmac[] = "2472cf65d0e090618d769d3e46f0d9446cf212da";
UCHAR buf[512], buf_hmac[1024], buf_hmac2[1024], sha1[20], sha1_hmac[20];
BCRYPT_HASH_HANDLE hash, hash2;
BCRYPT_ALG_HANDLE alg; BCRYPT_ALG_HANDLE alg;
BCRYPT_HASH_HANDLE hash;
UCHAR buf[512], buf_hmac[1024], sha1[20], sha1_hmac[20];
char str[41]; char str[41];
NTSTATUS ret; NTSTATUS ret;
ULONG len; ULONG len;
...@@ -268,6 +269,29 @@ static void test_sha1(void) ...@@ -268,6 +269,29 @@ static void test_sha1(void)
test_hash_length(hash, 20); test_hash_length(hash, 20);
test_alg_name(hash, "SHA1"); test_alg_name(hash, "SHA1");
len = sizeof(buf_hmac2);
ret = pBCryptDuplicateHash(NULL, &hash2, buf_hmac2, len, 0);
ok(ret == STATUS_INVALID_HANDLE, "got %08x\n", ret);
len = sizeof(buf_hmac2);
ret = pBCryptDuplicateHash(hash, NULL, buf_hmac2, len, 0);
ok(ret == STATUS_INVALID_PARAMETER, "got %08x\n", ret);
hash2 = NULL;
len = sizeof(buf_hmac2);
ret = pBCryptDuplicateHash(hash, &hash2, buf_hmac2, len, 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
ok(hash2 != NULL, "hash not set\n");
memset(sha1_hmac, 0, sizeof(sha1_hmac));
ret = pBCryptFinishHash(hash2, sha1_hmac, sizeof(sha1_hmac), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
format_hash( sha1_hmac, sizeof(sha1_hmac), str );
ok(!strcmp(str, expected_hmac), "got %s\n", str);
ret = pBCryptDestroyHash(hash2);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
memset(sha1_hmac, 0, sizeof(sha1_hmac)); memset(sha1_hmac, 0, sizeof(sha1_hmac));
ret = pBCryptFinishHash(hash, sha1_hmac, sizeof(sha1_hmac), 0); ret = pBCryptFinishHash(hash, sha1_hmac, sizeof(sha1_hmac), 0);
ok(ret == STATUS_SUCCESS, "got %08x\n", ret); ok(ret == STATUS_SUCCESS, "got %08x\n", ret);
...@@ -990,6 +1014,7 @@ START_TEST(bcrypt) ...@@ -990,6 +1014,7 @@ START_TEST(bcrypt)
pBCryptCreateHash = (void *)GetProcAddress(module, "BCryptCreateHash"); pBCryptCreateHash = (void *)GetProcAddress(module, "BCryptCreateHash");
pBCryptHash = (void *)GetProcAddress(module, "BCryptHash"); pBCryptHash = (void *)GetProcAddress(module, "BCryptHash");
pBCryptHashData = (void *)GetProcAddress(module, "BCryptHashData"); pBCryptHashData = (void *)GetProcAddress(module, "BCryptHashData");
pBCryptDuplicateHash = (void *)GetProcAddress(module, "BCryptDuplicateHash");
pBCryptFinishHash = (void *)GetProcAddress(module, "BCryptFinishHash"); pBCryptFinishHash = (void *)GetProcAddress(module, "BCryptFinishHash");
pBCryptDestroyHash = (void *)GetProcAddress(module, "BCryptDestroyHash"); pBCryptDestroyHash = (void *)GetProcAddress(module, "BCryptDestroyHash");
pBCryptGenRandom = (void *)GetProcAddress(module, "BCryptGenRandom"); pBCryptGenRandom = (void *)GetProcAddress(module, "BCryptGenRandom");
......
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