Is there any hash structure that can be used for secure download of a file and validation of its contents?
Looks like all hashes like MD5 are made for consistency check and are vulnerable to hash extension attack, so it is possible to create another file with the same MD5 by just appending to the end of it.
I am writing an automated service that downloads data over insecure channels and I want to make sure that MITM can not alter file.
UPDATE: Hash is transferred to the user through secure channel. Right now I am using hash + filesize combination, to avoid hash extension attacks. Is it possible to use just single hash function?
UPDATE 2: I misunderstood what a length extension attack is. Quoting @CodeInChaos:
It does not give you a collision, it merely allows you to compute the hash of a longer file given the hash of a shorter file whose contents you don't know
So it is not possible to just append to file with existing hash to get the same hash. Doing this will mean looking for collisions in a longer file, so the question boils down to classic "how strong is the hash function". On the other hand, it is still interesting why SHA3 is not vulnerable to hash extension, but that's another topic.