Home
Writeups Misc About
Hash Stuffing

Hash Stuffing

Clearly the scheme given is not a hash function, in the sense that it is very easy to invert the function to obtain the original message. Hence, with any arbitrary hash, we can easily construct a message with that hash by inverting the operation.

Python Implementation:

Other solution take advantage of the flaw in the padding function, kudos to unblvr:

What this function does, is to pad the current block up to a full block size, by appending the number of missing bytes, not unlike the padding scheme in PKCS#7. The flaw, however, is that a block of the correct size has nothing added to it. This is why in PKCS#7, a message of the correct block size has another padding block appended to it.

This gives us a easy attack, in particular:

And the two messages are obviously different, one with 63 bytes and one with 64 bytes. After padding, the two messages are the same, as \x01 is appended.

Lastly, a cool solution from aloof, taking advantage of Sage (or more specifically the symbolic evaluation), to observe the patterns in the output of the hash:

Sage Implementation:

The output is something like:

The z are the constants, hence our task is to find values such that xa+xb is the same. A trivial solution is for a,b0,63, xa=xb=0 and xa=xb=1

This leads to the solution of: