Main loop:
for i from 0 to 79
if 0 ≤ i ≤ 19 then
f := (b and c) or (( not b) and d)
k := 0x5A827999
else if 20 ≤ i ≤ 39
f := b xor c xor d
k := 0x6ED9EBA1
else if 40 ≤ i ≤ 59
f := (b and c) or (b and d) or (c and d)
k := 0x8F1BBCDC
else if 60 ≤ i ≤ 79
f := b xor c xor d
k := 0xCA62C1D6
temp := (a leftrotate 5) + f + e + k + w[i]
e := d
d := c
c := b leftrotate 30
b := a
a := temp
Add this chunk's hash to result so far:
h0 := h0 + a
h1 := h1 + b
h2 := h2 + c
h3 := h3 + d
h4 := h4 + e
Produce the final hash value (big-endian):
digest = hash = h0 append h1 append h2 append h3 append h4
Reference:
Hans Delfs and Helmut Knebl, Introduction to Cryptography: Principles and Applications, 2 nd Edition, Springer Verlag.
1. Introduction to Cryptography with Coding Theory , W. Trappe and L. C. Washington, Pearson Education .
2. Cryptography and Network Security , William Stallings, Prenctice Hall India .
3. Cryptography Theory and Practice , D. R. Stinson, CRC Press .