views:

131

answers:

7

Today I read about MD5 hash and was wondering if this is possible. seems like a recursive problem... or is there a solution?

+1  A: 

You must exclude the hash sum from the calculation. Then you have use it, but you cant add the hash rum til the end of the file expecting it to be correct, or if you calculate the run over new yu will always end ut with a new MD5 hash. Ening up in a never ending story :)

eaanon01
+4  A: 

Well, as soon as you fill in the MD5 sum the file will change and get a new MD5 - so: no, it is not feasible. In theory just trial-and-error could lead to a document that contains its own hash ... but the document would be probably quite garbled and not contain anything meaningful.

But it is possible to fill 128 bit with zeros (for instance) during calculation. This place will hold the MD5 sum and has to be zero again, when verifying the hash later.

tanascius
addendum: It's not feasible **that we know of**. It's quite possible that some future mathematical supergenius will devise a way to quickly construct such a file.
BlueRaja - Danny Pflughoeft
@BlueRaja: See [here](http://www.mscs.dal.ca/~selinger/md5collision/).
sbi
@sbi: that has nothing to do with this duscussion...
BlueRaja - Danny Pflughoeft
A: 

It's not possible.

But you can rename the file according to the hash of its contents, which attaches the information without changing the hash.

Ed Guiness
A: 

Well, adding a MD5 hash to a text changes the text, and thus the MD5 hash. Computing an MD5 hash of your text-including-the-to-be-computed MD5 hash is not possible.

jschulenklopper
+3  A: 

Consider any hash and imagine adding some random text to it. Since there is an infinite amount of possible texts you could add, but only a finite amount of possible hash values, there must be possible texts which yield the hash. The problem is just that you might not have enough resources to find it.

What you might be able to try is whether there are any MD5 hash values that, when hashed, yield themselves as a result (thanks to Francesco for that link!):
For all possible permutations of an MD5 hash, create the hash and compare the result with the original.

sbi
That is, does the MD5 hash admit a fixed point? See http://stackoverflow.com/questions/235785/is-there-an-md5-fixed-point-where-md5x-x
Francesco
@Francesco: Thanks for the link, I added it to the answer.
sbi
I was thinking more of in these terms:md5(crap + x) == x?I mean a .doc containing other stuff + the MD5 hash info at the end.
bakra
@bakra: That's what my answer's first paragraph is all about.
sbi
+1  A: 

In theory, it's possible: possible file contents are infinite, possible hashes are not. In practise, being able to accomplish it would mean you've found a vulnerability in the algorithm, thus rendering the hash useless for security purposes.

Álvaro G. Vicario
A: 

This is very easy to get around. Have the first few bytes of the file be the md5() hash. Remove this have before calculating the checksum. Although you taking a hash of the hash isn't practical or useful, you can still convey a message with its corresponding checksum.

Rook