Commit Graph

337 Commits

Author SHA1 Message Date
Joe Richey b04bd03e14 Explicitly use windows-2022
Currently this is the same as `windows-latest` so this is not a
functional change.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-31 00:09:06 -07:00
Joe Richey 9d4a91f9a1 Remove workaround not needed on Ubuntu 22.04
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-31 00:09:06 -07:00
Joe Richey 941c2fff69 Update tests to run on Ubuntu 22.04 (instead of 20.04)
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-31 00:09:06 -07:00
Joe Richey 5ddec2a8f4 Check OS using runner.os instead of matrix.os
This makes it easier to later update the OS verions

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-31 00:09:06 -07:00
Joe Richey 8e4ecdb72f Use "host" instead of "target" in Web Tests
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-31 00:08:59 -07:00
Joseph Richey 5a4a8eafe5 Fix iOS simulator CI (#323)
The upgrade to macOS 12 broke this iOS simulator CI (as support for the
iPhone 7 was dropped I think).

We should have a follow up PR to see if we can just test against a more
recent iPhone.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-30 20:31:26 -07:00
Jared Ramon Elizan 8b36b3e634 README.md (#322)
fixed typo
2022-10-30 17:13:52 -07:00
Joseph Richey c93c2603f0 Merge pull request #321 from rust-random/webtest
CI: Add Web Tests for Edge on Windows
2022-10-26 01:23:35 -07:00
Joe Richey c3d9797a0b Just Pin Versions for compiled downloads
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-25 23:44:36 -07:00
Joe Richey 03f6688195 Cleanup other binary download steps
Be consistent and always use wget

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-25 23:31:56 -07:00
Joe Richey f84a061151 Add additional Web Tests
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-25 23:05:32 -07:00
Joseph Richey 8e44d13ebf Merge pull request #317 from thomcc/tvos-watchos
Add tvOS and watchOS support, identical to iOS support
2022-10-25 02:50:29 -07:00
Thom Chiovoloni e32ea822c3 Add tvOS and watchOS to CI 2022-10-24 23:24:56 -07:00
Thom Chiovoloni e6ed8e1a55 Add tvOS and watchOS support, identical to iOS support 2022-10-24 18:21:50 -07:00
Joseph Richey 2aabb63d2c Merge pull request #316 from rust-random/ci
CI: Run iOS targets and other improvements
2022-10-24 12:22:23 -07:00
Joe Richey 4917673cd2 Break up Tier 3 builds
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-24 01:56:17 -07:00
Joe Richey b35add2bb7 Uptade to Swatinem/rust-cache@v2
Also move the cache step to be right before we start running cargo
commands.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-24 01:56:17 -07:00
Joe Richey a91ad48d8c Update to actions/checkout@v3
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-24 01:56:17 -07:00
Joe Richey b1da11b850 Run iOS Simulator Tests
This builds, links, and runs the tests on `x86_64-apple-ios` using
[`dinghy`](https://github.com/sonos/dinghy). It moves the targets
which only Build/Link to their own job.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-24 01:56:10 -07:00
Joe Richey 14b461fa39 Make job names consistent
This makes it easier to tell on which targets we:
  - Build
  - Link
  - Run

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-24 01:50:03 -07:00
Joe Richey 762c95dd7a Move from actions-rs/toolchain to dtolnay/rust-toolchain
The current action we are using is unmantained:
https://github.com/actions-rs/toolchain/issues/216

This replacement is faster, smaller, and more cachable.

We can also completely remove the toolchain step when testing with
cross, as cross handles configuration of its own toolchain.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 21:32:21 -07:00
Joseph Richey 52a4c3cbad Remove buffer zeroing from Node.js implementation (#315)
We can use
[`Uint8Array::view_mut_raw`](https://rustwasm.github.io/wasm-bindgen/api/js_sys/struct.Uint8Array.html#method.view_mut_raw)
which was
[added](https://github.com/rustwasm/wasm-bindgen/pull/1850) in version
`0.2.54` of `wasm-bindgen`. This method was introduced to deal with
uninitialized memory, see the Safety comment for more info.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 16:22:28 -07:00
Joseph Richey 710b24dd27 Use getentropy on Emscripten (#307)
Signed-off-by: Joe Richey <joerichey@google.com>

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 15:09:31 -07:00
Joseph Richey 68b4d7a8fc Merge pull request #303 from rust-random/wasm64
Add wasm64-unknown-unknown support
2022-10-23 14:57:21 -07:00
Joe Richey 3fa761b949 Add chunking for Node.js implementation
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 13:47:00 -07:00
Joe Richey 1d371ef5e2 Add wasm64-unknown-unknown support
We can build and link just fine, but we cannot actually run the tests as
`wasm-bindgen-test-runner` hasn't yet added support.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 13:47:00 -07:00
Joseph Richey f2d76625d5 Solaris: consistantly use /dev/random source (#310)
On Solaris, we opt to use /dev/random source instead of /dev/urandom due
to reasons explained in the comments and
[in this Solaris blog post](https://blogs.oracle.com/solaris/post/solaris-new-system-calls-getentropy2-and-getrandom2).

However, we haven't been making the same choice when getting randomness
via the `getrandom(2)` function, as we just pass `0` for the flags. We
[used to](https://github.com/rust-random/rand/pull/730/files#diff-694d4302a3ff2a976f2fbd34bc05ada22ee61a4e21d2d985beab27f7a809268fR151)
always set `GRND_RANDOM`, but that was removed in the move from `OsRng`
to this crate.

For context, https://github.com/rust-random/rand/pull/730,
https://github.com/rust-random/getrandom/pull/9, and
https://github.com/rust-random/getrandom/pull/51 are the major changes
to the Solaris/Illumos implementation over the years.

See the solaris documentation for:
- [`getrandom(2)`](https://docs.oracle.com/cd/E88353_01/html/E37841/getrandom-2.html)
- [`urandom(4)`](https://docs.oracle.com/cd/E88353_01/html/E37851/urandom-4d.html)

I also updated the doucmentation to better reflect when
[Illumos added the `getrandom(2)` function](https://www.illumos.org/issues/9971#change-23483).

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 13:46:01 -07:00
Joseph Richey ad08dd9e72 Cleanup wasm32-wasi target (#306)
* Cleanup wasm32-wasi target

This change ensures that we only compile our WASI implementation for
32-bit targets. The interaction between the WASI proposal and the
memory64 proposal is not yet clear, [wasmtime does not yet support](
https://github.com/bytecodealliance/wasmtime/issues/3594#issuecomment-992590383)
using WASI with memory64, and many of the interfaces use 32-bit values
for pointers.

This change also reduces the use of `unsafe` from the wasi
implementation. As noted in #253, changes to `Errno` mean that we can't
get the error message from the raw error code, but we can avoid using
unsafe when converting this code to a NonZeroU32. This handling also
makes WASI behave more like our other targets, which also manually check
that errno is non-zero.

Signed-off-by: Joe Richey <joerichey@google.com>

* Disable default features for WASI crate

Similar to this crate, the `wasi` crate just uses a `std` feature to
implement `std::error::Errno`, which we don't use.

Signed-off-by: Joe Richey <joerichey@google.com>

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 13:29:09 -07:00
Joseph Richey d87d3399bb Document use of /dev/urandom vs /dev/random (#311)
Also, on platforms where the devices are the same, prefer using
/dev/urandom.

Documentation of the devices being the same:
- macOS [`random(4)`](https://www.unix.com/man-page/mojave/4/urandom/)
- DragonFly [`getrandom(2)`](https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom)
- Haiku [implementation](https://github.com/haiku/haiku/blob/f40bacae87f37276be7d107a6b3d41ca97b4d82c/src/add-ons/kernel/bus_managers/random/driver.cpp#L217-L222)

Signed-off-by: Joe Richey <joerichey@google.com>

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 13:26:32 -07:00
Joseph Richey 88d0d31a2c Move 3ds selection above rdrand/js/custom fallback (#312)
This makes the big cfg_if easier to read.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-23 12:59:43 -07:00
Joseph Richey 412e0d5ff5 Merge pull request #309 from briansmith/b/test-benches
CI: On Nightly toolchains, test the benchmarks instead of just building them.
2022-10-23 00:26:23 -07:00
Brian Smith 84883207b9 CI: On Nightly toolchains, test the benchmarks instead of just building them.
`cargo test` will run one iteration of each benchmark to provide evidence
that they don't fail in an obvious way (e.g. unintended panics).
2022-10-22 23:16:50 -07:00
Joseph Richey 2ec38ad931 Merge pull request #304 from rust-random/rng_tests
This PR adds some tests which make sure calls to getrandom (for both small and large buffers) "look" random.

While we could certainly add more complicated randomness tests, these simple tests are:
  - Very easy to understand
  - Don't require any external crates
  - Makes sure we aren't doing something obviously stupid like
    - forgetting [these lines](https://github.com/rust-random/getrandom/blob/bd0654fe70980583e51573e755bafa3b2f8342d9/src/rdrand.rs#L91-L95)
    - failing to initialize every other byte
    - initializing some significant fraction of bytes with a constant

As this tests all buffer sizes from 1 to 64, it also fixes #290.
2022-10-22 14:21:31 -07:00
Joe Richey b893cb9c77 Use iterators for num_diff_bits
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:52:42 -07:00
Joe Richey c83edb650b Add quality tests for calling getrandom on small buffers
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:37:23 -07:00
Joe Richey c12f70c20a Sharpen bounds in test_diff
We can be much stricter without risking inadvertant failure.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:37:21 -07:00
Joseph Richey 97c17892e7 Merge pull request #300 from rust-random/custom_test
Tests: Use custom tests to verify operations on empty slices are no-ops.

Reworking of #299 to keep our custom tests in a single file (and keep things better organized in general).
2022-10-22 13:32:14 -07:00
Brian Smith cf85546863 Tests: Use custom tests to verify operations on empty slices are no-ops.
Modify the custom tests so that they would have detected and prevented
the issue fixed in https://github.com/rust-random/getrandom/pull/298.
2022-10-22 13:25:44 -07:00
Joe Richey ee0ca47aa2 Run (most) common tests against the custom RNG
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:25:44 -07:00
Joe Richey 92af82ab9a Remove state from Custom RNG
This makes it much easier to run this RNG alongside other tests.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:25:44 -07:00
Joseph Richey ce5c2d96ac Test emscripten via Cross (#302)
Part of addressing #275 

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:23:49 -07:00
Joseph Richey d2ca7695e3 Fix Solaris/OpenBSD/Dragonfly build and re-enable CI (#301)
Fixes #216 

This also adds two minor CI improvements:
  - Do a full link on `freebsd`
  - Build, Link, but don't run on `illumos`
  - Use the stable toolchain for our Tier 2 Build-only targets
  - Build (via `build-std`) for Tier 3 targets: `openbsd`, `dragonfly`, `haiku`

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-22 13:22:38 -07:00
Joseph Richey f7b733042c Update MSRV in .clippy.toml (#305)
This reflects the changes in #291
2022-10-22 11:20:18 +00:00
Joseph Richey bd0654fe70 Rework benchmarks to make it easier to get assembly. (#297)
* Rename benches/mod.rs to benches/buffer.rs

This naming makes more sense, especially if we add more benchmark
files.

Signed-off-by: Joe Richey <joerichey@google.com>

* Rework benchmarks to make it easier to get assembly.

This change:
  - Move the benchmarks from mod.rs to buffer.rs
  - Move the inner loop we benchmark into an `#[inline(never)]` function
  - Includes instructions for getting the ASM for a specific benchmark

This should hopefully reduce the variance of these benchmarks and make
it easier to figure out if we are emitting the assembly or IR we expect
for a particular implementation.

Signed-off-by: Joe Richey <joerichey@google.com>

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-21 14:10:44 +00:00
Joseph Richey 55ad4c41ba Add back empty slice check (#298)
https://github.com/rust-random/getrandom/pull/291 inadvertantly removed
this check

See https://github.com/rust-random/getrandom/pull/104 for why this was
added in the first place. Also, per our docs:

> If `dest` is empty, `getrandom` immediately returns success, making
> no calls to the underlying operating system.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-21 14:02:34 +00:00
Brian Smith 47a59dda25 Add getrandom_uninit_slice(dest: &mut [MaybeUninit<u8>]) -> .... (#291)
* Add `getrandom_uninit(dest: &mut [MaybeUninit<u8>]) -> ...`.

Add a public API for filling an `&mut [MaybeUninit<u8>]`. This will primarily
serve as the building block for more typeful APIs for constructing random
arrays.

Increase the MSRV to 1.36, as `MaybeUninit` was added in that release.

Fixes #226.

* Revert testing changes

Signed-off-by: Joe Richey <joerichey@google.com>

* Allow rdrand tests to work with new implementation

Signed-off-by: Joe Richey <joerichey@google.com>

* Add Additional benchmarks and buffer size

Signed-off-by: Joe Richey <joerichey@google.com>

* Use pointer casts instead of transmute

Signed-off-by: Joe Richey <joerichey@google.com>

* Avoid initializing the buffer in `getrandom_uninit` benchmarks.

* Benchmarks: Consume the result in `black_box`.

Signed-off-by: Joe Richey <joerichey@google.com>
Co-authored-by: Joe Richey <joerichey@google.com>
2022-10-20 19:09:20 -07:00
Joseph Richey 5c1bb00b74 Release v0.2.8 (#294)
Also updates the changelog

Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-20 13:53:06 -07:00
Joseph Richey 353d0ca157 Update docs for wasm32-unknown-unknown implementation (#295)
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-20 02:33:05 -07:00
Joseph Richey cfdad53dce Merge pull request #284 from rust-random/webcrypto
Rework JS feature detection
2022-10-06 15:06:39 -07:00
Joe Richey 9962c706c9 Update Module::require internal comments
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-06 14:52:39 -07:00