md5sha1checksumdigest

Are there algorithms for putting a digest into the file being digested?


Are there algorithms for putting a digest into the file being digested?

In otherwords, are there algorithms or libraries, or is it even possible to have a hash/digest of a file contained in the file being hashed/digested. This would be handy for obvious reasons, such as built in digests of ISOs. I've tried googling things like "MD5 injection" and "digest in a file of a file." No luck (probably for good reason.)

Not sure if it is even mathematically possible. Seems you'd be able to roll through the file but then you'd have to brute the last bit (assuming the digest was the last thing in the file or object.)

Thanks, Chenz


Solution

  • The only way to do this is if you define your file format so the hash only applies to the part of the file that doesn't contain the hash.

    However, including the hash inside a file (like built into an ISO) defeats the whole security benefit of the hash. You need to get the hash from a different channel and compare it with your file.