I have noticed that different implementations of SHA1 give different results. As I'm currently programming my own SHA1 implementation (in MATLAB / GNU Octave), I wonder which one should I follow?
There are several implementations of SHA1 in Rosetta Code. Using the message
Rosetta Code, most of them give SHA1 hash of
There is also Tools for Noobs Online sha1() function, that gives the same hash as the examples in Rosetta Code.
In Rosetta Code, there are also two examples of computing SHA1 in Unix shell:
In my own computer (Debian Linux Wheezy amd64),
echo 'Rosetta Code' | sha1sum gives a SHA1 hash of
echo 'Rosetta Code' | openssl sha1 also gives the same hash.
However, the Rosetta Code examples of computing SHA1 in Unix Shell use different message:
ASCII string . According to Rosetta Code,
echo -n 'ASCII string' | sha1 should give
echo -n 'ASCII string' | openssl sha1 | sed 's/.*= //' should give the same hash. When I try
ASCII string as message in Tools for Noobs Online sha1() function, it gives the same hash as the examples of Rosetta Code on computing SHA1 in Unix shell. So I can conclude that all these implementations of SHA1 in Rosetta Code and also Tools for Noobs Online sha1() function give identical hashes.
In my own computer, using the message
ASCII string I get the hash
4f9e000b925f5d96def1d9b3e21cdc11f1df6139 either by
echo 'ASCII string' | sha1sum or
echo 'ASCII string' | openssl sha1.
So, of all these implementations, only my own computer's
openssl sha1 differ from the examples of Rosetta Code and Tools for Noobs Online sha1() function. Has this something to do with the UTF-8 vs. ASCII, processor type, endianness, message suffixing differences or is there something wrong in my Linux configuration?