3

I know it sounds strange.. but, are there any ways in practice to put the hash of a PDF file in the PDF file? And after geting the hash in the PDF file - if someone would do a hash check of the PDF file, the hash would be the same as the one that is already in the PDF file? :) maybe with MD5, since it's known to have weaknesses? Example:

[user@notebook ~] wget -q http://renyi.hu/~csirmaz/nws06/xajanlo.ps -O Md5-xajanlo.ps; wget -q http://renyi.hu/~csirmaz/nws06/xutasit.ps -O Md5-xutasit.ps; md5sum Md5-xajanlo.ps; md5sum Md5-xutasit.ps; sha512sum Md5-xajanlo.ps; sha512sum Md5-xutasit.ps; rm Md5-xajanlo.ps Md5-xutasit.ps
583bdceb34826c38ac7f1fdac3aca807  Md5-xajanlo.ps
583bdceb34826c38ac7f1fdac3aca807  Md5-xutasit.ps
c82d26f77ccd4597622fc985d4220aedad6f866555c6db82db2d6d17e22016268a3e88d0b0cd89a8e536ae7d666c446edeb77edef2fca783739e4bff9d7032be  Md5-xajanlo.ps
205c18b396bee84995d8c325787600ca88ca3d9758c4dfe89cdaa242ab9513710057c5fce55afb2c6ef3117703be7c31266a1fa6fbac1f369b82f0719587c60c  Md5-xutasit.ps
[user@notebook ~] 
newuser999
  • 133
  • 1
  • 3
  • And what happens if i simply modify the pdf and replace the hash that you have put into the pdf file accordingly? ;) I guess signing the pdf file is what you are looking for. – DrLecter Nov 22 '13 at 07:43
  • 3
    it seems that you are asking a way to solve this equation $H(a*)=a$ – T.B Nov 22 '13 at 07:56
  • Could you explain your motivation if you would like to do what Alex assumes? – DrLecter Nov 22 '13 at 08:02
  • @DrLecter: good point :) – newuser999 Nov 22 '13 at 08:08
  • The question is the question, nothing else, just want to know if it could be done – newuser999 Nov 22 '13 at 08:10
  • Technically it might be possible (mathematically it's definitely possible?) to construct two documents with the same hash, where one of the documents contains that hash value. Even with the known problems with MD5 collision resistance though, this seems improbable - it's not simply finding a collision, but finding a collision that contains the colliding hash in a specific location in one of the sources. – archie Nov 22 '13 at 08:43
  • 1
    See this question: http://crypto.stackexchange.com/questions/9910/is-it-theoretically-possible-to-construct-a-string-that-contain-its-own-hash-val – Cryptographeur Nov 22 '13 at 10:35
  • With CRC yes, with MD5 no. Standard practice for similar applications is to ignore the hash or signature part while hashing. – CodesInChaos Nov 22 '13 at 10:43
  • Technically, I believe this is actually doable, in a roundabout way. PDF can contain JavaScript, which is a Turing-complete programming language, so it should be possible to write a PDF+JS quine. MD5 (and other hash functions) can also be implemented in JavaScript, so it should be possible to create a PDF+JS document that computes its own MD5 hash and displays it. Actually doing that is left as an exercise. – Ilmari Karonen Apr 26 '17 at 15:39

1 Answers1

4

You cannot push the hash of a file 'in' the file, as newly modified file will have a different new hash....

As said, it seems that you are asking a way to solve this equation H(∗∗a∗∗∗)=a

fgrieu
  • 140,762
  • 12
  • 307
  • 587
131
  • 156
  • 3
  • 1
    Kudos for giving an answer to the question as worded, and sorry that I initially missed that. – fgrieu Nov 22 '13 at 21:50