Lets say for example I used a function such as:
int someHash(string someValue)
{
return crc32(someValue) + 10 - 5 * 20;
}
How easy would it be to deduce how the hash was manipulated in order to reproduce the same hash value?
Lets say for example I used a function such as:
int someHash(string someValue)
{
return crc32(someValue) + 10 - 5 * 20;
}
How easy would it be to deduce how the hash was manipulated in order to reproduce the same hash value?
This depends on the transformation. In the case of your someHash
function, this is very easy. Notice that the transformation you are applying is an easy linear function. Your transformation can be expressed as:
Where h' is the new hash and h is the original hash. If you have one hash and its altered hash, you can solve the equation for c. (c = h' - h = -90
).
This example is one of many, why we often say that rolling your own crypto is often not a really good idea. The scheme actually needs two properties:
The attack mentioned above is one reason why 1. is important. In this case, the transformation has a very clear structure, which we can easily exploit.
2. is needed, because even if we did not have a scheme that had this structure, we can still enumerate over c
. After having tried a really small amount of numbers, we still find the constant c = -90
.
This does not mean that this is impossible. Quite the contrary: We use a block cipher to re-encrypt the hash. This works, because a block cipher produces an output that looks random and it takes a randomly generated ≥128 bit key, (which is large enough such that it cannot be guessed easily).