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

从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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值