I'm trying to write an implementation of SHA-1 in C++. But for some reason I can't get it to work. Two values won't add up correctly.
I'm using this link to check the steps of SHA-1 with input test
In the first round of the function (for word 0) I have this sample of my code:
#define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
a = 0xefcdab89;
b = 0x98badcfe;
c = 0x10325476;
d = 0xc3d2e1f0;
f = (b & c) | (d & (~b));
cout << LEFTROTATE(a, 5); // equal to 3903086636 (11101000101001000110000000101100)
cout << f; // equal to 2562383102 (10011000101110101101110011111110)
I want the two values to add up to give me LEFTROTATE(a, 5) + f
, but I get the following:
cout << LEFTROTATE(a, 5) + f; // equal to 2170502442 (10000001010111110011110100101010)
I'm expecting the output to be 6465469738 (110000001010111110011110100101010)
since 3903086636 + 2562383102 = 6465469738
. The value decreases for some reason and I don't know why.