bcrypt: Add semi-stub implementation of BCryptGenRandom
Bruno Jesus
00cpxxx at gmail.com
Wed Feb 5 16:44:56 CST 2014
Properly fix the use case of bug https://bugs.winehq.org/show_bug.cgi?id=34921
-------------- next part --------------
diff --git a/dlls/bcrypt/Makefile.in b/dlls/bcrypt/Makefile.in
index f9aacec..6f39a49 100644
--- a/dlls/bcrypt/Makefile.in
+++ b/dlls/bcrypt/Makefile.in
@@ -1,4 +1,5 @@
MODULE = bcrypt.dll
+IMPORTLIB = advapi32
C_SRCS = \
bcrypt_main.c
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 02d0a7d..943f85f 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -25,6 +25,7 @@
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
+#include "ntsecapi.h"
#include "bcrypt.h"
#include "wine/debug.h"
@@ -57,7 +58,21 @@ NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount,
NTSTATUS WINAPI BCryptGenRandom(BCRYPT_ALG_HANDLE algorithm, UCHAR *buffer, ULONG count, ULONG flags)
{
- FIXME("%p, %p, %u, %08x - stub\n", algorithm, buffer, count, flags);
+ TRACE("%p, %p, %u, %08x - semi-stub\n", algorithm, buffer, count, flags);
+ if(flags & BCRYPT_RNG_USE_ENTROPY_IN_BUFFER)
+ {
+ FIXME("unsupported flag BCRYPT_RNG_USE_ENTROPY_IN_BUFFER\n");
+ }
+
+ if(flags & BCRYPT_USE_SYSTEM_PREFERRED_RNG)
+ {
+ if(RtlGenRandom(buffer, count)) return STATUS_SUCCESS;
+ }
+ else if(!algorithm) return STATUS_INVALID_HANDLE;
+
+ if(!buffer || !count) return STATUS_INVALID_PARAMETER;
+
+ FIXME("called with unsupported parameters, returning error\n");
return STATUS_NOT_IMPLEMENTED;
}
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c
index 1d18634..3307ceb 100644
--- a/dlls/bcrypt/tests/bcrypt.c
+++ b/dlls/bcrypt/tests/bcrypt.c
@@ -46,6 +46,7 @@ static void test_BCryptGenRandom(void)
{
NTSTATUS ret;
UCHAR buffer[256];
+ DWORD *rnd = (DWORD*) buffer;
if (!pBCryptGenRandom)
{
@@ -53,7 +54,6 @@ static void test_BCryptGenRandom(void)
return;
}
- todo_wine {
ret = pBCryptGenRandom(NULL, NULL, 0, 0);
ok(ret == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got 0x%x\n", ret);
ret = pBCryptGenRandom(NULL, buffer, 0, 0);
@@ -64,7 +64,14 @@ static void test_BCryptGenRandom(void)
ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
ret = pBCryptGenRandom(NULL, NULL, sizeof(buffer), BCRYPT_USE_SYSTEM_PREFERRED_RNG);
ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
- }
+
+ /* Test random number generation - It's impossible for a sane RNG to return 8 zeros */
+ rnd[0] = 0;
+ rnd[1] = 0;
+ ret = pBCryptGenRandom(NULL, buffer, sizeof(DWORD) * 2, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
+ ok(ret == STATUS_SUCCESS, "Expected success, got 0x%x\n", ret);
+ ok(rnd[0] || rnd[1], "Expected a random number, got 0\n");
+ trace("BCryptGenRandom : %08X%08X\n", rnd[0], rnd[1]);
}
START_TEST(bcrypt)
More information about the wine-patches
mailing list