Long back, I own a Cyrix machine and periodically it stops booting by showing the message – “Checksum failure“. I still remember those long beeps. :) Well, Checksum is digest generated from a long data which can be used to check the integrity of data.

For instance, if you want to know whether your data file is corrupted, generate and keep the checksum and afterwards for verification again generate the checksum and compare. So how to generate the checksum?


You can use the function – CheckSumMappedFile(). Actually its used to calculate the checksum of mapped file. Well, you can use it to calculate the checksum of your data too! Just see the code snippet.

// The data.
char* pString = "Hello";
DWORD HeaderSum = 0;
DWORD Checksum = 0;

// Calculate the checksum.
CheckSumMappedFile( pString,
                    strlen( pString),
                    &HeaderSum,
                    &Checksum );


The return of the function is PIMAGE_NT_HEADERS and in this case, it will be 0 and just ignore it. Since our data provided is not a valid PE file, its obvious. If you check the Checksum variable, you can find it contains a valid checksum always. So Take care!


Targeted Audience – Intermediate.