285 Commits

Author SHA1 Message Date
Joe Richey
eacffd578a wasm: Move JS-based Custom RNGs back into the main crate
They will be gated behind the "js" feature, as we can now do detect,
at compile-time, which implementation (wasm-bindgen vs stdweb) we
should use.

The "js" implementation takes precedence over the "custom"
implementation. This prevents issues that arise from the buggy way
Cargo handles features across multiple targets.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-29 01:11:13 -07:00
Joe Richey
6aba12ccdb Rename "cpu" feature to "rdrand"
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-28 19:03:02 -07:00
Joe Richey
618593ca03 cpu: Have "cpu" feature take precedence over "custom"
Right now, features are always enabled across all targets. This means
that if _any_ Custom RNG is used _anywhere_ in a crate's dependancy
graph on _any_ target. The "custom" feature will be active on all
targets.

This makes it impossible to have a bare metal target that uses "cpu" on
x86_64 and a Custom RNG on aarch64. This solution also makes sure that
any implementation `getrandom` itself provides cannot be overridden.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-28 19:03:02 -07:00
Joe Richey
a29180afcd wasm32: Unify error codes an implementations
Right now, while our implementations for stdweb and wasm-bindgen use
similar APIs, they do not use similar implementations. This change:

  - Switches to using the same error codes for both implementations
  - Uses error codes that detail exactly what API is missing
  - Cleans up the implemetnations to make them much more readable
  - Consitantly use thread_local in both implementations

This makes issues easier to debug and the code easier to understand.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25 13:20:12 -07:00
Joe Richey
10df5588c2 AppVeyor: Run CI on 0.2 branch
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25 12:13:57 -07:00
Joe Richey
7631f75292 ci: Pin the Cross binary to avoid breaking the CI
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-25 03:00:58 -07:00
Diggory Hardy
8191d7f26b
Merge pull request #143 from josephlr/fixing-webpack-warning
Apply #137 to 0.2 branch
2020-04-28 08:45:26 +01:00
Pauan
ec4a3e1f03 Fixing Webpack require warning 2020-04-27 15:57:14 -07:00
zer0x64
7bfdabf358 wasm-bindgen: Added support for Internet Explorer 11 2020-04-27 06:22:44 -07:00
zer0x64
0ad1c77214 wasm-bindgen: Added support for Internet Explorer 11 2020-04-27 06:22:04 -07:00
Pauan
f1c264d476 Fixing Webpack require warning 2020-04-27 02:45:09 -07:00
Joe Richey
54b4c8d1b6 travis: Allow nightly builds to fail 2020-04-27 02:15:05 -07:00
Joe Richey
b44da72a01 travis: Fix wasm32 CI
Split emscripten stuff into its own target and stop relying on cargo web
to download/manage then emscripten toolchain. We can just get it
ourselves. We also now run the emscripten tests.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-04-27 02:15:05 -07:00
Diggory Hardy
717b5cc654
Merge pull request #145 from josephlr/nightly
travis: Allow nightly builds to fail
2020-04-27 09:38:01 +01:00
Joe Richey
c7862af490 travis: Allow nightly builds to fail 2020-04-27 00:51:12 -07:00
Joe Richey
74eca5e871 fmt: Use consistent include style 2020-04-27 00:14:53 -07:00
Joe Richey
138d903318 ios: Don't use SecRandom type
The type of the `rnd` parameter is SecRandomRef which is an alias for an
"Opaque Pointer". This is better represented in Rust as a c_void pointer.

We also know that kSecRandomDefault is NULL, so we can simplify the code.

https://developer.apple.com/documentation/security/1399291-secrandomcopybytes
https://developer.apple.com/documentation/security/secrandomref
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/using_imported_c_functions_in_swift
2020-04-27 00:14:53 -07:00
Joe Richey
afcfcd1525 build: Remove getrandom_uwp cfg
As our minimum rust version is 1.33, we can just use `target_vendor`.
2020-04-27 00:14:53 -07:00
Joe Richey
b3d3fbcb10 assert: Make use of asserts consistent
- Use debug asserts in code
- Use normal asserts in tests
- Use *assert_eq! methods when possible
- Remove unnecessary asserts
2020-04-27 00:14:53 -07:00
Joe Richey
d1a84dbd0d error: Make internal_error! a function
Also make Error::code a const fn. These increase the Min Rust version to 1.33
2020-04-27 00:14:53 -07:00
Diggory Hardy
3d17318c59
Merge pull request #141 from josephlr/travis
travis: Fix wasm32 CI
2020-04-26 14:47:36 +01:00
Joe Richey
c25d0a81eb
travis: Fix wasm32 CI
Split emscripten stuff into its own target and stop relying on cargo web
to download/manage then emscripten toolchain. We can just get it
ourselves. We also now run the emscripten tests.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-04-25 02:44:08 -07:00
Joe Richey
2e39004c4b rdrand: Add 32-bit x86 support
Also add tests for 32-bit x86
2020-02-20 15:24:57 -08:00
Joe Richey
52e7e9fe23 tests: Test CPU-based RNG on all x86 targets
This allows us to verify the RDRAND implementation on Linux.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-02-19 10:21:58 -08:00
Joe Richey
1375181832 tests: Improve testing infrastructure
- Cleanup .travis.yml
  - Loops over std/no_std targets
  - Remove deprecated/useless keys
  - No more `cd`, we just use `--package`.
