Repository navigation
Allow calling getrandom with 257-byte buffer - #355
kimhyunkang wants to merge 3 commits into
Conversation
Fixes issue briansmith#353. Now `rand::sysrand::fill` does not loop with fixed 256-byte chunks, but calls `getrandom` to fill the whole buffer. I agree to license my contributions to each file under the terms given at the top of each file I changed.
1 similar comment
briansmith
left a comment
There was a problem hiding this comment.
Sorry, re-reviewing this I noticed that some changes are needed.
|
|
||
| const size_t GFp_sysrand_chunk_max_len = ULONG_MAX; | ||
|
|
||
| int GFp_sysrand_chunk(void *out, size_t requested) { |
There was a problem hiding this comment.
See below. the return type needs to be long and we need to use LONG_MAX and long everywhere here.
| if (syscall(SYS_getrandom, out, requested, 0u) < 0) { | ||
| if (errno == ENOSYS) { | ||
| return -1; | ||
| int r = syscall(SYS_getrandom, out, requested, 0u); |
There was a problem hiding this comment.
I noticed in the similar BoringSSL patch they are using long. And, according to http://man7.org/linux/man-pages/man2/syscall.2.html, long is the right type to use. That means that the function return type needs to be long and the FFI declaration in the Rust code needs to use c::long. I just added c::long in 5c4627a.
There was a problem hiding this comment.
Also, according to http://man7.org/linux/man-pages/man2/getrandom.2.html, the flags argument type is unsigned int. I suggest that we write this:
unsigned int NO_FLAGS = 0;
syscall(..., NO_FLAGS);This way, we are sure there's no funny business going on.
There was a problem hiding this comment.
I forgot that C's long is different on Windows than on other platforms. I pushed a fix for it: dcba8a8
| #[cfg(any(target_os = "linux", windows))] | ||
| extern { | ||
| static GFp_sysrand_chunk_max_len: c::size_t; | ||
| fn GFp_sysrand_chunk(buf: *mut u8, len: c::size_t) -> c::int; |
|
@briansmith : I just updated the return types from |
|
Thanks for doing this! I merged this as 828e20f. |
Fixes issue #353.
Now
rand::sysrand::filldoes not loop with fixed 256-byte chunks,but calls
getrandomto fill the whole buffer.I agree to license my contributions to each file under the terms given
at the top of each file I changed.