Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CryptGenRandom is deprecated #14089

Closed
wants to merge 1 commit into from

Conversation

fingera
Copy link
Contributor

@fingera fingera commented Aug 28, 2018

src/random.cpp Outdated
@@ -9,8 +9,16 @@
#include <support/cleanse.h>
#ifdef WIN32
#include <compat.h> // for Windows API
#include <wincrypt.h>
#if defined(_MSC_VER) && defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0601
#include <bcrypt.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so with this, it will still use the deprecated function with mingw?
(which is used for the distributed binaries)

src/random.cpp Outdated
#include <wincrypt.h>
#if defined(_MSC_VER) && defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0601
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add this into build_msvc/*/*.vcxproj and configure.ac instead of adding random library into source code. Once you update configure.ac, the #if defined(_MSC_VER)..#endif thing could be removed.

src/random.cpp Outdated
@@ -9,8 +9,16 @@
#include <support/cleanse.h>
#ifdef WIN32
#include <compat.h> // for Windows API
#include <wincrypt.h>
#if defined(_MSC_VER) && defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0601
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking _WIN32_WINNT is not necessary. The min version required to run Bitcoin Core is Vista which is the same as the required min version of BCryptGenRandom

@fingera fingera force-pushed the 2-crypto-api-deprecated branch 3 times, most recently from a235c05 to b3142a4 Compare August 29, 2018 03:52
@fingera
Copy link
Contributor Author

fingera commented Aug 29, 2018

thankyou, now the minimum system is windows vista

@ken2812221
Copy link
Contributor

Concept ACK

@laanwj
Copy link
Member

laanwj commented Aug 29, 2018

utACK on superficial code changes

however, as random generation is critical to wallet security, someone with actual knowledge of windows random APIs should review this

@NicolasDorier
Copy link
Contributor

I would be inclined to NACK, new version of .NET still depend on advapi32.dll CryptGenRandom for secure RNG. I would be more confident to use when microsoft eat their dog food.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Aug 29, 2018

@fingera
Copy link
Contributor Author

fingera commented Aug 30, 2018

Windows Vista: The random number generator is based on the hash-based random number generator specified in the FIPS 186-2 standard.
Windows 8: Beginning with Windows 8, the RNG algorithm supports FIPS 186-3. Keys less than or equal to 1024 bits adhere to FIPS 186-2 and keys greater than 1024 to FIPS 186-3.
https://docs.microsoft.com/zh-cn/windows/desktop/SecCNG/cng-algorithm-identifiers#BCRYPT_RNG_ALGORITHM

ok, maybe switch to bcrypt after many years?

@luke-jr
Copy link
Member

luke-jr commented Aug 30, 2018

Could do both?

@fingera
Copy link
Contributor Author

fingera commented Aug 31, 2018

bitcoin random source:
// First source: OpenSSL's RNG
// Second source: OS RNG
// Third source: HW RNG, if available.

OpenSSL's RNG already append CryptGenRandom(Compile Target < Win7)
OS RNG improve it, so OS RNG use new BCryptGenRandom :)

@sipa
Copy link
Member

sipa commented Aug 31, 2018

We will in the near future probably remove OpenSSL as a randomness source.

@fingera
Copy link
Contributor Author

fingera commented Aug 31, 2018

Remove randomness source must be very carefull.
Can I do it?
What to do now?

@sipa
Copy link
Member

sipa commented Aug 31, 2018

No, we're still relying on some of its features that need to be implemented differently first.

I'm just pointing out that OpenSSL using some API already is not a reason to not also use it ourselves.

@fingera
Copy link
Contributor Author

fingera commented Aug 31, 2018

Add both os source now? Or wait for Microsoft's new API to accept more tests

@laanwj
Copy link
Member

laanwj commented Aug 31, 2018

I'm closing this for now.
We can do this at some point in the future, but I agree with @NicolasDorier that it's not relevant now.

@laanwj laanwj closed this Aug 31, 2018
@fingera
Copy link
Contributor Author

fingera commented Aug 31, 2018

ok, please read 14116

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants