jedisct1 / libsodium

A modern, portable, easy to use crypto library.
https://libsodium.org
Other
12.15k stars 1.73k forks source link

Error from argon2_hash() during verify propagated. #1039

Closed martingd closed 3 years ago

martingd commented 3 years ago

When verifying a password, argon2_verify() calls argon2_hash() to recreate the hash to compare. The recreated hash is then compared to the stored hash.

However, argon2_hash() could fail, e.g., because of an out-of-memory condition. In this case, the existing code will return ARGON2_VERIFY_MISMATCH instead of the error reported by argon2_hash(). This will cause the client code of libsodium to incorrectly believe the password did not match and report that back to the user.

With this patch, argon2_verify() will propagate the error from argon2_hash() if it fails. Only if it argon2_hash() succeeds, the existing hash and the recreated hash will be compared and if not matching ARGON2_VERIFY_MISMATCH will be returned.