In this piece of pseudocode from the MD5 Wikipedia website, fully available here, there is a pseudofunction leftrotate().
for each 512-bit chunk of message
break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
//Initialize hash value for this chunk:
var int A := a0
var int B := b0
var int C := c0
var int D := d0
//Main loop:
for i from 0 to 63
if 0 ≤ i ≤ 15 then
F := (B and C) or ((not B) and D)
g := i
else if 16 ≤ i ≤ 31
F := (D and B) or ((not D) and C)
g := (5×i + 1) mod 16
else if 32 ≤ i ≤ 47
F := B xor C xor D
g := (3×i + 5) mod 16
else if 48 ≤ i ≤ 63
F := C xor (B or (not D))
g := (7×i) mod 16
dTemp := D
D := C
C := B
B := B + leftrotate((A + F + K[i] + M[g]), s[i])
A := dTemp
end for
//Add this chunk's hash to result so far:
a0 := a0 + A
b0 := b0 + B
c0 := c0 + C
d0 := d0 + D
end for
var char digest[16] := a0 append b0 append c0 append d0 //(Output is in little-endian)
//leftrotate function definition
leftrotate (x, c)
return (x << c) binary or (x >> (32-c));
However, is the leftrotate() function a logical rotate or a circular rotate? As when I looked up the function on the bitwise operations wikipedia I saw different leftrotations. Which one does the MD5 hashfunction use?
The rotation is defined on the first Wikipedia as:
leftrotate (x, c)
return (x << c) binary or (x >> (32-c));
On RFC 1321 the function is formulated differently, like so:
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s)
Where s is the shift, but still I don't know what kind of leftrotate it is.