# Preimage of SHA512 with a known suffix

Is it possible to figure out what $arg1 is if I know both $arg2 and $arg3 in addition to $hash?

$hash = hash('sha512',$arg1 . $arg2 .$arg3);

-

## migrated from security.stackexchange.comMay 12 '14 at 8:26

This question came from our site for information security professionals.

Assuming that . represents concatenation, no, except in the specific case that $arg1 is the empty string. You're trying to perform a preimage attack, which is one of the things that SHA512 is designed to be resistant to. Further, knowing $arg2 and $arg3 does not let you speed up a brute-force attack on $arg1, because for each candidate value for $arg1, $arg2 and $arg3 will modify the checksum differently. (If you knew $arg1 and $arg2 and were looking for $arg3, you could precompute the partial checksum of the first two values as the starting point for each try at finding $arg3) - The exception should not be: "$arg1 is the empty string" but rather: $arg1 is low entropy, including of small size, e.g. a password; in that case, it is possible to figure out $arg1 by exhaustive search. – fgrieu May 12 '14 at 13:19

Sure you can depending on the entropy contained in $arg1. For example, say you know $arg2=Will you marry me?

and $arg3=\r\n\r\nBob. If Bob has been dating two girls, say Alice and Trudy, you could guess that either $arg1=Alice,\r\n

or $arg1=Trudy,\r\n. A simple test of both possibilities will tell you the answer since you know $hash.

If $arg2 and $arg3 are known then $hash = hash('sha512',$arg1) has the same search space as $hash = hash('sha512',$arg1 . $arg2 .$arg3).

So if $arg1 has a small search space, you could do an exhaustive search. - +1 but I'm missing the part in the answer that states that this should not result in less search space than just hash('sha512',$arg1) (and the answer of Mark is missing this particular argument) – Maarten Bodewes May 12 '14 at 16:04
@owlstead It is the same search space as <code>hash('sha512', \$arg1)</code>. – mikeazo May 12 '14 at 16:09
You don't have to explain that to me :) edited into answer, if you don't mind. Hmm, maybe I should have switched the equations in the edit... – Maarten Bodewes May 12 '14 at 16:20
@owlstead, I see. I was missing your point. It is clear now. – mikeazo May 12 '14 at 16:27