RFC - bcrypt: Semi-stub BCryptGenRandom

Bruno Jesus 00cpxxx at gmail.com
Sun Feb 2 20:18:34 CST 2014


Hi, I'm looking for comments related to the attached patch.

Is it valid to use advpi32? It seems to be the most easy way to
generate random numbers.

If not valid, what other ways are there to generate random numbers?

If anyone would like to compile this patch please also get
http://source.winehq.org/patches/data/102143

Thanks in advance,
Bruno
-------------- next part --------------
diff --git a/dlls/bcrypt/Makefile.in b/dlls/bcrypt/Makefile.in
index f9aacec..d0549f7 100644
--- a/dlls/bcrypt/Makefile.in
+++ b/dlls/bcrypt/Makefile.in
@@ -1,4 +1,5 @@
 MODULE    = bcrypt.dll
+IMPORTLIB = advapi32.dll
 
 C_SRCS = \
 	bcrypt_main.c
diff --git a/dlls/bcrypt/bcrypt.spec b/dlls/bcrypt/bcrypt.spec
index e1ffb8a..87623f8 100644
--- a/dlls/bcrypt/bcrypt.spec
+++ b/dlls/bcrypt/bcrypt.spec
@@ -24,7 +24,7 @@
 @ stub BCryptFinalizeKeyPair
 @ stub BCryptFinishHash
 @ stub BCryptFreeBuffer
-@ stub BCryptGenRandom
+@ stdcall BCryptGenRandom(ptr ptr long long)
 @ stub BCryptGenerateKeyPair
 @ stub BCryptGenerateSymmetricKey
 @ stub BCryptGetFipsAlgorithmMode
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 441b3ef..d43a001 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -23,6 +23,7 @@
 
 #include "winbase.h"
 #include "bcrypt.h"
+#include "ntsecapi.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(bcrypt);
 
@@ -50,3 +51,25 @@ NTSTATUS WINAPI BCryptEnumAlgorithms(ULONG dwAlgOperations, ULONG *pAlgCount,
 
     return ERROR_CALL_NOT_IMPLEMENTED;
 }
+
+NTSTATUS WINAPI BCryptGenRandom(ULONG *hAlgorithm, UCHAR *pbBuffer, ULONG cbBuffer,
+                                ULONG dwFlags)
+{
+    FIXME("%p, %p, %u, %08x - semi-stub\n", hAlgorithm, pbBuffer, cbBuffer, dwFlags);
+
+    if(dwFlags & BCRYPT_RNG_USE_ENTROPY_IN_BUFFER)
+    {
+        FIXME("unsupported flag BCRYPT_RNG_USE_ENTROPY_IN_BUFFER\n");
+    }
+
+    if(dwFlags & BCRYPT_USE_SYSTEM_PREFERRED_RNG)
+    {
+        if(hAlgorithm)
+            return ERROR_INVALID_HANDLE;
+
+        if(RtlGenRandom(pbBuffer, cbBuffer))
+            return ERROR_SUCCESS;
+    }
+    return ERROR_CALL_NOT_IMPLEMENTED;
+}
+


More information about the wine-devel mailing list