@@ -26,13 +26,14 @@ exports.addEntropySource = sources.addEntropySource;
2626/**
2727 * Request random bytes from the best available entropy source. This
2828 * function is asynchronous bacause it might take some time to gather
29- * enough entropy from the source. This is similar to /dev/random
30- * in Unix.
29+ * enough entropy from the source. This might use /dev/random as a backend
30+ * in KVM and might be extremely slow depending on the buffer size and
31+ * the amount of available entropy.
3132 *
3233 * @param {number|Uint8Array } value Number of bytes to request or buffer to fill
3334 * @param {function } cb Callback with the resulting Uint8Array buffer argument
3435 */
35- exports . getRandomValues = function ( value , cb ) {
36+ exports . getTrueRandomValues = function ( value , cb ) {
3637 var u8 = null ;
3738 if ( typeutils . isNumber ( value ) ) {
3839 u8 = new Uint8Array ( value ) ;
@@ -43,20 +44,20 @@ exports.getRandomValues = function(value, cb) {
4344 }
4445
4546 if ( ! u8 ) {
46- throw new Error ( 'getRandomValues : argument 0 is not a number or Uint8Array' ) ;
47+ throw new Error ( 'getTrueRandomValues : argument 0 is not a number or Uint8Array' ) ;
4748 }
4849
4950 if ( u8 . length === 0 ) {
50- throw new Error ( 'getRandomValues : buffer length must be greater than 0' ) ;
51+ throw new Error ( 'getTrueRandomValues : buffer length must be greater than 0' ) ;
5152 }
5253
5354 if ( ! typeutils . isFunction ( cb ) ) {
54- throw new Error ( 'getRandomValues : argument 1 is not a function' ) ;
55+ throw new Error ( 'getTrueRandomValues : argument 1 is not a function' ) ;
5556 }
5657
5758 var defaultSource = getDefaultSource ( ) ;
5859 if ( ! defaultSource ) {
59- throw new Error ( 'getRandomValues : no entropy source available' ) ;
60+ throw new Error ( 'getTrueRandomValues : no entropy source available' ) ;
6061 }
6162
6263 defaultSource . getBytes ( u8 , function ( ) {
@@ -66,14 +67,12 @@ exports.getRandomValues = function(value, cb) {
6667} ;
6768
6869/**
69- * Request random bytes from the immediately available entropy source. This
70- * function is synchronous, but the output may contain less entropy than
71- * getRandomValues() output. This is similar to Unix's /dev/urandom.
70+ * Request random bytes from the CSPRNG seeded with enough entropy.
7271 *
7372 * @param {number|Uint8Array } value Number of bytes to request or buffer to fill
7473 * @return {Uint8Array } Buffer filled with random data
7574 */
76- exports . getPseudoRandomValues = function ( value ) {
75+ exports . getRandomValues = function ( value ) {
7776 var u8 = null ;
7877 if ( typeutils . isNumber ( value ) ) {
7978 u8 = new Uint8Array ( value ) ;
@@ -84,11 +83,11 @@ exports.getPseudoRandomValues = function(value) {
8483 }
8584
8685 if ( ! u8 ) {
87- throw new Error ( 'getPseudoRandomValues : argument 0 is not a number or Uint8Array' ) ;
86+ throw new Error ( 'getRandomValues : argument 0 is not a number or Uint8Array' ) ;
8887 }
8988
9089 if ( u8 . length === 0 ) {
91- throw new Error ( 'getPseudoRandomValues : buffer length must be greater than 0' ) ;
90+ throw new Error ( 'getRandomValues : buffer length must be greater than 0' ) ;
9291 }
9392
9493 for ( var i = 0 ; i < u8 . length ; i ++ ) {
0 commit comments