Question

I'm trying to learn about SHA-1, I was looking at the C implementation that was included in the specification (RFC 31741) and this part confuses me:

context->Intermediate_Hash[0]   = 0x67452301;
context->Intermediate_Hash[1]   = 0xEFCDAB89;
context->Intermediate_Hash[2]   = 0x98BADCFE;
context->Intermediate_Hash[3]   = 0x10325476;
context->Intermediate_Hash[4]   = 0xC3D2E1F0;

What are the significance of those hard coded hex values, are they just special sauce that makes the algorithm work, or do they represent some mathematical constants?

You can view the full code here: http://www.faqs.org/rfcs/rfc3174.html

Was it helpful?

Solution

They're "nothing up my sleeve numbers".

The chosen value has no special properties. These are numbers have the same properties as randomly chosen values, but don't allow the algorithm designer to choose them. The algorithm designer choosing the constants might allow him to embed some kind of backdoor, so they're chosen in a way that reduces the degrees of freedom as much as possible.

Typical choices include the first digits of pi, or in the case of SHA-1 square-roots of small primes:

The constant values used are chosen as nothing up my sleeve numbers: the four round constants k are 2^30 times the square roots of 2, 3, 5 and 10. The first four starting values for h0 through h3 are the same as the MD5 algorithm, and the fifth (for h4) is similar.

From Wikipedia: SHA-1

OTHER TIPS

To save you on an overly verbose answer, they're just constants specific to the algorithm. As an example of a similar usage, refer to the Carmack Square Root. It uses a special value as a way of speeding up traditional methods of square rooting by providing an initial naive guess.

They're just numbers that help out serving as, as implied by the code, intermediate hash elements. They don't necessarily have any meaning as you may imply as mathematical constants, but they're important to the algorithm.

It does not answer your question but do note that the real reference to SHA-1 (as explained in the RFC) is FIPS 180. No more explanations there but at least it is the original source :-(

Also, remember that SHA-1 is today seriously endangered.

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