Skip to content

Commit f760ca2

Browse files
committed
crypto: clarify require("crypto").getRandomValues is Node.js specific
Refs: nodejs#41779 Refs: nodejs#41760
1 parent 4fbe9e5 commit f760ca2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/api/crypto.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4112,7 +4112,8 @@ added: v17.4.0
41124112
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
41134113
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.
41144114

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

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

@@ -6005,6 +6006,7 @@ See the [list of SSL OP Flags][] for details.
60056006
[`crypto.publicEncrypt()`]: #cryptopublicencryptkey-buffer
60066007
[`crypto.randomBytes()`]: #cryptorandombytessize-callback
60076008
[`crypto.randomFill()`]: #cryptorandomfillbuffer-offset-size-callback
6009+
[`crypto.randomFillSync()`]: #cryptorandomfillsyncbuffer-offset-size
60086010
[`crypto.scrypt()`]: #cryptoscryptpassword-salt-keylen-options-callback
60096011
[`crypto.webcrypto.getRandomValues()`]: webcrypto.md#cryptogetrandomvaluestypedarray
60106012
[`crypto.webcrypto.subtle`]: webcrypto.md#class-subtlecrypto

lib/crypto.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ function getFipsForced() {
252252
return 1;
253253
}
254254

255+
function getRandomValues(array) {
256+
return randomFillSync(array);
257+
}
258+
255259
ObjectDefineProperty(constants, 'defaultCipherList', {
256260
value: getOptionValue('--tls-cipher-list')
257261
});
@@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, {
303307
getRandomValues: {
304308
configurable: false,
305309
enumerable: true,
306-
get() { return lazyWebCrypto().crypto.getRandomValues; },
310+
get: () => getRandomValues,
307311
set: undefined,
308312
},
309313

0 commit comments

Comments
 (0)