Even if they discover hash(b), they can't produce b.
Even if they discover hash(b), they can't produce b.
So if what you’re hashing has low entropy/randomness (say a password) then you can totally brute force it.
In fact if there’s not a salt you can look it up in a rainbow table, saving yourself some compute. Googling a hash also works sometimes. If you want to brute force look at hashcat.
Something like SHA256 protects about 128 bits of entropy. If you go much lower than that, you’ll be brute forced. You can look at hashcat benchmarks online to estimate the time and money necessary to perform the attack. Anyone can crack an average simple password using a single round of SHA256 in no time.
Of course it's way less impactful than discovering b, but it's nonetheless a vulnerability.
Consider what happens to the first byte of the hash if you add a new byte to the input, e.g. "1230"...
To be practical: my first guesses are:
0000...0000
1000...0000
2000...0000
...
f000...0000
I discover that c000...0000 takes slightly longer. Then, my next guesses are:
c000...0000
c100...0000
c200...0000
...
cf00...0000
Now I discovered that c700...0000 takes slightly longer...
And so on.
At the end I have the full hash.
Getting the plaintext key from that hash is a different problem.
UPDATE: damn, I understood what you mean now. Sorry. Yes, it will take a lot of computation to generate the good hashes.
This is not an easy problem, and in fact is what is used as proof-of-work for many cryptocurrencies.
There is no practical preimage attack against MD5, it would work fine in this case.