Skip to content

Commit f2bec20

Browse files
authoredDec 21, 2017
README: comparisons resist timing attacks
Clarify in README that the comparisons resist timing attacks. This fixes issue #563.
1 parent 096a34f commit f2bec20

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.