473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Simple MD5 Hash - Different output on different OS

Hi All,

Should an md5 hash of the same string output the same hash on Windows
and Unix?

I downloaded md5.c from http://www.advogato.org/article/830.html and
compiled it on windows via cygwin and compiled it on Solaris 10.

Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99

Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437

Thanks for your time
Kind regards
Danny
Nov 20 '08 #1
10 7196
On 20 Nov, 10:16, Smurff <danny.kell...@gmail.comwrote:
Hi All,

Should an md5 hash of the same string output the same hash on Windows
and Unix?

I downloaded md5.c fromhttp://www.advogato.org/article/830.htmland
compiled it on windows via cygwin and compiled it on Solaris 10.

Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99

Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437

Thanks for your time
Kind regards
Danny
It certainly should.. A quick perusal of the webpage reveals that md5 -
t runs a self test, try this and see which version fails!
Nov 20 '08 #2
On Nov 20, 11:48*am, SozzlyJoe <capcl...@gmail.comwrote:
On 20 Nov, 10:16, Smurff <danny.kell...@gmail.comwrote:


Hi All,
Should an md5 hash of the same string output the same hash on Windows
and Unix?
I downloaded md5.c fromhttp://www.advogato.org/article/830.htmland
compiled it on windows via cygwin and compiled it on Solaris 10.
Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99
Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437
Thanks for your time
Kind regards
Danny

It certainly should.. A quick perusal of the webpage reveals that md5 -
t runs a self test, try this and see which version fails!- Hide quoted text -

- Show quoted text -
Thanks for the reply. You were right, the test on cygwin did infact
complete ok but on solaris I recieved this:

d41d8cd98f00b204e9800998ecf8427e << Expected Hash Value
227b7f48d21283f63bc9bbc15b44ea1a << Actual Hash Value
Self Test Failed
md5:007:Test Failure.
Do you believe it is because of this actual implementation and / or
should I look at using something like OpenSSL? Its just that this chap
made this very easy for me :)

Thank you again for your time
Kind regards
Danny
Nov 20 '08 #3
On 20 Nov, 12:02, Smurff <danny.kell...@gmail.comwrote:
On Nov 20, 11:48*am, SozzlyJoe <capcl...@gmail.comwrote:
Do you believe it is because of this actual implementation and / or
should I look at using something like OpenSSL? Its just that this chap
made this very easy for me :)
Not sure, to be honest. What compiler are you using on Solaris? Try
turning on all the warnings and look for anything suspicious.
If your compiler is not gcc, try using that instead.

Nov 20 '08 #4
Smurff wrote:
Hi All,

Should an md5 hash of the same string output the same hash on Windows
and Unix?

I downloaded md5.c from http://www.advogato.org/article/830.html and
compiled it on windows via cygwin and compiled it on Solaris 10.

Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99

Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437

