Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support node 4 #23

Closed
hueniverse opened this issue Sep 5, 2016 · 9 comments
Closed

Support node 4 #23

hueniverse opened this issue Sep 5, 2016 · 9 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@hueniverse
Copy link
Contributor

No description provided.

@hueniverse hueniverse added the bug Bug or defect label Sep 5, 2016
@hueniverse hueniverse added this to the 3.1.1 milestone Sep 5, 2016
@hueniverse hueniverse self-assigned this Sep 5, 2016
@msingh025
Copy link

Dear Hueniverse,
Could you please review code block of
exports.fixedTimeComparison = function (a, b) {

if (typeof a !== 'string' ||
    typeof b !== 'string') {

    return false;
}

let mismatch = (a.length === b.length ? 0 : 1);
if (mismatch) {
    b = a;
}

for (let i = 0; i < a.length; ++i) {
    const ac = a.charCodeAt(i);
    const bc = b.charCodeAt(i);
    mismatch |= (ac ^ bc);
      if(mismatch != 0)
    break;
}

return (mismatch === 0);

};
I have added a check inside for , immediate break the loop at false conditions.
Please provide you valuable comment on it.

@Marsup
Copy link
Contributor

Marsup commented May 3, 2017

What does it have to do with this issue ?

@msingh025
Copy link

Not related to this issue , It was only enhancement .

@mtharrison
Copy link

@msingh025 this function fixedTimeComparison() is specifically designed to take the same time to execute on two same length strings whether they are equal or not. This is to prevent timing attacks.

@msingh025
Copy link

@mtharrison thanks a lot , we are on the same page, I have used it in our authentication module, before using it, i read and found, we are comparing strings char by char, I thought, I should break the loop on mismatched chars, so I added a extra line inside loop
if(mismatch != 0)
break;

@mtharrison
Copy link

@msingh025 why should you break on mismatched chars?

@msingh025
Copy link

@mtharrison bcz , I do not want iterate char till end of string's length. if const ac and const bc are not equal then defiantly both string a and string b is not equal to each other . Then I should break loop at that point.

@mtharrison
Copy link

That defeats the whole purpose of this function to be a fixed time comparison. If whether or not two strings are equal influences the running time of the function it is not running in fixed time and you might as well just be doing string1 === string2.

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

4 participants