- Improve tests
  - Main `getrandom` tests are now unit test modules instead of
    integration tests, making the code cleaner.
  - The custom RNG crates now use this common module as part of their
    integration tests.
  - No more weird test-only features needed to get the crate to build.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-02-19 10:21:58 -08:00
Joe Richey
ff6299dd77 cpu: Add support for CPU-based randomness
This allows freestanding targets to use getrandom.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-02-19 10:21:58 -08:00
Joe Richey
cd84484205 target: Drop support for some x86_64 targets
We will use a more generic "cpu" mechanism to support these.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-02-19 10:21:58 -08:00
Joe Richey
4263ac6bc4 custom: Allow no_std custom RNG handlers
Signed-off-by: Joe Richey <joerichey@google.com>
2020-02-19 10:21:58 -08:00
Joe Richey
8365277450 custom: Add Custom RNG for wasm-bindgen 2020-01-10 09:16:20 +00:00
Joe Richey
7d558f1cc3 custom: Add custom RNG for stdweb 2020-01-10 09:16:20 +00:00
Joe Richey
3d7a7b5f06 Remove built-in support for wasm32-unknown-unknown 2020-01-10 09:16:20 +00:00
Joe Richey
448bcac6b1 custom: Add support for Custom RNGs 2020-01-10 09:16:20 +00:00
Joseph Richey
d6b75d1c05
log: Remove optional log dependancy (#131)
This feature isn't enabled by rand/rand_core and provides very little
error information that isn't already conveyed through our Error values.

This also simplifies the supported configuration space for getrandom.
We update the docs and CI to match this change.
2020-01-09 13:27:09 -08:00
Joe Richey
0f14f2a186 Merge branch 'master' into 0.2
Signed-off-by: Joe Richey <joerichey@google.com>
2020-01-08 11:11:08 -08:00
Artyom Pavlov
33b859bae1
Prepare release v0.1.14 (#128) 2020-01-07 12:05:23 +00:00
Joe Richey
c5e2025d2c util: Remove unused spin-lock interfaces
We no longer use spin-locks anywhere in getrandom, so remove any
interfaces which spin.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-01-07 11:06:56 +00:00
Joe Richey
46963aac74 use_file: Remove use of spin-locks
Don't spin when polling /dev/random. We also remove the use of spin
locks when opening the persistent fd for platforms that require it.

For both these cases, we can just use the pthread lock/unlock methods
in libc. This includes adding Mutex and DropGuard abstractions.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-01-07 11:06:56 +00:00
Joe Richey
245b5b2121 util_libc: open_readonly shoud return a Result
Signed-off-by: Joe Richey <joerichey@google.com>
2020-01-07 11:06:56 +00:00
Joseph Richey
a913c9c673 dragonfly: Don't try to read errno value (#129) 2020-01-07 03:54:43 +00:00
Joseph Richey
48781cd9ec wasi: Update and Fix Travis failures (#126) 2020-01-05 20:59:50 +00:00
Joseph Richey
8096bac100 0.2: Error and Testing improvements (#120) 2019-10-28 08:06:05 +00:00
Joseph Richey
cf2d81bfff Improve src/lib.rs cfgs (#119)
Right now for each of `util_libc` and `use_file` we have a list of
`target_os` configs to determine if we build the module.

This PR moves these mod declarations into the main `cfg_if` statement
(the one that selects which implementation we use). This way, the mod
statements are kept in-sync with the implementations that use them.

Also, I merged together `target_os` cfgs that have the same
implementation. The downside to this is that the targets are no longer
in alphabetical order.

Also, this is only being applied to `0.2` as the `0.1` cfgs still have
to keep `std` around.
2019-10-25 12:55:12 +00:00
Artyom Pavlov
d661aa7e1b
Prepare release v0.1.13 (#118) 2019-10-25 12:25:33 +00:00
Joe Richey
1f1f964e4a Merge branch 'master' into 0.2 2019-10-24 02:10:00 -07:00
Joseph Richey
81bd43e5d6
Fix typos and bad doc links. (#117) 2019-10-24 02:06:53 -07:00
Artyom Pavlov
9a385f1923
Add VxWorks support (#86) 2019-10-23 09:35:50 +00:00
nia
2fa1bbac80 Switch to using the arandom sysctl on NetBSD (same as FreeBSD). (#115)
Rename it from freebsd.rs to sysctl_arandom.rs.

NetBSD has been patching rustc for some time to use the FreeBSD
implementation because every single invocation of the compiler
may drain from the entropy pool and cause the next to block.

This can massively inflate build times for rust software, or cause
it to fail entirely, especially in VMs (for example, our Xen package
building cluster).
2019-10-23 09:03:44 +00:00
Joseph Richey
add45a3899 Remove dummy implementation (#107)
Removes the “dummy” feature and “wasm32-unknown-unknown” dummy impl
2019-10-15 23:40:05 -07:00
Joseph Richey
605736748a Only impl std traits if feature is specified (#106)
* Fix CI to allow for PRs against 0.2 to be run

* Only impl std traits if feature is specified

* Fix l4re
2019-10-15 23:40:05 -07:00
Diggory Hardy
6b4925a76d
Merge pull request #112 from dekellum/min-cfg-if
cfg-if 0.1.2 is minimal version of dependency
2019-10-01 08:43:28 +01:00