MD5 哈希算法使用哪种类型的左旋转?
Which type of leftrotation is used by the MD5 hash algorithm?
在这段来自 MD5 维基百科网站的伪代码中,完全可用 here,其中有一个伪函数 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));
但是,leftrotate()函数是逻辑旋转还是循环旋转?当我在 bitwise operations wikipedia 上查找函数时,我看到了不同的左旋转。 MD5 哈希函数使用哪一个?
旋转在第一个维基百科上定义为:
leftrotate (x, c)
return (x << c) binary or (x >> (32-c));
在 RFC 1321 上,函数的表述方式不同,如下所示:
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s)
哪里s是移位,但我还是不知道它是什么leftrotate
在谷歌搜索其他一些问题时找到了答案here
位旋转也称为循环移位旋转,可以在此处找到更多信息:
- Circular shift
- Bitwise operations
循环移位将数字向左移动 x 个数量,将多余的数字追加到末尾。
在这段来自 MD5 维基百科网站的伪代码中,完全可用 here,其中有一个伪函数 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));
但是,leftrotate()函数是逻辑旋转还是循环旋转?当我在 bitwise operations wikipedia 上查找函数时,我看到了不同的左旋转。 MD5 哈希函数使用哪一个?
旋转在第一个维基百科上定义为:
leftrotate (x, c)
return (x << c) binary or (x >> (32-c));
在 RFC 1321 上,函数的表述方式不同,如下所示:
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s)
哪里s是移位,但我还是不知道它是什么leftrotate
在谷歌搜索其他一些问题时找到了答案here
位旋转也称为循环移位旋转,可以在此处找到更多信息: - Circular shift - Bitwise operations
循环移位将数字向左移动 x 个数量,将多余的数字追加到末尾。