hash - MD5哈希算法使用哪种类型的左旋转?

标签 hash md5 bitwise-operators

这段伪代码来自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是shift,但我仍然不知道它是哪种leftrotate。

最佳答案

在谷歌搜索其他一些问题时找到了答案 here

位旋转也称为循环移位旋转,可以在此处找到更多信息: -Circular shift -Bitwise operations

循环移位将数字向左移动 x 量,并将多余的数字附加到末尾。

enter image description here

关于hash - MD5哈希算法使用哪种类型的左旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32933254/

相关文章:

java - 我应该使用哪种密码散列方法?

cryptography - SHA512优于MD5的原因

C 编程设置 Unsigned Char 数组中的位

python - 如何应用按位运算符来比较对象列表

java - Java 中的 SimHash 实现?

authentication - 在.NET Core 2.0中实现bcrypt

c++ - MD5 哈希函数输出垃圾

node.js - 带有base64摘要算法的nodejs md5错误结果

java - Java 中的按位左移产生相同的值......?

c# - PBKDF2 c#.NET 的性能