286 Commits

Author SHA1 Message Date
Joe Richey
0503000381 Fix link typo
Signed-off-by: Joe Richey <joerichey@google.com>
2022-10-06 14:51:49 -07:00
Joe Richey
0579fe3014 Update documentation and error messages
This allows users to get an actionable error message about this
particular problem. We also add detection for this problem.

Signed-off-by: Joe Richey <joerichey@google.com>
2022-09-13 02:56:51 -07:00
Joe Richey
d69e8e003b Rework JS feature detection
Now we look for the standard Web Cryptography API before attempting to
check for Node.js support. This allows Node.js ES6 module users to add
a polyfill like:
```js
import {webcrypto} from 'crypto'
globalThis.crypto = webcrypto
```
as described in https://github.com/rust-random/getrandom/issues/256#issuecomment-1161028902

Signed-off-by: Joe Richey <joerichey@google.com>
2022-09-13 00:37:43 -07:00
Mauri Mustonen
d3aa089bbd
Add description about Cargo js feature for WebAssembly section (#280)
* add description about Cargo js feature
* add note about different crate types
* clean up
* Fix wording/grammer
* Remove "Indirect Depenencies" section
* Note that libraries shouldn't add their own JS feature

Signed-off-by: Joe Richey <joerichey@google.com>
Co-authored-by: Mauri Mustonen <mauri.mustonen@hotmail.com>
Co-authored-by: Joe Richey <joerichey@google.com>
2022-08-30 01:06:17 -07:00
Artyom Pavlov
0b71d50b49
Fix link to wasm-bindgen (#278) 2022-08-18 18:58:34 -07:00
Autumn
9a64857ae6
document the variation in underlying details of abstracted randomness sources (#276) 2022-08-18 01:53:05 +00:00
Joseph Richey
7089766df0
Add/Rework benchmarks to track initialization cost (#272)
This PR adds more benchmarks so we can get and accurate idea about two
things:

  - What is the cost of having to zero the buffer before calling
    `getrandom`?
  - What is the performance on aligned, 32-byte buffers?
    - This is by far the most common use, as its used to seed
      usersapce CSPRNGs.

I ran the benchmarks on my system:
  - CPU: AMD Ryzen 7 5700G
  - OS: Linux 5.15.52-1-lts
  - Rust Version: 1.62.0-nightly (ea92b0838 2022-05-07)

I got the following results:
```
test bench_large      ... bench:   3,759,323 ns/iter (+/- 177,100) = 557 MB/s
test bench_large_init ... bench:   3,821,229 ns/iter (+/- 39,132) = 548 MB/s
test bench_page       ... bench:       7,281 ns/iter (+/- 59) = 562 MB/s
test bench_page_init  ... bench:       7,290 ns/iter (+/- 69) = 561 MB/s
test bench_seed       ... bench:         206 ns/iter (+/- 3) = 155 MB/s
test bench_seed_init  ... bench:         206 ns/iter (+/- 1) = 155 MB/s
```

These results were very consistent across multiple runs, and roughtly
behave as we would expect:
  - The thoughput is highest with a buffer large enough to amoritize the
    syscall overhead, but small enough to stay in the L1D cache.
  - There is a _very_ small cost to zeroing the buffer beforehand.
  - This cost is imperceptible in the common 32-byte usecase, where the
    syscall overhead dominates.
  - The cost is slightly higher (1%) with multi-megabyte buffers as the
    data gets evicted from the L1 cache between the `memset` and the
    call to `getrandom`.

I would love to see results for other platforms. Could we get someone to
run this on an M1 Mac?

Signed-off-by: Joe Richey <joerichey@google.com>
2022-07-13 06:04:41 -07:00
Leonardo Yvens
3d818a6a0a
use $crate in macro (#270)
This is the recommended way of referring to the current crate in a macro.
2022-07-07 23:48:06 -07:00
Joseph Richey
63f861c684
Release v0.2.7 (#264)
Signed-off-by: Joe Richey <joerichey@google.com>
2022-06-13 14:31:59 -07:00
Joseph Richey
c82a522713
Use AtomicPtr instead of AtomicUsize for Weak (#263)
This allows Strict Provenance to work properly, fixing #262. It also
now matches what `libstd` does:
9f7e997c8b/library/std/src/sys/unix/weak.rs (L85-L141)

Also, while reading the `libstd` code, I noticed that they use an
`Acquire` fence and `Release` store as the returned pointer should
have "consume" semantics. As this doesn't yet exist in Rust, we
instead do exactly what `libstd` does, which means:
  - Relaxed Load
  - Release Store
  - Acquire fence when returning pointer

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

Co-authored-by: Joe ST <joe@fbstj.net>
2022-06-13 12:10:19 -07:00
Tobias Klauser
9e2c896e65
bsd_arandom: fix typo in comment (#260)
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2022-04-22 18:15:59 +00:00
Thomas de Zeeuw
2d65a40cc5
Update to wasi 0.11 (#253)
* Update to wasi 0.11

The main breaking change between v0.10 and v0.11 is that Error is
removed in favour of Errno. Unfortunately we can't create an Errno from
outside the wasi create so we're loosing some debug information for
errors.

I've opened an issue to add back such a constructor, see
<https://github.com/bytecodealliance/wasi/issues/64>.

* Use libc::strerror to get the error message on wasi

Since wasi v0.11 doesn't (yet) provided a way to create Errno, see
<https://github.com/bytecodealliance/wasi/issues/64>.

* Remove libc dependency for WASI

This does mean that we won't get an error message for the error type.
2022-04-15 02:20:44 -07:00
Joseph Richey
4882ac8a4c
Add notes when various functions were added (#257)
Signed-off-by: Joe Richey <joerichey@google.com>
2022-04-03 12:24:03 -07:00
Joseph Richey
fcece06dd5
Merge pull request #255 from rust-random/release/v0.2.6
Release v0.2.6
2022-03-25 15:34:56 -07:00
Артём Павлов [Artyom Pavlov]
0830ba66be Disable Solaris CI job 2022-03-26 01:19:56 +03:00
Артём Павлов [Artyom Pavlov]
2630158149 Release v0.2.6 2022-03-26 01:09:35 +03:00
Tobias Stoeckmann
fcae1d2626
libc: retry open when interrupted (#252)
The open call can be interrupted. Since sys_fill_exact covers this for
read operation already, it should be done here as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2022-03-25 22:02:35 +00:00
Mark Drobnak
d40ec2c7e4
Add support for the Nintendo 3DS (armv6k-nintendo-3ds) (#248) 2022-03-25 16:26:05 +00:00
Artyom Pavlov
157d6f23dc
Fix v0.2.5 release date (#250) 2022-02-22 16:48:08 +00:00
Artyom Pavlov
cd3a987b9b
Release v0.2.5 (#247) 2022-02-22 12:09:08 +00:00
Þórhallur Sverrisson
cf02327ac9
Enable support for espidf (esp32 family of microcontrollers) (#245) 2022-02-05 00:55:59 +00:00
Joseph Richey
e1a9c9e740
Merge pull request #246 from rust-random/cross_fix
Update cross URL
2022-01-29 18:12:01 -08:00
Артём Павлов [Artyom Pavlov]
f49f083412 fix cross tests 2022-01-29 18:48:38 +03:00
Joseph Richey
21e03e8056
ios: Fix Error checking for SecRandomCopyBytes (#244)
Apple's documentation for SecRandomCopyBytes says that errSecSuccess is
returned on success, and all other values indicate failure.
  https://developer.apple.com/documentation/security/1399291-secrandomcopybytes

The SecBase.h header also clearly establishes that `errSecSuccess = 0`:
  https://opensource.apple.com/source/Security/Security-55471/sec/Security/SecBase.h.auto.html

Fixes #243

Signed-off-by: Joe Richey <joerichey@google.com>
2022-01-21 16:50:40 +00:00
Joseph Richey
e6e7dd6048
Merge pull request #234 from mjhanninen/fix-webpack-dynamic-require-error
Fix Webpack warning caused by dynamic require
2022-01-13 18:58:40 -08:00
Joe Richey
8fad7c5ab4 js: Add comment explaining why we do this hack
Signed-off-by: Joe Richey <joerichey@google.com>
2022-01-13 18:48:09 -08:00
Artyom Pavlov
b9c7c0c13d
Release v0.2.4 (#238) 2022-01-13 21:46:24 +00:00
kpcyrd
9110af54d1
Fix get_rng_fd comment typo (#240) 2022-01-13 21:46:02 +00:00
Stewart Mackenzie
ec445bb0ac
Added x86_64-unknown-hermit support (#236) 2021-12-07 14:48:30 +00:00
Tomoaki Kawada
f5e33009ed
Add SOLID target support (#235) 2021-11-30 00:21:36 +00:00
Matti Hänninen
8372c165af Fix Webpack warning caused by dynamic require
Webpack supports dynamic importing only for some special cases in which
it is able to narrow down the set of packages to bundled.  In the
general case it just produces an empty (Webpack) context plus the
warning stating that "the request of a dependency is an expression."

Apparently the commit 120a1d7f changed the Javascript generated by
wasm-bindgen so that the binding for the `require` became:

```
module.require(getStringFromWasm0(arg0, arg1))
```

when it used to be:

```
getObject(arg0).require(getStringFromWasm0(arg1, arg2))
```

In the latter case Webpack did not even realize that this code imported
a package and, hence, did not try to bundle it.  The new code triggers
the bundling and because the dependency is fully dynamic Webpack has
problems with it.

This commit reverts partially the commit 120a1d7f so that the generated
binding obfuscates the `require` call enough to hide it from Webpack
again.
2021-10-15 21:03:35 +03:00
Cyborus04
0d0404be5a
Use NonZeroU32::new_unchecked to convert wasi error (#233) 2021-10-15 03:57:40 +00:00
Joseph Richey
e4004f41fa
redox: Switch to /dev/urandom (#222)
Signed-off-by: Joe Richey <joerichey@google.com>
2021-10-14 18:16:03 -07:00
Joseph Richey
30308ae845
js: Explictly list all dependancies used with the "js" feature (#220)
This makes it easier to tell at a glance what parts of `wasm-bindgen`
are needed for `getrandom`.

See: https://github.com/tkaitchuck/aHash/issues/95#issuecomment-881152315

Signed-off-by: Joe Richey <joerichey@google.com>
2021-07-16 00:23:43 -07:00
Dirk Stolle
dcf452bb14
fix some typos (#218) 2021-05-20 19:26:19 -07:00
Artyom Pavlov
de51e2961d
Release v0.2.3 (#211) 2021-05-20 08:00:44 +00:00
Joseph Richey
120a1d7f47
Imporve detection for Node JS (#215)
This uses `process.versions.node` to see if we are in Node.js rather
than using `global.self` to check if we are in a Browser.

This change also makes some minor `wasm_bindgen` improvements:
  - Use `js_sys::global()` to get the global object
  - Bind the node require as `module.require`
  - Improving error messages

Signed-off-by: Joe Richey <joerichey@google.com>
2021-05-20 08:00:20 +00:00
Joseph Richey
922d1de82d
Fix Solaris CI (#216)
The new target is called `x86_64-pc-solaris`, but `cross` doesn't
support that yet, so just use `sparcv9-sun-solaris`.

See the following issues for more info:
  https://github.com/rust-lang/rust/issues/85098
  https://github.com/rust-lang/rust/pull/82216

Signed-off-by: Joe Richey <joerichey@google.com>
2021-05-14 12:04:30 +03:00
Tobias Klauser
24716865bd
Fix dead link to NetBSD sysctl man page (#212)
Use the offical NetBSD man page URL https://man.netbsd.org

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2021-05-02 20:31:17 +00:00
Tobias Klauser
36d085a1f4
Add support for getrandom syscall on DragonFly BSD (#210)
DragonFly BSD supports the getrandom system call since version 5.7 [1].
Use it if available, otherwise fall back to /dev/random.

[1] https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2021-04-04 03:14:02 +00:00
Joseph Richey
0eb0be130e
Update docs and compile_errors for wasm32-unknown-unknown (#209)
Signed-off-by: Joe Richey <joerichey@google.com>
2021-03-06 02:15:07 -08:00
Artyom Pavlov
c4a0004e8b
Replace build.rs with link attributes (#205) 2021-02-16 18:09:32 -08:00
Artyom Pavlov
9b2d55803e
Fix WASI function name and doc link (#202) 2021-02-02 02:29:30 -08:00
Artyom Pavlov
d79de0c95c
Release v0.2.2 (#201) 2021-01-19 12:34:27 +00:00
Joseph Richey
27b5172a2e
Merge pull request #200 from rust-random/doc_feature
Use doc_cfg to improve register_custom_getrandom docs
2021-01-19 02:56:00 -08:00
Joe Richey
d7a0d580d4
Set doc(cfg(feature = "std")) on std trait impls
Signed-off-by: Joe Richey <joerichey@google.com>
2021-01-19 02:46:59 -08:00
Joe Richey
2cfbd8ee60
Modify doc tests to set docsrs
Signed-off-by: Joe Richey <joerichey@google.com>
2021-01-19 02:46:38 -08:00
Артём Павлов [Artyom Pavlov]
69634b700e Use doc_cfg to improve register_custom_getrandom docs 2021-01-18 01:00:23 +03:00
Joseph Richey
9a48bfabc0
Merge pull request #198 from rust-random/hermit
Add fixes for Caching and rustc-dep-of-std feature
2021-01-17 12:32:22 -08:00
Joe Richey
3661e9dc2a
Properly forward rustc-dep-of-std feature
Signed-off-by: Joe Richey <joerichey@google.com>
2021-01-17 00:28:36 -08:00