Comments (18)
Mimicking the well designed itsdangerous:constant_time_compare:
constantEquals = function constantEquals(x, y) {
var result = (x.length === y.length ? 0 : 1),
length = Math.max(x.length, y.length),
i;
for (i=0; i < length; i++) {
result |= (x.charCodeAt(i) === y.charCodeAt(i) ? 0 : 1)
}
return result === 0;
},
I have not given this enough thought for it to be considered vetted, but I hope it may be a start.
-- There are two assumptions worth noting:
- The
charCodeAt
is the same speed whether or not the index is outside the bounds of the string (otherwise one could garner the length of the other string); - The comparison between strings is the same as the comparison between a string and undefined (same problem; possible workaround, assuming empty string compare is the same as a non-empty string compare:
result |= ((x.charCodeAt(i) || '') === (x.charCodeAt(i) || '') ? 0: 1)
)
from credential.
Hi,
Thank you!
Would you consider writing some tests for these ideas and submitting a pull request with a better implementation?
from credential.
BTW, there's a prize involved: #8 (comment)
from credential.
Many thanks @ericelliott -- I will try to have a look in the near future as I may, but of course will defer any prize benefit to anyone who posts a usable PR sooner than I. :) Cheers
from credential.
I really appreciate your help on this. I've added you as a collaborator. Please be sure that you get a security expert to sign off on every pull request before merging. If you need help finding one, ask me and I'll tap my contacts.
from credential.
Thank you @ericelliott, it is an honour (and a pleasure) to be of help on this. I will of course have any PRs vetted before merging. Cheers
from credential.
from credential.
Closing in favour of PR #13
from credential.
Reopening so that we can easily track all open issues. PR #13 does not have any corresponding open issue without this. =)
from credential.
from credential.
I'm not saying that constant time comparison is not important, but imho timing attacks are useful against fast operations (like hashing). pbkdf2 is designed to be slow, so the comparison time at the end of the algorithm is not really measurable.
I'm definitely not a crypto expert, so maybe I'm wrong
from credential.
I'm definitely not a crypto expert, so maybe I'm wrong
That's key here.. We all have some feelings but no data to back it up.
from credential.
A short-circuit of the pbkdf2 is definitely observable, even on the last comparison. You can verify this with a t-test like I've done in the constant comparison.
Remember, it's not the length of time it takes to run a test, but the difference (the delta) in times over a large set.
You can see this in the BlackHat 2010 presentation I referenced.
from credential.
from credential.
Well, now I'm not sure that we need constant time comparison in the first place:
http://security.stackexchange.com/questions/9192/timing-attacks-on-password-hashes
there is no danger doing short-cut comparison of salted hashes of passwords, if the salt is hidden to the attacker.
The attacker has no control over the result hash, he can change only the input. A small change in the input (eg. 1 bit) causes significant change in the result (every is flipped with 50% probability). With timing attack the attacker incrementally constructs the correct hash, but since he cannot construct arbitrary hashes, he cannot use timing attack to guess the correct hash.
from credential.
@madbence Yep. We are aware of this, but we have decided not to remove the feature in the short term. Maybe in the long term we'll strip it out, if we have enough confidence that the hashes are indeed protective against timing attacks. We'll probably want to prove that with tests.
from credential.
Sure, thanks for the info!
from credential.
http://php.net/manual/en/function.hash-equals.php
This newly added function suggests that hashes are vulnerable to timing attacks.. Confusing world.
from credential.
Related Issues (20)
- callback, promise or both HOT 10
- I can't make the cli work HOT 8
- Verifying with a pre-parsed JSON object HOT 4
- What if an attacker know that I am using this library? HOT 9
- The use of "time" - a weakness worth noting? HOT 13
- Why hash() just return string rather than object? HOT 2
- fix failing CI server
- Does it really needs webpack? HOT 7
- Node v6 deprecation - "crypto.pbkdf2 without specifying a digest is deprecated" HOT 3
- Release v2.0.0 on npm HOT 3
- Support bcrypt hashing method? HOT 1
- performance optimisation HOT 4
- Make errors programmatically processable HOT 7
- Do not encourage people to write security issue in public places HOT 1
- Default number of iterations seems extreme HOT 2
- Due to the large number of iterations, Its consuming the full CPU usage. HOT 7
- Update deps, freshen code, release new major version. HOT 7
- Bad default settings HOT 4
- the 'verify' function takes too much time, about 1.3 seconds HOT 2
- Inconsistent use of bytes length/encodings? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from credential.