Question

Suppose that I wrote an implementation of a standard algorithm such as an MD* or a SHA*: How I know that it's correct ? Different implementations of the same algorithm must produce the same digest ?

Was it helpful?

Solution

The reference documents themselves contain a small number of example cases, which can be used. (The hash of "abc" is in all of the reference documents, for example.) In addition, Aaron Gifford has made a number of test cases available at http://www.adg.us/computers/sha.html. In particular, he has tests for some of the border cases (where the text is exactly the length of a block, or one less, and a couple of other special lengths. If your implementation calculates the correct value for all of these, there is a good chance that it is correct.

OTHER TIPS

Yes this is the case. However some hash algorithms come with variations/settings, so you will need to match those if that is the case.

A good example is how an MD5 is often given to allow you to verify your download was correct. In order for this to work the MD5 hash implementation needs to produce the same result for all implementations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top