PDA

View Full Version : embedding an md5 checksum in a file


Steve Canfield
07-23-2003, 08:20 AM
I have a C++ program to which I would like to add an integrity check.
Basically, I would like the executable to calculate it's own MD5
checksum and compare it to an expected value.

typedef something MD5SUM;

// returns true if the sums are identical
bool CompareMd5Sum(const MD5SUM& s1, const MD5SUM& s2);

// returns true if this executable has a valid MD5 sum
bool ValidateExecutable()
{
MD5SUM expectedValue = "349823490ad;adsf"
MD5SUM exeValue = CalculateMyMd5();
return CompareMd5Sum(expectedValue, exeValue);
}

This would be used to check the integrity of the executable (granted,
it's a rather coarse, crude check, but hopefully simple). This could
help us check for corrupted executables produced by dongle hacks,
viruses, or just installation failures.

I'm afraid this might be impossible. If you strip away all of the
executable except for the MD5 sum, I think I'm asking for a way of
finding a checksum that is it's own checksum.

Any ideas?

steve

LJ
08-23-2003, 06:35 AM
Steve Canfield wrote: I have a C++ program to which I would like to add an integrity check. Basically, I would like the executable to calculate it's own MD5 checksum and compare it to an expected value. typedef something MD5SUM; // returns true if the sums are identical bool CompareMd5Sum(const MD5SUM& s1, const MD5SUM& s2); // returns true if this executable has a valid MD5 sum bool ValidateExecutable() { MD5SUM expectedValue = "349823490ad;adsf" MD5SUM exeValue = CalculateMyMd5(); return CompareMd5Sum(expectedValue, exeValue); } This would be used to check the integrity of the executable (granted, it's a rather coarse, crude check, but hopefully simple). This could help us check for corrupted executables produced by dongle hacks, viruses, or just installation failures. I'm afraid this might be impossible. If you strip away all of the executable except for the MD5 sum, I think I'm asking for a way of finding a checksum that is it's own checksum. Any ideas?

CalculateMyMd5() has to know where the expected-value literal is and
not include it as input to the MD5 hash. This may not be as impossible
as it sounds. The offset from the beginning of the file to the literal
may be stable.

--Mike Amling


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service