Search code examples
hashcryptographycomputer-sciencepassword-hash

Can we repeatedly hash an input and hash it indefinitely?


Was just wondering that if we are given an input string x and we hash it with function f to get f(x) can we repeat this process indefinitely i.e f(f(x)) and so on. Because most hash functions generate a different fixed output that is not the same as the input. So by this premise, would we be able to carry this out indefinitely? One possible issue I can think is that it has to be fixed length and usually hashes are shorter than the input? Please correct me if I am wrong. Would love an explanation!


Solution

  • Yes you absolutely can hash the prior hash output.

    When we do this with cryptographic keys it’s called ratcheting.

    The output size of the hashing algo will determine how many outputs you can rehash before you get a collision.

    Thus for a 256-bit hash function we will see a collision with 50% probability after 2^128 hashing calls.