CAST-128加密算法( 二 )


密/解密过程中只需要4K字节,因为子钥的产生通常在输入数据之前就完成了 。
置换箱S1-S8的内容参见附录A 。
2.4 密钥表
假设128位的密钥是x0x1x2x3x4x5x6x7x8x9xAxBxCxDxExF,其中x0是最高位的字节,
xF是最低位的字节 。
令z0…zF是中间(临时)字节 。
令S[i]表示置换箱i,“^”代表异或加 。
按照下述公式从密钥x0x1x2x3x4x5x6x7x8x9xAxBxCxDxExF生成子钥:
z0z1z2z3=x0x1x2x3^S5[xD]^S6[xF]^S7[xC]^S8[xE]^S7[x8]
z4z5z6z7=x8x9xAxB^S5[z0]^S6[z2]^S7[z1]^S8[z3]^S8[xA]
z8z9zAzB=xCxDxExF^S5[z7]^S6[z6]^S7[z5]^S8[z4]^S5[x9]
zCzDzEzF=x4x5x6x7^S5[zA]^S6[z9]^S7[zB]^S8[z8]^S6[xB]
K1=S5[z8]^S6[z9]^S7[z7]^S8[z6]^S5[z2]
K2=S5[zA]^S6[zB]^S7[z5]^S8[z4]^S6[z6]
K3=S5[zC]^S6[zD]^S7[z3]^S8[z2]^S7[z9]
K4=S5[zE]^S6[zF]^S7[z1]^S8[z0]^S8[zC]
x0x1x2x3=z8z9zAzB^S5[z5]^S6[z7]^S7[z4]^S8[z6]^S7[z0]
x4x5x6x7=z0z1z2z3^S5[x0]^S6[x2]^S7[x1]^S8[x3]^S8[z2]
x8x9xAxB=z4z5z6z7^S5[x7]^S6[x6]^S7[x5]^S8[x4]^S5[z1]
xCxDxExF=zCzDzEzF^S5[xA]^S6[x9]^S7[xB]^S8[x8]^S6[z3]
K5=S5[x3]^S6[x2]^S7[xC]^S8[xD]^S5[x8]
K6=S5[x1]^S6[x0]^S7[xE]^S8[xF]^S6[xD]
K7=S5[x7]^S6[x6]^S7[x8]^S8[x9]^S7[x3]
K8=S5[x5]^S6[x4]^S7[xA]^S8[xB]^S8[x7]
z0z1z2z3=x0x1x2x3^S5[xD]^S6[xF]^S7[xC]^S8[xE]^S7[x8]
z4z5z6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