What's new

Hash Calculator

mudlord

Banned
Finally, here it is.

This application is a hash calculator that can fingerprint files with the following checksum algorithms:

* MD2
* MD4
* MD5
* SHA-1
* SHA-2
* CRC32 (uses the lookup table from ZLIB)

This program is built off my new Win32 applications toolkit. Several tricks have been used to attain the small filesize, without resorting to EXE packers. NO MFC or .NET DLLs are used.

http://athene.csu.edu.au/~bmille16/files/hashcalc.exe

Enjoy!
 

xtra krazzy

Dolphin Developer
Too bad the application doesn't start.. Wanted to test your toolkit (Running on vista, error while opening with the address of 0x00000018).

Nonetheless, this is a great idea, especially for USB drive/general mobility.
 
OP
mudlord

mudlord

Banned
It must not like the PE alignment trick I used....Vista must be very picky about PE section alignment then....

Works on XP SP2 perfectly.
 
OP
mudlord

mudlord

Banned
Brilliant, the reason it was not working was due to how I was initialising through WinMain..... Fixed that.
 
OP
mudlord

mudlord

Banned
Okay, I fixed the CRC32 algorithm and added Drag N' Drop support :)

Link is still the same.
 

xtra krazzy

Dolphin Developer
The link may stay the same but it doesn't work for me... Again. :|
The old, non-drag'n'droppable, attached version is still working for me though.
 
OP
mudlord

mudlord

Banned
Well, lets think this all through. Right....

* Main WinMain uses plain ol' DialogBox to handle the TestDlgProc.
* The dialogproc handles Drag N' Drop as well as file loading. Drag and drop is down in the app like this:
Code:
case WM_DROPFILES:
				DragQueryFile((HANDLE)wParam, 0, buffer, sizeof(buffer) / sizeof(char) - 1);
			        DragFinish((HANDLE)wParam);
				    CheckFile(buffer);
				    break;

Notice CheckFile(buffer). CheckFile() is a function that uses const char* path as the pointer to handle file I/O. This pointer is then used in the hash algorithms to handle the path and perform the actual handling. Before, I used CheckFile(HWND hwnd, char* file), due to the need to use SetDlgItemText(). Now I use GetForegroundWindow() to handle that, so I can remove the need to check windows contexts by passing a parameter.

fopen() in the app presumes the char* buffer is a file. If it isnt, the app will crash since I didnt add exception handling yet for the case my fd* pointer fails for checksum calculation. The CRC32 algorithm doesn't use malloc() for buffers. It instead reads the file into the hash buffer, and then the checksum is calculated when that buffer fills. MD5/SHA1 algorithms though use malloc() to make the buffers and theres no memory leaks.

So I'm at a loss when it doesnt work for you, when it does for me fine....:(
 

xtra krazzy

Dolphin Developer
So I'm at a loss when it doesnt work for you, when it does for me fine....:(

All that long post because of a huge misunderstanding...
The file in the link doesn't execute for me, just like it didn't before you made another file and attached it in this thread, which works.

By the way, isn't CRC calculation incremental? (W/O buffers) (I once found an algorithm which belongs to some adlib(same as old sound cards?) or something of the sort which was O(n) and incremental)
 
OP
mudlord

mudlord

Banned
Yes, CRC calculation is incremental.

However:

