Suppose we have a value $secret
which is a random 56-bit (7-byte) string. Suppose an adversary wishes to discover $secret
. The adversary cannot directly see $secret
, but he can see substr(sha1_hex("$secret $salt"), 0, 8)
(where $salt
is public -- and perhaps irrelevant to our calculations).
Since $secret
is only 56-bit, it may be vulnerable to a brute-force attack by a modern supercomputer -- if you can find an offline test. An attacker might use the hash-prefix as a test:
function brute_force_hash_prefix($targetHashPrefix, $salt)
$candidates = array()
foreach possible $candidate which is 56-bits long
$candidateHashPrefix = substr(sha1_hex("$candidate $salt"), 0, 8)
if ($candidateHashPrefix == $targetHashPrefix)
$candidates->add($candidate)
return $candidates
However, the test is not deterministic -- the attacker only has the first 8 hex digits (32-bits) of the SHA-1 hash. This creates a risk of false-positives (ie the brute-force attack may return multiple $candidates
which all yield the same first 8 hex digits).
The question: statistically speaking, how many $candidates
should one expect to produce?
(Why would one care? If the odds are that only one $candidate
will come through, then it's basically over. Then again, if there are thousands or millions of candidates, then the attacker has narrowed the field... but still needs to find some additional means for testing/filtering $candidate.)
sha1_hex()
in hex, so each character is 4 bits of the hash, and the first 8 characters are the first 32 bits of the SHA1 hash? $\endgroup$