SHA家族( 二 )

【SHA家族】Initialize variables:h0 := 0x67452301h1 := 0xEFCDAB89h2 := 0x98BADCFEh3 := 0x10325476h4 := 0xC3D2E1F0Pre-processing:append the bit '1' to the messageappend k bits '0', where k is the minimum number >= 0 such that the resulting messagelength (in bits) is congruent to 448 (mod 512)append length of message (before pre-processing), in bits, as 64-bit big-endian integerProcess the message in successive 512-bit chunks:break message into 512-bit chunksfor each chunkbreak chunk into sixteen 32-bit big-endian words w[i], 0 ≤ i ≤ 15Extend the sixteen 32-bit words into eighty 32-bit words:for i from 16 to 79w[i] := (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1Initialize hash value for this chunk:a := h0b := h1c := h2d := h3e := h4Main loop:for i from 0 to 79if 0 ≤ i ≤ 19 thenf := (b and c) or ((not b) and d)k := 0x5A827999else if 20 ≤ i ≤ 39f := b xor c xor dk := 0x6ED9EBA1else if 40 ≤ i ≤ 59f := (b and c) or (b and d) or (c and d)k := 0x8F1BBCDCelse if 60 ≤ i ≤ 79f := b xor c xor dk := 0xCA62C1D6temp := (a leftrotate 5) + f + e + k + w[i]e := dd := cc := b leftrotate 30b := aa := tempAdd this chunk's hash to result so far:h0 := h0 + ah1 := h1 + bh2 := h2 + ch3 := h3 + dh4 := h4 + eProduce the final hash value (big-endian):digest = hash = h0 append h1 append h2 append h3 append h4 SHA-2NIST发布了三个额外的SHA变体,这三个函式都将讯息对应到更长的讯息摘要 。以它们的摘要长度(以位元计算)加在原名后面来命名:SHA-256,SHA-384和SHA-512 。它们发布于2001年的FIPS PUB 180-2草稿中,随即通过审查和评论 。包含SHA-1的FIPS PUB 180-2,于2002年以官方标準发布 。2004年2月,发布了一次FIPS PUB 180-2的变更通知,加入了一个额外的变种SHA-224",这是为了符合双金钥3DES所需的金钥长度而定义 。SHA-256和SHA-512是很新的杂凑函式,前者以定义一个word为32位元,后者则定义一个word为64位元 。它们分别使用了不同的偏移量,或用不同的常数,然而,实际上二者结构是相同的,只在循环执行的次数上有所差异 。SHA-224以及SHA-384则是前述二种杂凑函式的截短版,利用不同的初始值做计算 。这些新的杂凑函式并没有接受像SHA-1一样的公众密码社群做详细的检验,所以它们的密码安全性还不被大家广泛的信任 。Gilbert和Handschuh在2003年曾对这些新变种作过一些研究,声称他们没有找到弱点 。套用SHA-1, SHA-224, SHA-256, SHA-384 和 SHA-512 都被需要安全杂凑算法的美国联邦政府所套用,他们也使用其他的密码算法和协定来保护敏感的未保密资料 。FIPS PUB 180-1也鼓励私人或商业组织使用 SHA-1 加密 。Fritz-chip 将很可能使用 SHA-1 杂凑函式来实现个人电脑上的数位着作权管理 。首先推动安全杂凑算法出版的是已合併的数位签章标準 。SHA 杂凑函式已被做为 SHACAL 分组密码算法的基础 。参见编码