[PATCH 0/1] MR2228: bcryptprimitives: ProcessRng stub
`ProcessRng` is the only publicly documented function exported by `bcryptprimitives`. This stub simply forwards it to `RtlGenRandom` in `advapi32`. Documentation: https://learn.microsoft.com/en-us/windows/win32/seccng/processprng -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228
From: Chris Denton <chris(a)chrisdenton.dev> ProcessRng is the only publicly documented function exported by bcryptprimitives. This stub simply forwards it to RtlGenRandom in advapi32. Note that there is no documented header file or import lib. Documentation: https://learn.microsoft.com/en-us/windows/win32/seccng/processprng --- configure | 2 + configure.ac | 1 + dlls/bcryptprimitives/Makefile.in | 8 ++++ dlls/bcryptprimitives/bcryptprimitives.spec | 1 + dlls/bcryptprimitives/bcryptprimitives_main.c | 44 +++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 dlls/bcryptprimitives/Makefile.in create mode 100644 dlls/bcryptprimitives/bcryptprimitives.spec create mode 100644 dlls/bcryptprimitives/bcryptprimitives_main.c diff --git a/configure b/configure index 5164b21486f..91a04862341 100755 --- a/configure +++ b/configure @@ -979,6 +979,7 @@ enable_avicap32 enable_avifil32 enable_avrt enable_bcrypt +enable_bcryptprimitives enable_bluetoothapis enable_browseui enable_bthprops_cpl @@ -21004,6 +21005,7 @@ wine_fn_config_makefile dlls/avifile.dll16 enable_win16 wine_fn_config_makefile dlls/avrt enable_avrt wine_fn_config_makefile dlls/bcrypt enable_bcrypt wine_fn_config_makefile dlls/bcrypt/tests enable_tests +wine_fn_config_makefile dlls/bcryptprimitives enable_bcryptprimitives wine_fn_config_makefile dlls/bluetoothapis enable_bluetoothapis wine_fn_config_makefile dlls/browseui enable_browseui wine_fn_config_makefile dlls/browseui/tests enable_tests diff --git a/configure.ac b/configure.ac index 84fadd08853..6fa72b8baf4 100644 --- a/configure.ac +++ b/configure.ac @@ -2372,6 +2372,7 @@ WINE_CONFIG_MAKEFILE(dlls/avifile.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/avrt) WINE_CONFIG_MAKEFILE(dlls/bcrypt) WINE_CONFIG_MAKEFILE(dlls/bcrypt/tests) +WINE_CONFIG_MAKEFILE(dlls/bcryptprimitives) WINE_CONFIG_MAKEFILE(dlls/bluetoothapis) WINE_CONFIG_MAKEFILE(dlls/browseui) WINE_CONFIG_MAKEFILE(dlls/browseui/tests) diff --git a/dlls/bcryptprimitives/Makefile.in b/dlls/bcryptprimitives/Makefile.in new file mode 100644 index 00000000000..bb59597899a --- /dev/null +++ b/dlls/bcryptprimitives/Makefile.in @@ -0,0 +1,8 @@ +MODULE = bcryptprimitives.dll +IMPORTS = advapi32 +IMPORTLIB = bcryptprimitives +UNIXLIB = bcryptprimitives.so +UNIX_CFLAGS = $(GNUTLS_CFLAGS) + +C_SRCS = \ + bcryptprimitives_main.c diff --git a/dlls/bcryptprimitives/bcryptprimitives.spec b/dlls/bcryptprimitives/bcryptprimitives.spec new file mode 100644 index 00000000000..928cb06afcd --- /dev/null +++ b/dlls/bcryptprimitives/bcryptprimitives.spec @@ -0,0 +1 @@ +@ stdcall ProcessPrng(ptr long) diff --git a/dlls/bcryptprimitives/bcryptprimitives_main.c b/dlls/bcryptprimitives/bcryptprimitives_main.c new file mode 100644 index 00000000000..32f4edaa1fb --- /dev/null +++ b/dlls/bcryptprimitives/bcryptprimitives_main.c @@ -0,0 +1,44 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "windows.h" +#include "ntsecapi.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(bcrypt); + +BOOL WINAPI ProcessPrng(PBYTE pbData, SIZE_T cbData) +{ + if (RtlGenRandom(pbData, cbData)) return TRUE; + + /* ProcessRng is documented as never failing. */ + FIXME("RtlGenRandom failed in ProcessPrng.\n"); + return FALSE; +} + +BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(instance); + break; + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2228
Do you have an application that needs this? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24734
Personally yes, though the application is an internal one so I do have other options. However I figured that, while the function is relatively new, the Wine implementation doesn't need much in the way of new code. It's a stable alternative to [`RtlGenRandom`](https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtl...) (which "may be altered or unavailable in subsequent [Windows] versions"). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24736
There's BCryptGenRandom() too, which is supported. It also has a header and an importlib. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24737
Right but on Windows that's not a true fallback. It's more complex and can fail on some systems (e.g. due to a custom system RNG or corrupted registry). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24738
I doubt that RtlGenRandom() will ever go away, but if it does developers should be given enough time to fix their code. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24739
Sure. But new software being written may start using a new function if they no longer need to support older Windows versions. And the deprecation warning is a strong signal for people to do so. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24742
No header or importlib could also be seen as a disincentive to use these functions directly. This dll looks like a crypto provider given exports like GetCipherInterface(), GetHashInterface(), ... it's likely supposed to be used by higher level libraries such as bcrypt. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_24744
This is now needed by chromium (boringssl), see bug https://bugs.winehq.org/show_bug.cgi?id=55181 Can we please revisit this? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_37555
On Tue Jul 4 13:57:27 2023 +0000, Fabian Maurer wrote:
This is now needed by chromium (boringssl), see bug https://bugs.winehq.org/show_bug.cgi?id=55181 Can we please revisit this? Sure.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_37807
I fixed a typo in a comment and rebased while I was at it (there were no conflicts). -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2228#note_37866
participants (4)
-
Chris Denton -
Christopher Denton (@cdenton) -
Fabian Maurer (@DarkShadow44) -
Hans Leidekker (@hans)