Giter Site home page Giter Site logo

Comments (18)

brianmhunt avatar brianmhunt commented on June 12, 2024

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:

  1. 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);
  2. 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.

ericelliott avatar ericelliott commented on June 12, 2024

Hi,

Thank you!

Would you consider writing some tests for these ideas and submitting a pull request with a better implementation?

from credential.

ericelliott avatar ericelliott commented on June 12, 2024

BTW, there's a prize involved: #8 (comment)

from credential.

brianmhunt avatar brianmhunt commented on June 12, 2024

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.

ericelliott avatar ericelliott commented on June 12, 2024

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.

brianmhunt avatar brianmhunt commented on June 12, 2024

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.

ericelliott avatar ericelliott commented on June 12, 2024

👍

from credential.

brianmhunt avatar brianmhunt commented on June 12, 2024

Closing in favour of PR #13

from credential.

ericelliott avatar ericelliott commented on June 12, 2024

Reopening so that we can easily track all open issues. PR #13 does not have any corresponding open issue without this. =)

from credential.

brianmhunt avatar brianmhunt commented on June 12, 2024

👌

from credential.

madbence avatar madbence commented on June 12, 2024

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.

tjconcept avatar tjconcept commented on June 12, 2024

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.

brianmhunt avatar brianmhunt commented on June 12, 2024

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.

ericelliott avatar ericelliott commented on June 12, 2024

👍

from credential.

madbence avatar madbence commented on June 12, 2024

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.

ericelliott avatar ericelliott commented on June 12, 2024

@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.

madbence avatar madbence commented on June 12, 2024

Sure, thanks for the info! 👍

from credential.

tjconcept avatar tjconcept commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.