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

SCrypt.Verify hash comparison vulnerable to a timing attack #24

Open
mbomb007 opened this issue Apr 26, 2018 · 0 comments
Open

SCrypt.Verify hash comparison vulnerable to a timing attack #24

mbomb007 opened this issue Apr 26, 2018 · 0 comments

Comments

@mbomb007
Copy link

mbomb007 commented Apr 26, 2018

See DefaultPasswordHash.cs

public bool Verify(string password, string hash)
{
    return hash == HashPassword(password, hash);
}

When you compare the hashes using ==, the comparison logic uses early-out optimization so that if the first character of both strings are different, the comparison ends abruptly returning false. If only the last character is different, the comparison gets that far (taking a bit longer) and returns false. So an attacker can send specific known hashes, record the differences in comparison time, and figure out the correct hash one character at a time.

A simple solution is to perform a byte-to-byte (or char to char) comparison in constant time with no optimization so that the entire string is compared. The recommended solution is probably to use Double-HMAC Comparison. There is an example in Security Driven .NET by Stan Drapkin, which makes use of Inferno (which makes use of System.Security.Cryptography.HMAC).

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant