MD5和SHA-1算法输入的最大长度

来源:互联网 发布:长春南关网络花店 编辑:程序博客网 时间:2024/05/21 10:46

从MD5算法和SHA-1算法的原理可以看出,二者都把二进制输入串的最后64bit用来存储输入串的长度


这样,二进制输入串的长度范围应该均为 0 ~ (2^64 - 1)。


区别在于:

MD5算法中,如果二进制输入串的位长度超出了 (2^64 - 1),则把 (bitLength % 2^64) 存储在最后64bit中,

所以,MD5算法的输入串是没有长度限制的(虽然不太可能出现超出长度限制的情况)。

引用自http://en.wikipedia.org/wiki/MD5:

MD5 processes a variable-length message into a fixed-length output of 128 bits. The input message is broken up into chunks of 512-bit blocks (sixteen 32-bit words); the message is padded so that its length is divisible by 512. The padding works as follows: first a single bit, 1, is appended to the end of the message. This is followed by as many zeros as are required to bring the length of the message up to 64 bits fewer than a multiple of 512. The remaining bits are filled up with 64 bits representing the length of the original message,modulo 264.


而SHA-1算法中,则只是单纯的把二进制输入串的位长度存在最后64bit,

所以,SHA-1算法的输入串的最大长度是:0 ~ (2^64 - 1)。


参考:

http://en.wikipedia.org/wiki/MD5

http://en.wikipedia.org/wiki/SHA-1



0 0
原创粉丝点击