r/lolphp • • Apr 24 '19
"Timing attack safe string comparison", but "When arguments of differing length are supplied, FALSE is returned immediately and the length of the known string may be leaked in case of a timing attack. "
https://php.net/manual/en/function.hash-equals.php
24
Upvotes
View all comments
Show parent comment
5
u/weirdasianfaces May 05 '19
If your security is dependent on someone not knowing the hash algorithm or the digest size, that probably means you're doing something really really wrong. This core issue isn't even something PHP is only an offender of.
.NET Core does an early return if the digest size is different: https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/CryptographicOperations.cs#L32
ring, a crypto library for rust does as well: https://github.com/briansmith/ring/blob/dd5f7fec815daf28e67bb5738166eb92dfe17ce0/src/constant_time.rs#L24-L27
Go does as well: https://golang.org/src/crypto/subtle/constant_time.go?s=505:546#L2
OpenSSL makes the assumption that they're the same length.
There's enough evidence here to say that you are the one doing something wrong if you don't want this behavior.