Code:
int CheckCRC32 (char *file)
{
	#define SIZE_HASH_BUFFER  16384
	FILE        *fd;
	unsigned long m_crc32;
	unsigned char pBuf[SIZE_HASH_BUFFER];
	unsigned long readbuffer = 0;
	if( ( fd = fopen( file, \"rb\" ) ) == NULL )
	{
	SetDlgItemText(GetForegroundWindow(),IDC_CRC, \"Can\'t create CRC32 checksum\");
    return( 1 );
	}
	crc32Init(&m_crc32);
	while(1) {
		readbuffer = fread(pBuf, 1, SIZE_HASH_BUFFER, fd);
		if(readbuffer != 0)
		{
			crc32Update(&m_crc32,pBuf,readbuffer);
        }
        if(readbuffer != SIZE_HASH_BUFFER) break;
	
    }
	crc32Finish(&m_crc32);
	fclose(fd);
	sprintf(pBuf,\"%08X\",m_crc32);
	SetDlgItemText(GetForegroundWindow(),IDC_CRC, pBuf);
	SetDlgItemText(GetForegroundWindow(),IDC_FILE, file);
	fd = NULL;
}

As you can see, I use a 16MB buffer.

Other algorithms are done as follows:

Code:
void CheckFileHash (char *file)
{
    int i, x;
    unsigned char retmd5[33],
                  md5h[16],
				  sha1h[32],
				  sha2h[32],
				  retsha1[33],
				  retsha2[33];
    const char  *hex = \"0123456789ABCDEF\";
    SetDlgItemText(GetForegroundWindow(),IDC_FILE, file);
    md5_file( file, md5h );
    
    for(i = 0, x = 0; i < 16; i++) {
        retmd5[x++] = hex[md5h[i] >> 4];
        retmd5[x++] = hex[md5h[i] & 0xf];
    }
    retmd5[x] = 0;
    SetDlgItemText(GetForegroundWindow(),IDC_MD5SUM, retmd5);

  
	sha1_file( file, sha1h );

    for(i = 0, x = 0; i < 16; i++) {
        retsha1[x++] = hex[sha1h[i] >> 4];
        retsha1[x++] = hex[sha1h[i] & 0xf];
    }
    retsha1[x] = 0;
    SetDlgItemText(GetForegroundWindow(),IDC_SHA1, retsha1);

	sha2_file( file, sha2h, 0 );

    for(i = 0, x = 0; i < 16; i++) {
        retsha2[x++] = hex[sha2h[i] >> 4];
        retsha2[x++] = hex[sha2h[i] & 0xf];
    }
    retsha2[x] = 0;
    SetDlgItemText(GetForegroundWindow(),IDC_SHA1256, retsha2);
	
	
}


And for the curious, init code is here:
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
DialogBox (hInstance, MAKEINTRESOURCE(IDD_DLG1 ), 0, TestDlgProc);
}

Code:
BOOL APIENTRY TestDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam) 
        { 
    switch (message) 
        { 
                // Initialize the dialog box 
            case WM_INITDIALOG: 
                        {        

                        }break; 
            case WM_DROPFILES:
					DragQueryFile((HANDLE)wParam, 0, buffer, sizeof(buffer) / sizeof(char) - 1);
			        DragFinish((HANDLE)wParam);
				    CheckFileHash(buffer);
					CheckCRC32 (buffer);
				    break;


                // Process command messages 
            case WM_COMMAND: 
				switch(LOWORD(wParam))
                        { 
                        // Validate and Make the changes 
                       
			case IDC_LOADFILE:
				 DoOpen();
                        break;
                }break;
                // Closed from sysbox 
                case WM_CLOSE: 
                EndDialog(hDlg,TRUE); 
                break; 
                } 

        return FALSE; 
}

Might as well post the whole lot :|
 

xtra krazzy

Dolphin Developer
The link works perfectly now... Great tool. Consider adding a "last modified" timestamp or something of the sort.

I will be using this tool for file comparisons. Thanks
 

Toasty

Sony battery
@mudlord: If you want an additional challenge you might try including support for some of the more esoteric algorithms out there. The ED2K hashing algorithm (not the MD4 hash, but the AICH one) took me quite a while to do, as documentation is pretty scarce, particularly on just how the hash tree is supposed to be structured. Anyway, just a thought - great work on a nice, compact hash calculator!
 
OP
mudlord

mudlord

Banned
Hmm, I'm certainly interested in adding more hashes.....

My goal next is to add support for:

* Adler32
* Tiger
* Panama
* RIPEMD-320
* CRC16
* MD4 as well as the ED2K hashes

I might add file comparing support too.
 
OP
mudlord

mudlord

Banned
Well, here's the update:

Now it supports:

* Adler-32
* MD2
* MD4
* Panama
* RIPEMD160
* SHA256
* SHA384
* SHA512
* Tiger

I'm currently in the process of adding support for ED2K hashes....
 

xtra krazzy

Dolphin Developer
This window is getting way too big for a lightweight program... Care to add a hash selection checklist or something of the sort? I just really liked the compact design.
One more thing (only if you have the will and time): Could you please uppercase the hex? Thanks in advance...

EDIT: Well, now I remembered that you are using dialogs, therefore my suggestion is impossible.

Good luck with the ed2k hashes!
 
Last edited:

Toasty

Sony battery
There are probably hundreds of hashing calculators out there, but this is mudlord's hashing calculator. :p
 
OP
mudlord

mudlord

Banned
There is another Hash Calculator: www.slavasoft.com/hashcalc/index.htm
Support of 12 well-known and documented hash and checksum algorithms: MD2, MD4, MD5, SHA-1, SHA-2( 256, 384, 512), RIPEMD-160, PANAMA, TIGER, ADLER32, CRC32 + eDonkey/eMule checksums.

Wow...thats quite impressive, and it supports the ED2K hashes...Funny thing with those hashes, theres not much public info on them,might as well get the Emule source and dig around in it...Also, me programming this calculator has been a nice practical use of cryptography theory :p, so I dont see the issue of more calculators being brought into this world.

When I first coded this, I just wanted a basic MD5/CRC32 calc. Now its gone way beyond what I need in one. Well, least some people find it useful.

On a practical note, I might split the app in two. Mainly due to speed, because of how intense calculating 256-512bit keys are.
 
Last edited:

Top