-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill crypto to shim std::random_device in wasm builds
- Loading branch information
1 parent
0898ae4
commit df93faf
Showing
4 changed files
with
134 additions
and
149 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// We use this to shim a crypto library in the WebAudioWorklet environment, which | ||
// is necessary for Emscripten's implementation of std::random_device, which we need | ||
// after pulling in signalsmith-stretch. | ||
// | ||
// I've seen some issues on esmcripten that seem to suggest an insecure polyfill like | ||
// this should already be provided, but I'm getting runtime assertion errors that it's | ||
// not available. An alternative solution would be to upstream a change to the stretch | ||
// library to rely on an injected random device in C++ territory, so that for our case | ||
// we could inject some simple PRNG. | ||
globalThis.crypto = { | ||
getRandomValues: (array) => { | ||
for (var i = 0; i < array.length; i++) { | ||
array[i] = (Math.random() * 256) | 0; | ||
} | ||
} | ||
}; |