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

Windows: RtlGenRandom vs BCryptGenRandom #65

Open
newpavlov opened this issue Jul 26, 2019 · 5 comments
Open

Windows: RtlGenRandom vs BCryptGenRandom #65

newpavlov opened this issue Jul 26, 2019 · 5 comments
Labels

Comments

@newpavlov
Copy link
Collaborator

@newpavlov newpavlov commented Jul 26, 2019

IIUC both functions use the same algorithm under the hood (also see this). The main difference is that BCryptGenRandom will not work on Windows XP, but otherwise it looks like BCryptGenRandom should be preferred. IIRC Rust explicitly does not support Windows XP anymore, so it should not matter.

@chouquette
Can you help here? In rust-lang/rust#60260 you have used BCryptGenRandom for UWP targets and left RtlGenRandom for non-UWP targets. Is there a reason for that?

cc @GabrielMajeri

@chouquette

This comment has been minimized.

Copy link

@chouquette chouquette commented Jul 26, 2019

Hi,

Mostly because I was asked to :) rust-lang/rust#60260 (comment)

My understanding is that Microsoft advises to use CryptGenRandom over RtlGenRandom, but CryptGenRandom is deprecated and the "next generation cryptography API" should be used instead, and BCryptGenRandom is part of that API, so if you have the choice, BcryptGenRandom is probably to be favored, however it seems in the context of Rust, there are some historical reasons for keeping RtlGenRandom

In the case of UWP the choice is easy, you can't use RtlGenRandom

@ollie27

This comment has been minimized.

Copy link

@ollie27 ollie27 commented Jul 26, 2019

I believe XP is still technically supported by std (https://forge.rust-lang.org/platform-support.html#tier-3) and that's why it needs both implementations. When XP support is officially dropped then the RtlGenRandom version can be removed and BCryptGenRandom can be used for all Windows targets. I suggest that getrandom just copies std for now.

@newpavlov

This comment has been minimized.

Copy link
Collaborator Author

@newpavlov newpavlov commented Jul 26, 2019

Ah, indeed. In that case I think we can use RtlGenRandom fallback only for XP targets, and BCryptGenRandom for all other Windows targets.

UPD: Never mind, we can't distinguish between XP and later versions by using only target triplet.

Relevant discussion: https://internals.rust-lang.org/t/8745

@newpavlov

This comment has been minimized.

Copy link
Collaborator Author

@newpavlov newpavlov commented Jul 28, 2019

Relevant issue: openssl/openssl#8644

So we will have to wait for dropping of Windows XP (and hopefully Vista) from the list of supported Rust targets, until then we will have to keep using RtlGenRandom.

@newpavlov newpavlov added the postponed label Jul 28, 2019
@alexcrichton

This comment has been minimized.

Copy link

@alexcrichton alexcrichton commented Jul 29, 2019

I'd recommend using git blame and doing some digging to learn about the rationale for the usage in Rust's standard library. Doing that, for example, leads to rust-lang/rust#45370 which has a lot more information about why things are the way they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.