Skip to content

Conversation

@xoloki
Copy link
Contributor

@xoloki xoloki commented May 16, 2016

This PR removes all of the dangerous Windows entropy gathering routines in favor of standard CryptGenRandom calls, as was discussed in the "Improving OpenSSL default RNG" thread on openssl-dev. This fixes common, repeatable crashes that happen when running openssl under the VS debugger.

@OscarLinden OscarLinden mentioned this pull request May 16, 2016
@xoloki
Copy link
Contributor Author

xoloki commented May 16, 2016

nmake test passes

@xoloki
Copy link
Contributor Author

xoloki commented May 16, 2016

@mattcaswell is this PR okay?

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering whether we should retain RAND_event(), and just have it call RAND_poll() (ignoring all params), and return RAND_status()? i.e. for backwards compat.

Copy link
Contributor

Choose a reason for hiding this comment

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

Via OPENSSL_API_COMPAT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a good time to make a clean break. But keeping them as deprecated would be a reasonable option.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think we keep them but deprecated (using the OPENSSL_API_COMPAT macro as @richsalz suggests), and all they do is call RAND_poll/RAND_status.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So

if OPENSSL_API_COMPAT < 0x10100000L

?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. And wrap the header file declarations in DEPRECATEDIN_1_1_0()

Copy link
Member

Choose a reason for hiding this comment

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

Oh...which also means the documentation needs to change too :-)

Copy link

@gvanem gvanem Jul 27, 2020

Choose a reason for hiding this comment

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

Oh...which also means the documentation needs to change too :-)

I noted that too here:

additionally link your application with WS2_32.LIB, GDI32.LIB,

This change means gdi32.dll is no longer needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: See also this thread on openssl-users.

@mattcaswell
Copy link
Member

Yes, this PR looks a lot better. I just have a few minor comments.

@mattcaswell
Copy link
Member

For the sake of maintaining the history, this PR replaces #512.

@mattcaswell mattcaswell added this to the 1.1.0 milestone May 16, 2016
@xoloki
Copy link
Contributor Author

xoloki commented May 16, 2016

Ok, functions added back as deprecated in header/source/docs. nmake test still passes.

Copy link
Member

Choose a reason for hiding this comment

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

No, it returns RAND_status().

@mattcaswell
Copy link
Member

Just done a test build and everything looks good. One final thing I spotted. libcrypto.num needs updating to mark RAND_event() and RAND_screen() as DEPRECATEDIN_1_1_0

@xoloki
Copy link
Contributor Author

xoloki commented May 16, 2016

Done @mattcaswell

@mattcaswell
Copy link
Member

+1

@mattcaswell
Copy link
Member

Needs a second team review now.

@matbech
Copy link
Contributor

matbech commented May 27, 2016

For reference, the same issue has been raised in Go:
golang/go#15589

Firefox has asked Microsoft for clarification a while ago:
https://bugzilla.mozilla.org/show_bug.cgi?id=504270

If the argument is not to use "deprecated" functions, at least consider using BCryptGenRandom (with BCRYPT_USE_SYSTEM_PREFERRED_RNG) on Windows 7 and higher as CryptoAPI itself is a legacy API (superseded by NCrypt/BCrypt).

Also for reference, the following projects have decided against the CryptoAPI:

  • rand in all Microsoft CRT implementations (RtlGenRandom)
  • .NET (BCryptGenRandom)
  • Chromium (RtlGenRandom)
  • Go (pending patch to use RtlGenRandom)
  • Firefox (RtlGenRandom)

It's clear that CryptGenRandom has an unnecessary overhead (and dependency) which can be avoided by using either BCryptGenRandom or RtlGenRandom.

@xoloki
Copy link
Contributor Author

xoloki commented May 27, 2016

Another part of this PR was removing all the #ifdef code for various windows platforms. I don't think adding another for Win7 and greater is a good fit for this change.

CryptoAPI may be legacy, but it's not deprecated, so I think it's the appropriate choice here. We're only grabbing 32 bytes from it anyway. If this was being called all the time then tiny changes in performance would be worth increasing code complexity. But I just don't see the tradeoff here.

@richsalz
Copy link
Contributor

Agree with @xoloki. It's part of the official API, this cleans up things a great deal, and is portable across all Windows platforms. Perhaps in the next release, when we drop XP and other old platforms, we can look at BCryptoGenRandom.

Also, doesn't this address a couple of open RT tickets?

+1

@t-j-h
Copy link
Member

t-j-h commented May 29, 2016

+1 in its current form ...

@richsalz
Copy link
Contributor

So, want me to merge?

levitte pushed a commit that referenced this pull request May 29, 2016
… calling conventions

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
levitte pushed a commit that referenced this pull request May 29, 2016
Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tim Hudson <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from #1079)
@richsalz
Copy link
Contributor

thanks for your efforts! merged!!

@richsalz richsalz closed this May 29, 2016
@xoloki
Copy link
Contributor Author

xoloki commented May 29, 2016

Thanks so much @mattcaswell, @levitte, and @richsalz!

@viniciusgati
Copy link

any chance to have this causing problems on linux?

@mattcaswell
Copy link
Member

This is all in code that doesn't even get compiled on linux, so there should be no impacts.

xiaoyinl added a commit to xiaoyinl/openssl that referenced this pull request Jul 21, 2017
GlobalMemoryStatus is deprecated and may return incorrect data (https://msdn.microsoft.com/en-us/library/windows/desktop/aa366586(v=vs.85).aspx). Since we already use `BCryptGenRandom` or `BCryptGenRandom`, I guess we can remove memory status and process ID as sources of randomness? openssl#1079 removed a lot of code that manually gathers entropy. I think based on the same logic, we can remove these two as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.