LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 09-09-2022, 12:14 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,237

Rep: Reputation: 88
Can a container contain its own hash?


I assume it's impossible, but maybe I am wrong...

Is it possible for a container to contain the hash of its own content?

For example, a document (PDF or any format) states among other things:
"The md5 hash of this document is ed4f489876105b369cc7628fc3841579"

Then you run the file/document through md5sum and get ed4f489876105b369cc7628fc3841579.

Or a program/script/executable that prints out its own hash.

It could be md5 or any other hash algorithm.

Is there a way to lock a drawer with the key inside?

Note: I found just a few discussions on Google and found them all not clear enough or conclusive.

Last edited by lucmove; 09-09-2022 at 12:17 AM.
 
Old 09-09-2022, 01:14 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,078

Rep: Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665Reputation: 2665
You can write a prog/script that will generate it's own hash as output, but if you put the result back inside the file as a literal, that will of course change the file's hash.

HTH
 
Old 09-09-2022, 08:31 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,925
Blog Entries: 4

Rep: Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587Reputation: 3587
The only way to avoid this would be to write the algorithm to search the data for an occurrence of the known hash-string, or perhaps for a set of markers surrounding it, and to omit those bytes from the hash calculation: hashing first the bytes leading up to the marker, then the bytes following it.
 
Old 09-09-2022, 09:40 AM   #4
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,237

Original Poster
Rep: Reputation: 88
Quote:
Originally Posted by sundialsvcs View Post
The only way to avoid this would be to write the algorithm to search the data for an occurrence of the known hash-string, or perhaps for a set of markers surrounding it, and to omit those bytes from the hash calculation: hashing first the bytes leading up to the marker, then the bytes following it.
Interesting idea! I would never think of that. Thank you.
 
Old 09-09-2022, 10:26 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,655

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
Quote:
Originally Posted by lucmove View Post
Is it possible for a container to contain the hash of its own content?

For example, a document (PDF or any format) states among other things:
"The md5 hash of this document is ed4f489876105b369cc7628fc3841579"

Then you run the file/document through md5sum and get ed4f489876105b369cc7628fc3841579.
It's possible in the sense that there is some string which you could append to "The md5 hash of this document is ed4f489876105b369cc7628fc3841579" in order to make the statement true. However, finding the string for existing cryptographic algorithms is intractible (finding it would constitute a successful Preimage attack). It should be doable with crc32 or something like that though.
 
Old 09-09-2022, 11:57 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,633

Rep: Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024Reputation: 5024
Quote:
Originally Posted by lucmove View Post
Or a program/script/executable that prints out its own hash.
Well, that, at least...

Code:
❯ cat myownhash.sh 
#!/usr/bin/env bash
md5sum $0

❯ md5sum myownhash.sh
5bc550ed629d5f7cbf00ed93ad1e8363  myownhash.sh

❯ ./myownhash.sh 
5bc550ed629d5f7cbf00ed93ad1e8363  /home/dugan/Documents/myownhash.sh

Last edited by dugan; 09-10-2022 at 12:38 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Chakra Linux: Its Own Beast, Its Own Beauty LXer Syndicated Linux News 0 08-18-2017 05:42 PM
LXer: Microsoft has created its own FreeBSD. Repeat. Microsoft has created its own FreeBSD LXer Syndicated Linux News 0 06-09-2016 11:42 AM
LXer: Microsoft has developed its own Linux. Repeat. Microsoft has developed its own Linux LXer Syndicated Linux News 0 09-18-2015 04:51 PM
[SOLVED] How to find files that contain one string, but don't contain another. PatrickDickey Linux - Newbie 2 09-11-2011 06:00 AM
Using hash value as key for other hash in Perl scuzzman Programming 6 02-14-2006 05:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration