Code covered by the BSD License  

Highlights from
CalcMD5

4.71429

4.7 | 8 ratings Rate this file 59 Downloads (last 30 days) File Size: 12.5 KB File ID: #25921
image thumbnail

CalcMD5

by

 

23 Nov 2009 (Updated )

Another MD5 calculator as fast C-Mex

| Watch this File

File Information
Description

MD5 is a 128 bit message digest developped by the RSA Data Security Inc. and described in the RFC 1321.

This implementation calculates the MD5 sum for files, strings or byte streams (e.g. UINT8 arrays). The sum can be replied as [1 x 16] double vector, [1 x 32] hexadecimal number or as [1 x 22] base64 number.
For strings either ASCII or Unicode values are considered.

There are some MD5 implementations on the FEX already:
1. Michael Kleder's excellent java method for MD2, MD5, SHA-1/256/384/512 hashes:
  http://www.mathworks.com/matlabcentral/fileexchange/8944
The C-Mex CalcMD5 published here is faster: 90% faster for 10kB strings, 30% for 1MB strings, 40% for 10MB strings (see screen shot). In addition CalcMD5 can process files directly without the need of importing them to the memory.
2. Steven Huang's MD5 C-Mex:
  http://www.mathworks.com/matlabcentral/fileexchange/7919
This file has some bugs. After fixing them, the speed is similar, because it is based on the same public C-source from the RFC 1321. CalcMD5 handles Unicode strings and byte streams in addition. Huang's MD5 let FOPEN decide, if the input is a file name or a string.
3. Suresh Joel's tool calls an EXE file based on the same C-source:
  http://www.mathworks.com/matlabcentral/fileexchange/3432
It works for files only and not for arrays or strings directly. Calling EXE files can be restricted by virus protectors.
4. Some further MD5 tools on the FEX do not reply correct answers.

Summary: CalcMD5 does not add something really new to the FEX. The small advantages are just the speed, the possibility to access files and arrays with the same tool and the different output formats.

Pre-compiled DLLs (Matlab 6) and MEXW32 (Matlab >= 7.6) can be found at:
http://n-simon.de/mex

Now the MEX compiles for 64-bit addressing also, but currently arrays and files are limited to 2.1GB. Full 64 bit support is under construction.

Acknowledgements

Md5 Checksum and Md5 In Matlab inspired this file.

This file inspired Data Hash.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Can be compiled with the LCC shipped with Matlab
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
17 Jul 2014 Egor

Thanks, usefull tool!

21 Aug 2013 Eelke Spaak

Is there any progress on the support for large (> 2^31 bytes) variables? This would be very useful to me.

18 Jun 2013 David Hildebrand  
03 Mar 2012 Justin  
19 Jul 2011 Philip

Great job, thanks!

30 Dec 2009 Sebastiaan

Glad to hear :)

To make it 'public': Linux users compile with this:
mex CFLAGS="\$CFLAGS -std=c99" CalcMD5.c

29 Dec 2009 Jan Simon

Thanks Sebastiaan! The 64-bit bug is fixed (since 17-Dec-2009). Full 64-bit support is under development.
I like the C99 comment style with //, so your suggestion to add "-std=C99" for the GCC compiler works well.

15 Dec 2009 Sebastiaan

Nice functionality, but I have problems using this under Linux, and there is a bug:

First off, it is a C file with C++ style commenting: don't do that - users have to manually disable the -ansi option from their CFLAGS, which is on by default.

The bug is on 64 bit systems, where you assume that unsigned long int is 4 bytes - which is actually 8.

For correct implementation, replace line 104:
typedef unsigned long int UINT32; /* four byte word */
with
typedef UINT32_T UINT32; /* four byte word */

Using UINT32_T from tmwtypes.h assures 4 bytes on each system.

If you want, I can send you the updated file with C style commenting.

I am looking forward to the version which handles large files and arrays. Maybe I will make one in the future, but I know that LCC is not too happy with long long ints.

07 Dec 2009 Joerg Bretschneider

Great work! Compiling the mex went seamlessly. I used this to get some version control independent from buggy datenum.

Updates
17 Dec 2009

UINT32 has 4 bytes on 64-bit systems now. Thanks to Sebastiaan (34534)!

Contact us