Skip to content

Commit a55ce18

Browse files
committed
Emphasise importance of a CSPRNG, see #16
1 parent b1bc999 commit a55ce18

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ While bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure J
1616
times](https://github.com/dcodeIO/bcrypt.js/wiki/Benchmark)), effectively reducing the number of iterations that can be
1717
processed in an equal time span.
1818

19+
The maximum input length is 72 bytes (note that UTF8 encoded characters use up to 4 bytes) and the length of generated
20+
hashes is 60 characters.
21+
1922
Usage
2023
-----
2124
The library is compatible with CommonJS and AMD loaders and is exposed globally as `dcodeIO.bcrypt` if neither is
@@ -117,8 +120,8 @@ API
117120
---
118121
### setRandomFallback(random)
119122

120-
Sets the random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto API
121-
is available.
123+
Sets the pseudo random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto
124+
API is available. Please note: It is highly important that this PRNG is cryptographically secure!
122125

123126
| Parameter | Type | Description
124127
|-----------------|-----------------|---------------

src/bcrypt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979

8080

8181
/**
82-
* Sets the random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto API
83-
* is available.
82+
* Sets the pseudo random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto
83+
* API is available. Please note: It is highly important that this PRNG is cryptographically secure!
8484
* @param {?function(number):!Array.<number>} random Function taking the number of bytes to generate as its
8585
* sole argument, returning the corresponding array of cryptographically secure random byte values.
8686
* @see http://nodejs.org/api/crypto.html

tests/bench.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ function testAsync(name, salt, impl, cb) {
2020
});
2121
}
2222

23+
function testMax(name, impl) {
24+
var s = "",
25+
salt = bcryptjs.genSaltSync(4),
26+
last = null;
27+
while (s.length < 100) {
28+
s += "0";
29+
var hash = impl.hashSync(s, salt);
30+
if (hash === last) {
31+
console.log(name+" maximum input length is: "+(s.length-1));
32+
break;
33+
}
34+
last = hash;
35+
}
36+
}
37+
38+
testMax("bcrypt.js", bcryptjs);
39+
2340
console.log("## Comparing bcryptjs with bcrypt\n");
2441

2542
function next() {

0 commit comments

Comments
 (0)