Skip to content

Commit 43734e3

Browse files
authoredDec 29, 2017
Merge pull request #564 from david-a-wheeler/readme-timing
README: comparisons resist timing attacks
2 parents 096a34f + f2bec20 commit 43734e3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎README.md

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ bcrypt.compare(someOtherPlaintextPassword, hash, function(err, res) {
103103
// res == false
104104
});
105105
```
106+
107+
The "compare" function counters timing attacks (using a so-called 'constant-time' algorithm).
108+
In general, don't use the normal JavaScript string comparison functions to compare passwords,
109+
cryptographic keys, or cryptographic hashes if they are relevant to security.
110+
106111
### with promises
107112

108113
bcrypt uses whatever Promise implementation is available in `global.Promise`. NodeJS >= 0.12 has a native Promise implementation built in. However, this should work in any Promises/A+ compliant implementation.
@@ -159,6 +164,9 @@ As with async, both techniques achieve the same end-result.
159164
bcrypt.compareSync(myPlaintextPassword, hash); // true
160165
bcrypt.compareSync(someOtherPlaintextPassword, hash); // false
161166
```
167+
The "compareSync" function counters timing attacks (using a so-called 'constant-time' algorithm).
168+
In general, don't use the normal JavaScript string comparison functions to compare passwords,
169+
cryptographic keys, or cryptographic hashes if they are relevant to security.
162170

163171
### Why is async mode recommended over sync mode?
164172
If you are using bcrypt on a simple script, using the sync mode is perfectly fine. However, if you are using bcrypt on a server, the async mode is recommended. This is because the hashing done by bcrypt is CPU intensive, so the sync version will block the event loop and prevent your application from servicing any other inbound requests or events.

0 commit comments

Comments
 (0)
Please sign in to comment.