Обсуждение: [PATCH] Windows port add support to BCryptGenRandom

Поиск
Список
Период
Сортировка

[PATCH] Windows port add support to BCryptGenRandom

От
Ranier Vilela
Дата:
Hi,
According to microsoft documentation at:
https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom
The function CryptGenRandom is deprecated, and may can be removed in future release.
This patch add support to use BCryptGenRandom.

BCryptGenRandom apparently works without having to set up an environment before calling.
The drawback, its change causes need to link to bcrypt.lib.

regards,
Ranier Vilela
Вложения

RE: [PATCH] Windows port add support to BCryptGenRandom

От
Ranier Vilela
Дата:
Forget Mkvcbuild_v1.patch

regards,
Ranier Vilela
Вложения

Re: [PATCH] Windows port add support to BCryptGenRandom

От
Michael Paquier
Дата:
On Mon, Dec 16, 2019 at 09:18:10PM +0000, Ranier Vilela wrote:
> According to microsoft documentation at:
> https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cryptgenrandom
> The function CryptGenRandom is deprecated, and may can be removed in future release.
> This patch add support to use BCryptGenRandom.

+#if defined(_MSC_VER) && _MSC_VER >= 1900 \
+     && defined(MIN_WINNT) && MIN_WINNT >= 0x0600
+#define USE_WIN32_BCRYPTGENRANDOM
[...]
+       $postgres->AddLibrary('bcrypt.lib') if ($vsVersion > '12.00');

And looking at this page, it is said that the minimum version
supported by this function is Windows 2008:
https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom

Now, your changes in MkvcBuild.pm and the backend code assume that
we need to include bcrypt.lib since MSVC 2015 (at least version
14.00 or _MSC_VER >= 1900.  Do you have a reference about when this
has been introduced in VS?  The MS docs don't seem to hold a hint
about that..
--
Michael

Вложения

RE: [PATCH] Windows port add support to BCryptGenRandom

От
Ranier Vilela
Дата:
De: Michael Paquier
Enviadas: Terça-feira, 17 de Dezembro de 2019 03:43
Para: Ranier Vilela
Cc: pgsql-hackers@lists.postgresql.org
Assunto: Re: [PATCH] Windows port add support to BCryptGenRandom

>And looking at this page, it is said that the minimum version
>supported by this function is Windows 2008:
>https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom

>Now, your changes in MkvcBuild.pm and the backend code assume that
>we need to include bcrypt.lib since MSVC 2015 (at least version
>14.00 or _MSC_VER >= 1900.  Do you have a reference about when this
>has been introduced in VS?  The MS docs don't seem to hold a hint
>about that..
Sorry Perl I understand a little bit.
Windows Vista I believe.
is the primary font and have more information.

Best regards,
Ranier Vilela

Re: [PATCH] Windows port add support to BCryptGenRandom

От
Michael Paquier
Дата:
On Tue, Dec 17, 2019 at 03:57:56AM +0000, Ranier Vilela wrote:
> Windows Vista I believe.
> https://github.com/openssl/openssl/blob/master/crypto/rand/rand_win.c
> is the primary font and have more information.

So, this basically matches with what the MS documents tell us, and my
impression: this API is available down to at least MSVC 2008, which is
much more than what we support on HEAD where one can use MSVC 2013 and
newer versions.  Note that for the minimal platforms supported our
documentation cite Windows Server 2008 R2 SP1 and Windows 7, implying
_WIN32_WINNT >= 0x0600.

In short, this means two things:
- Your patch, as presented, is wrong.
- There is no need to make conditional the use of BCryptGenRandom.
--
Michael

Вложения

RE: [PATCH] Windows port add support to BCryptGenRandom

От
Ranier Vilela
Дата:
De: Michael Paquier
Enviadas: Terça-feira, 17 de Dezembro de 2019 04:34
>So, this basically matches with what the MS documents tell us, and my
>impression: this API is available down to at least MSVC 2008, which is
>much more than what we support on HEAD where one can use MSVC 2013 and
>newer versions.  Note that for the minimal platforms supported our
>documentation cite Windows Server 2008 R2 SP1 and Windows 7, implying
>_WIN32_WINNT >= 0x0600.
As concern [1], at src/include/port/win32.h, the comments still references Windows XP and claims about possible MingW break.

>In short, this means two things:
>- Your patch, as presented, is wrong.
Well, I try correct him to target MSVC 2013.

>There is no need to make conditional the use of BCryptGenRandom.
If legacy Windows Crypto API still remain, and the patch can broken MingW, I believe as necessary conditional use of BCryptGenRandom.

Best regards,
Ranier Vilela

Re: [PATCH] Windows port add support to BCryptGenRandom

От
Michael Paquier
Дата:
On Tue, Dec 17, 2019 at 02:20:20PM +0000, Ranier Vilela wrote:
> As concern [1], at src/include/port/win32.h, the comments still
> references Windows XP and claims about possible MingW break.

This looks like a leftover of d9dd406, which has made the code to
require C99.  As we don't support compilation with Windows XP and
require Windows 7, we should be able to remove all the dance around
MIN_WINNT in win32.h, don't you think?
--
Michael

Вложения

Re: [PATCH] Windows port add support to BCryptGenRandom

От
Juan José Santamaría Flecha
Дата:


On Wed, Dec 18, 2019 at 3:20 AM Michael Paquier <michael@paquier.xyz> wrote:
On Tue, Dec 17, 2019 at 02:20:20PM +0000, Ranier Vilela wrote:
> As concern [1], at src/include/port/win32.h, the comments still
> references Windows XP and claims about possible MingW break.

This looks like a leftover of d9dd406, which has made the code to
require C99.  As we don't support compilation with Windows XP and
require Windows 7, we should be able to remove all the dance around
MIN_WINNT in win32.h, don't you think?


+1, there is a reference in [1] about that is possible to build PostgreSQL using the GNU compiler tools for older versions of Windows, that should be also updated.


Regards,

Juan José Santamaría Flecha

RE: [PATCH] Windows port add support to BCryptGenRandom

От
Ranier Vilela
Дата:
De: Michael Paquier
Enviadas: Quarta-feira, 18 de Dezembro de 2019 02:19
>This looks like a leftover of d9dd406, which has made the code to
>require C99.  As we don't support compilation with Windows XP and
>require Windows 7, we should be able to remove all the dance around
>MIN_WINNT in win32.h, don't you think?
It would be a good thing since there is no support for these old systems.
And whenever there is a patch that touches windows, someone could complain that it would be breaking something.

Can You help improve the support of BCryptoGenRandom?
I still have doubts about:
  1. This break MingW?
  2. Legacy API, have to stay?
  3. Perl support, pgbench specifically.

If legacy API, have to stay, I have no doubt that it needs to be guarded by conditionals.


Best regards,

Ranier Vilela


Re: [PATCH] Windows port add support to BCryptGenRandom

От
Michael Paquier
Дата:
On Wed, Dec 18, 2019 at 09:52:07AM +0100, Juan José Santamaría Flecha wrote:
> +1, there is a reference in [1] about that is possible to build PostgreSQL
> using the GNU compiler tools for older versions of Windows, that should be
> also updated.

There is actually a little bit more which could be cleaned up.  I am
going to begin a new thread on that after finishing looking.

> [1] https://www.postgresql.org/docs/current/install-windows.html

Are you referring to the part about cygwin?  We could remove all the
paragraph..
--
Michael

Вложения