Commit 5df4ff13 authored by Christopher Denton's avatar Christopher Denton Committed by Alexandre Julliard
Browse files

bcrypt: Add basic support for pseudo-handles.

Support constant values for algorithm handles in `BCryptGenRandom` and make no attempt to dereference such handles.
parent c8592b97
Pipeline #1947 skipped
......@@ -190,6 +190,17 @@ NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE handle, UCHAR *buffer, ULONG c
if (!(flags & BCRYPT_USE_SYSTEM_PREFERRED_RNG))
return STATUS_INVALID_HANDLE;
}
else if (((ULONG_PTR)algorithm & 1) == 1)
{
/* Pseudo algorithm handles are denoted by having the lowest bit set.
* An aligned algorithm pointer will never have this bit set.
*/
if (algorithm != BCRYPT_RNG_ALG_HANDLE)
{
FIXME("pseudo-handle algorithm %p not supported\n", algorithm);
return STATUS_NOT_IMPLEMENTED;
}
}
else if (algorithm->hdr.magic != MAGIC_ALG || algorithm->id != ALG_ID_RNG)
return STATUS_INVALID_HANDLE;
......
......@@ -57,6 +57,14 @@ static void test_BCryptGenRandom(void)
ret = BCryptGenRandom(NULL, buffer, 8, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
ok(memcmp(buffer, buffer + 8, 8), "Expected a random number, got 0\n");
/* Test pseudo handle, which was introduced at the same time as BCryptHash */
if (pBCryptHash)
{
ret = BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, buffer, sizeof(buffer), 0);
ok(ret == STATUS_SUCCESS, "Expected success, got %#lx\n", ret);
}
else win_skip("BCryptGenRandom pseudo handles are not available\n");
}
static void test_BCryptGetFipsAlgorithmMode(void)
......
......@@ -401,6 +401,9 @@ typedef PVOID BCRYPT_HANDLE;
typedef PVOID BCRYPT_HASH_HANDLE;
typedef PVOID BCRYPT_SECRET_HANDLE;
/* Pseudo handles for BCryptGenRandom */
#define BCRYPT_RNG_ALG_HANDLE ((BCRYPT_ALG_HANDLE)0x00000081)
/* Flags for BCryptGenRandom */
#define BCRYPT_RNG_USE_ENTROPY_IN_BUFFER 0x00000001
#define BCRYPT_USE_SYSTEM_PREFERRED_RNG 0x00000002
......
Supports Markdown
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