Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: clarify require("crypto").getRandomValues is Node.js specific #41782

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -4112,7 +4112,8 @@ added: v17.4.0
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.

A convenient alias for [`crypto.webcrypto.getRandomValues()`][].
A convenient alias for [`crypto.randomFillSync()`][] that has the same signature as
[`crypto.webcrypto.getRandomValues()`][].

### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`

Expand Down Expand Up @@ -6005,6 +6006,7 @@ See the [list of SSL OP Flags][] for details.
[`crypto.publicEncrypt()`]: #cryptopublicencryptkey-buffer
[`crypto.randomBytes()`]: #cryptorandombytessize-callback
[`crypto.randomFill()`]: #cryptorandomfillbuffer-offset-size-callback
[`crypto.randomFillSync()`]: #cryptorandomfillsyncbuffer-offset-size
[`crypto.scrypt()`]: #cryptoscryptpassword-salt-keylen-options-callback
[`crypto.webcrypto.getRandomValues()`]: webcrypto.md#cryptogetrandomvaluestypedarray
[`crypto.webcrypto.subtle`]: webcrypto.md#class-subtlecrypto
Expand Down
6 changes: 5 additions & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ function getFipsForced() {
return 1;
}

function getRandomValues(array) {
return randomFillSync(array);
targos marked this conversation as resolved.
Show resolved Hide resolved
}

ObjectDefineProperty(constants, 'defaultCipherList', {
value: getOptionValue('--tls-cipher-list')
});
Expand Down Expand Up @@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, {
getRandomValues: {
configurable: false,
enumerable: true,
get() { return lazyWebCrypto().crypto.getRandomValues; },
get: () => getRandomValues,
set: undefined,
},

Expand Down