Uh oh!
There was an error while loading. Please reload this page.
Use ProcessPrng on Windows - #415
Conversation
5495418 to
5223c3eCompare1d62b41 to
03abb05Compare
briansmith
left a comment
There was a problem hiding this comment.
Besides the lines I commented on, I didn't review the rest.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@briansmith the above are really good point w.r.t. sandboxing. I think that it would be good to have general documentation along the lines of "before starting a sandbox, you should first successfully call
I think that this won't cause issues in some sandboxes provided that |
6825ae5 to
4bfd348CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
josephlr
commented
May 26, 2024
@newpavlov and @briansmith this is now ready for review! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| #[repr(transparent)] | ||
| #[derive(PartialEq, Eq)] | ||
| pub struct BOOL(pub i32); | ||
| pub const TRUE: BOOL = BOOL(1i32); |
There was a problem hiding this comment.
It's unfortunate to have this ugliness without the program that generated it to confirm that it actually created this ugliness. However, I also think it's fine because of how repr(transparent) works so it isn't the end of the world.
There was a problem hiding this comment.
I think this is a good point. For both APIs I didn't directly use the output of windows-bindgen, but instead took that output as a starting point, then deleted lines until I got code that looked decent.
I think that referencing windows-bindgen in the comments at all was misleading, so I changed the comments to just reference the API metadata names directly. Given that, I also changed the BOOL/BOOLEAN types to just be typedefs (which is more honest IMO).
There was a problem hiding this comment.
For reference, here's the full output for running windows-bindgen with the following arguments:
// Bindings generated by `windows-bindgen` 0.56.0#![allow( non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]#[inline]pubunsafefnRtlGenRandom(randombuffer:*mut core::ffi::c_void,randombufferlength:u32,) -> BOOLEAN{
windows_targets::link!("advapi32.dll""system""SystemFunction036"fnRtlGenRandom(randombuffer :*mut core::ffi::c_void, randombufferlength :u32) -> BOOLEAN);RtlGenRandom(randombuffer, randombufferlength)}#[inline]pubunsafefnProcessPrng(pbdata:&mut[u8]) -> BOOL{
windows_targets::link!("bcryptprimitives.dll""system"fnProcessPrng(pbdata :*mutu8, cbdata :usize) -> BOOL);ProcessPrng(
core::mem::transmute(pbdata.as_ptr()),
pbdata.len().try_into().unwrap(),)}#[repr(transparent)]#[derive(PartialEq,Eq)]pubstructBOOL(pubi32);implDefaultforBOOL{fndefault() -> Self{unsafe{ core::mem::zeroed()}}}implCloneforBOOL{fnclone(&self) -> Self{*self}}implCopyforBOOL{}impl core::fmt::DebugforBOOL{fnfmt(&self,f:&mut core::fmt::Formatter<'_>) -> core::fmt::Result{
f.debug_tuple("BOOL").field(&self.0).finish()}}impl windows_core::TypeKindforBOOL{typeTypeKind = windows_core::CopyType;}#[repr(transparent)]#[derive(PartialEq,Eq)]pubstructBOOLEAN(pubu8);implDefaultforBOOLEAN{fndefault() -> Self{unsafe{ core::mem::zeroed()}}}implCloneforBOOLEAN{fnclone(&self) -> Self{*self}}implCopyforBOOLEAN{}impl core::fmt::DebugforBOOLEAN{fnfmt(&self,f:&mut core::fmt::Formatter<'_>) -> core::fmt::Result{
f.debug_tuple("BOOLEAN").field(&self.0).finish()}}impl windows_core::TypeKindforBOOLEAN{typeTypeKind = windows_core::CopyType;}pubconstTRUE:BOOL = BOOL(1i32);Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
This picks up rust-random/getrandom#415. It's still apparently not supported until Windows XP, but seems like it compiles better.
Use [`ProcessPrng`](https://learn.microsoft.com/en-us/windows/win32/seccng/processprng) on Windows 10 and up, and use [`RtlGenRandom`](https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom) on older legacy Windows versions. Don't use [`BCryptGenRandom`](https://learn.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom) due to stability issues. --------- Signed-off-by: Joe Richey <joerichey@google.com>
Tweak the breaking changes section and add entries for rust-random#415, rust-random#440, rust-random#442, rust-random#448, rust-random#504, and rust-random#512.
Use
ProcessPrngon Windows 10 and up, and useRtlGenRandomon older legacy Windows versions. Don't useBCryptGenRandomdue to stability issues.