views:

42

answers:

3

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

A: 

No, because that would mean that the hash would have to be a hash of itself, which is not possible.

kb
eh... possible, but not cost effective because you'd have to somehow brute it.
Crazy Chenz
i can't see how it is possible without relying on finding a collision, but maybe that's what you mean by brute forcing? to find a scenario where hash(data+hash) and hash(hash) gives the same output?
kb
@kb: Yes, it is possible, just the way you have put it. for (x=0; x< 2**160; x++) {if SHA1(data || x) == x {print "Success" + x; break} } if (x==2**160) {print "Failure")}pretty silly, huh?
GregS
haha yeah ok, i stand corrected then. thanks for not downvoting. ^__^
kb
A: 

What you are asking is impossible, but if you are looking for insurance on you data, most compression programs (rar, zip, etc...) contain their own hashes and error correcting stuff built in.
Checkout the Wiki on RAR.

zdav
+2  A: 

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.

Nathan Kidd