If I know the hashes of two parts of some data, can I calculate the hash of the full data from those hashes?

StackOverflow https://stackoverflow.com/questions/5869742

  •  28-10-2019
  •  | 
  •  

If I know the hashes of two (or more) parts of some data, can I calculate the hash of the full data from those hashes?

Which hash types can this be done for? SHA1, SHA256, MD5? (Security of hashes is not important for my use case.)

i.e.

data0 = '0123'
data1 = '45678'
all_data = data0 + data1
hash0 = hash(data0)
hash1 = hash(data1)

Does fn exist such that

hash(all_data) == fn(hash0, hash1)

Does fn exist for MD5, SHA1 or SHA256?

Thanks,

Chris.

有帮助吗?

解决方案

Short answer. No.

Hashes are completely different for minimal deviations and untill you can't calculate them back this won't work. Even if you can calculate them back, the result will be a list of possibilities you can choose from. So there is nothing deterministic.

其他提示

Hashing through data0 puts the system in some intermediate state. Your hash(data1) was calculated from a clean state. You cannot fix hash1 to make up for that missing intermediate state (for a good hash function).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top