Thanks for your time
The author of the code seems to have been unaware of
"endianness," that is, that different computers arrange
the individual bytes of multi-byte integers in different
ways. He seems also to have been unaware that `unsigned
long' might not be exactly four bytes. In short, you're
dealing with code that makes non-portable assumptions.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Nov 20 '08 #5
On Nov 20, 10:16*am, Smurff <danny.kell...@gmail.comwrote:
Hi All,

Should an md5 hash of the same string output the same hash on Windows
and Unix?

I downloaded md5.c fromhttp://www.advogato.org/article/830.htmland
compiled it on windows via cygwin and compiled it on Solaris 10.
<snip>

Out of interest I did the same and got the same problem. It worked on
a 32-bit system and failed on a 64 bit system. When I changed the
typedef for mULONG from 'unsigned long' to 'unsigned' the program (in
self test mode, -t option) started working on the 64 bit system,
where, incidentally, sizeof(unsigned) == 4 and sizeof(unsigned long)
== 8. I assume it is something about the program, md5, or both, that
requires 32 bit unsigned quantities. The code has a TRANSFORM macro
that suggests as much.

regards,
Stijn
Nov 20 '08 #6
Smurff wrote:
>
I downloaded md5.c from http://www.advogato.org/article/830.html and
compiled it on windows via cygwin and compiled it on Solaris 10.
The code at the link relies critically on the endiannes of the hardware
it is run on. It should work fine on any little-endian hardware, like
x86, but will not work correctly on any big-endian hardware, like Sun.
This is what you observe in your experiments.

They use 'memcpy' to transfer data from the input 'mUCHAR' buffer to the
internal MD5 buffer and then just re-interpret the latter as an 'mULONG'
array for further processing. This can't work as in on a big-endian system.

--
Best regards,
Andrey Tarasevich
Nov 20 '08 #7
Smurff <da***********@gmail.comwrites:
On Nov 20, 11:48*am, SozzlyJoe <capcl...@gmail.comwrote:
>On 20 Nov, 10:16, Smurff <danny.kell...@gmail.comwrote:


Hi All,
Should an md5 hash of the same string output the same hash on Windows
and Unix?
I downloaded md5.c fromhttp://www.advogato.org/article/830.htmland
compiled it on windows via cygwin and compiled it on Solaris 10.
Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99
Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437
Thanks for your time
Kind regards
Danny

It certainly should.. A quick perusal of the webpage reveals that md5 -
t runs a self test, try this and see which version fails!- Hide quoted text -

- Show quoted text -

Thanks for the reply. You were right, the test on cygwin did infact
complete ok but on solaris I recieved this:

d41d8cd98f00b204e9800998ecf8427e << Expected Hash Value
227b7f48d21283f63bc9bbc15b44ea1a << Actual Hash Value
Self Test Failed
md5:007:Test Failure.
Do you believe it is because of this actual implementation and / or
should I look at using something like OpenSSL? Its just that this chap
made this very easy for me :)
It looks like that implementation is buggy, or at best, non-portable.
You shouldn't have too much trouble finding a better one. OpenSSL
probably has a good one, but there should also be standalone
implementations.

Note that if you have a choice, you might be better off using something
like SHA256. MD5 has some known weaknesses.
Nov 20 '08 #8
Nate Eldredge <na**@vulcan.lanwrites:
Smurff <da***********@gmail.comwrites:
>On Nov 20, 11:48*am, SozzlyJoe <capcl...@gmail.comwrote:
>>On 20 Nov, 10:16, Smurff <danny.kell...@gmail.comwrote:
Should an md5 hash of the same string output the same hash on Windows
and Unix?

I downloaded md5.c fromhttp://www.advogato.org/article/830.htmland
compiled it on windows via cygwin and compiled it on Solaris 10.

Windows/Cygwin
$ ./md5.exe -s password
5f4dcc3b5aa765d61d8327deb882cf99

Solaris
bash-3.00$ ./md5 -s password
a4d85586adcf1688d921e38312c7e437
[...]
It looks like that implementation is buggy, or at best, non-portable.
You shouldn't have too much trouble finding a better one. OpenSSL
probably has a good one, but there should also be standalone
implementations.

Note that if you have a choice, you might be better off using something
like SHA256. MD5 has some known weaknesses.
<OT>
Both Cygwin and Solaris have their own "md5sum" command; it doesn't
have the "-s" option, but it's easy enough to do the same thing.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 20 '08 #9
All,

Thanks for all your comments. The author of the code is in contact
with me and I am happy to test any of his code on my sparc box. In the
mean time I am looking at OpenSSL. There is a lot there and no where
as easy to understand. Im not the greatest programmer :)

If anyone has any links to a standalone version as the one in this
thread then I would be very greatful.

Thanks again guys and have a great weekend
Danny
Nov 21 '08 #10
Smurff <da***********@gmail.comwrites:
Thanks for all your comments. The author of the code is in contact
with me and I am happy to test any of his code on my sparc box. In the
mean time I am looking at OpenSSL. There is a lot there and no where
as easy to understand. Im not the greatest programmer :)

If anyone has any links to a standalone version as the one in this
thread then I would be very greatful.
As I've already mentioned in this thread, there's an "md5sum" command
in both Cygwin and Solaris. A version is part of the GNU coretuils
package.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 21 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: barnesc | last post by:
Hi! Here's a simple hashcash implementation in Python. 28 lines of actual code. Can be reduced to 17 lines for instructional purposes, if you don't want clustering, and use xrange() instead...
6
by: Weiguang Shi | last post by:
Hi there, I'm thinking of using binascii.crc32 as a hash-function when I read in the reference http://www.python.org/doc/current/lib/module-binascii.html: crc32( data) Compute CRC-32, the...
3
by: Murali | last post by:
I have a requirement where I have to use two unsigned ints as a key in a STL hash map. A couple of ways to do this is 1. create a struct with two unsigned ints and use that as key (write my own...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
6
by: Joseph Lee | last post by:
Dear All, Is there a function in C# that will hash code a large byte array into an int value? I am searching for a hash function that will convert any size data(as for me the input is a byte...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
1
by: Wayne Deleersnyder | last post by:
Hi All, I was going to write and ask if someone could help me fix the formatting of my output for hash values, but I believe I got it right now. But, because I couldn't find any website or...
15
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.