about summary refs log tree commit diff
path: root/src/libstd/sys/unix/rand.rs
AgeCommit message (Collapse)AuthorLines
2020-03-21Use getentropy(2) on macoshatoo-0/+37
2019-11-29Format libstd/sys with rustfmtDavid Tolnay-30/+33
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd/sys *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd/sys -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd/sys outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of the files. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-11-04Use any() in code shared between FreeBSD and NetBSDnia-1/+1
2019-11-04Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.nia-1/+2
This system call is present on all supported NetBSD versions and provides an endless stream of non-blocking random data from the kernel's ChaCha20-based CSPRNG. It doesn't require a file descriptor to be opened. The system call is documented here (under kern.arandom): https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0 And defined here: https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273 The semantics are the same as FreeBSD so reading 256 bytes per call is fine. Similar change for getrandom crate: rust-random/getrandom#115
2019-10-22Apply clippy::needless_return suggestionsMateusz MikuĊ‚a-1/+1
2019-08-06redox: convert to target_family unixJeremy Soller-1/+14
2019-05-01Fall back to `/dev/urandom` on `EPERM` for `getrandom`Tobias Bucher-1/+6
This can happen because of seccomp or some VMs. Fixes #52609.
2019-04-16Add a comment explaining why SecRandomCopyBytes is not used on MacOSEd Barnard-0/+7
2019-02-28libstd => 2018Taiki Endo-14/+10
2018-12-25Remove licensesMark Rousskov-10/+0
2018-09-02Fix an endless loop when `getrandom` is not availableTobias Bucher-0/+1
2018-08-29Don't leak the file descriptor in `rand`Tobias Bucher-44/+11
2018-08-26Reduce number of syscalls in `rand`Tobias Bucher-39/+57
In case that it is statically known that the OS doesn't support `getrandom` (non-Linux) or becomes clear at runtime that `getrandom` isn't available (`ENOSYS`), the opened fd ("/dev/urandom") isn't closed after the function, so that future calls can reuse it. This saves repeated `open`/`close` system calls at the cost of one permanently open fd. Additionally, this skips the initial zero-length `getrandom` call and directly hands the user buffer to the operating system, saving one `getrandom` syscall.
2018-06-27[fuchsia] Update zx_cprng_draw to target semanticsAdam Barth-26/+2
This change is the final step in improving the semantics of zx_cprng_draw. Now the syscall always generates the requested number of bytes. If the syscall would have failed to generate the requested number of bytes, the syscall either terminates the entire operating system or terminates the calling process, depending on whether the error is a result of the kernel misbehaving or the userspace program misbehaving.
2018-06-19Update zx_cprng_draw_new on FuchsiaAdam Barth-4/+3
Fuchsia is changing the semantics for zx_cprng_draw and zx_cprng_draw_new is a temporary name for the new semantics.
2017-11-09Use getrandom syscall for all Linux and Android targets.Marco A L Barbosa-50/+5
2017-11-08std: Remove `rand` crate and moduleAlex Crichton-215/+74
This commit removes the `rand` crate from the standard library facade as well as the `__rand` module in the standard library. Neither of these were used in any meaningful way in the standard library itself. The only need for randomness in libstd is to initialize the thread-local keys of a `HashMap`, and that unconditionally used `OsRng` defined in the standard library anyway. The cruft of the `rand` crate and the extra `rand` support in the standard library makes libstd slightly more difficult to port to new platforms, namely WebAssembly which doesn't have any randomness at all (without interfacing with JS). The purpose of this commit is to clarify and streamline randomness in libstd, focusing on how it's only required in one location, hashmap seeds. Note that the `rand` crate out of tree has almost always been a drop-in replacement for the `rand` crate in-tree, so any usage (accidental or purposeful) of the crate in-tree should switch to the `rand` crate on crates.io. This then also has the further benefit of avoiding duplication (mostly) between the two crates!
2017-10-31Fix NR_GETRANDOM for linux x32Marco A L Barbosa-1/+3
2017-09-24The Magenta kernel is now called Zircon.P.Y. Laligand-4/+4
2017-08-01Fixed all unnecessary muts in language coreIsaac van Bakel-2/+2
2017-02-06std: Remove cfg(cargobuild) annotationsAlex Crichton-4/+0
These are all now no longer needed that we've only got rustbuild in tree.
2016-11-04std: Track change to cprng syscall signature (Fuchsia)Raph Levien-8/+20
The mx_cprng_draw syscall has changed signature to separate the status and size return values, rather than multiplexing them into a single value with errors interpreted as a negative value. This patch tracks that change.
2016-10-24Add support for kernel randomness for FuchsiaRaph Levien-1/+53
Wire up cprng syscall as provider for rand::os::OsRng on Fuchsia.
2016-10-08Use less `size_t` casts in libstd since it's now defined as `usize`Tobias Bucher-3/+3
2016-09-09Add s390x supportUlrich Weigand-4/+10
This adds support for building the Rust compiler and standard library for s390x-linux, allowing a full cross-bootstrap sequence to complete. This includes: - Makefile/configure changes to allow native s390x builds - Full Rust compiler support for the s390x C ABI (only the non-vector ABI is supported at this point) - Port of the standard library to s390x - Update the liblibc submodule to a version including s390x support - Testsuite fixes to allow clean "make check" on s390x Caveats: - Resets base cpu to "z10" to bring support in sync with the default behaviour of other compilers on the platforms. (Usually, upstream supports all older processors; a distribution build may then chose to require a more recent base version.) (Also, using zEC12 causes failures in the valgrind tests since valgrind doesn't fully support this CPU yet.) - z13 vector ABI is not yet supported. To ensure compatible code generation, the -vector feature is passed to LLVM. Note that this means that even when compiling for z13, no vector instructions will be used. In the future, support for the vector ABI should be added (this will require common code support for different ABIs that need different data_layout strings on the same platform). - Two test cases are (temporarily) ignored on s390x to allow passing the test suite. The underlying issues still need to be fixed: * debuginfo/simd.rs fails because of incorrect debug information. This seems to be a LLVM bug (also seen with C code). * run-pass/union/union-basic.rs simply seems to be incorrect for all big-endian platforms. Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
2016-08-21Use the kernel arc4rand for FreeBSD OsRng.Aaron Gallagher-1/+52
This means that /dev/urandom doesn't have to be opened.
2016-08-21Reduce duplication in std::sys::unix::rand.Aaron Gallagher-29/+25
There were a bunch of more-of-less the same few lines for doing a fill_bytes+transmute, and I didn't want to copy-paste it yet again.
2016-04-20rand: add comments about getrandom() fallbackDoug Goldstein-0/+8
Add some comments so that people know why we are performing a fallback from getrandom() and what that fallback aims to achieve. Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2016-04-19rand: don't block before random pool is initializedDoug Goldstein-1/+8
If we attempt a read with getrandom() on Linux the syscall can block before the random pool is initialized unless the GRND_NONBLOCK flag is passed. This flag causes getrandom() to instead return EAGAIN while the pool is uninitialized. To avoid downstream users of crate or std functionality that have no ability to avoid this blocking behavior this change causes Rust to read bytes from /dev/urandom while getrandom() would block and once getrandom() is available to use that. Fixes #32953. Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2016-03-22try! -> ?Jorge Aparicio-1/+1
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
2016-02-17std: restructure rand os code into sys modulesSean McArthur-0/+273