Re: Could anyone verify a term for me?



William L. Bahn wrote:
"Hipo" <no@xxxxxxxxx> wrote in message
news:448dbf8e$0$11094$3b214f66@xxxxxxxxxxxxxxxxxxxxxxx
Hi.
I'm coding a SHA-1 implementation and I'm stuck at a point for
two days
now. I have to compute:
T = _rotl(0x67452301, 5) + ((0xefcdab89 & 0x98badcfe) xor
(~0xefcdab89 &
0x10325476)) + 0xc3d2e1f0 + 0x5a827999 + 0x80636261;

All numbers are unsigned ints and therfor 2^32 bit long. My
result for T
is always 0x2017fb14, but the partial result of a testvector
in the
standard paper claims T to be 0x0116fc33.

Could please anyone verify my result? It's driving me nuts and
the
algorithm is almost due.

thanks in advance, Hipo

I get the same result you do.

You didn't provide enough info to really know where in the hash
algorithm you are working, so I'm having to reverse engineer
where you are at. Initially, at least, I'm going to assume you
are at the very first pass through the main loop.

(snippets of algorithm taken from Wikipedia)
http://en.wikipedia.org/wiki/SHA1

a = 0x67452301
b = 0xEFCDAB89
c = 0x98BADCFE
d = 0x10325476
e = 0xC3D2E1F0

f = (b & c) | ((~b) & d) // notice inclusive-OR
k = 0x5A827999

Substituting into your expression:

T = _rotl(0x67452301, 5) + ((0xefcdab89 & 0x98badcfe) xor
(~0xefcdab89 &
0x10325476)) + 0xc3d2e1f0 + 0x5a827999 + 0x80636261;

becomes

T = _rotl(a, 5) + [((b & c) xor ((~b) & d))] + e + k +
0x80636261;

Now, the last term comes from the message being hashed, so I have
no idea where it is coming from in this particular case and
whether or not you have it correct.

[snip]
0x80636261 is what the ascii string "abc" becomes with a 0x80 terminator
in little endian notation in a 32-bit word.

But SHA-1 requires that its input data is in big-endian form within
32-bit words, in this case as W[0] = 0x61626380.

So the original poster's problem is pretty certain to be that they have
not put the input data into the correct big-endian format.

Brian Gladman
.