原创 AES加密算法 03

2009-10-4 23:33 2292 5 5 分类: 工程师职场
密钥扩展部分也有几个function

subword 进s盒
rotword 转 s0,s1,s2,s3转完了变成s1,s2,s3,s0
rcon  又是一个表 wiki链接
http://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon

pdf文档中给了伪代码
解释一下变量
Nb 列数 Number of columns (32-bit words) comprising the State. For this
standard, Nb = 4. (Also see Sec. 6.3.)
Nk 密钥数 Number of 32-bit words comprising the Cipher Key. For this
standard, Nk = 4, 6, or 8. (Also see Sec. 6.3.)
Nr 加密轮数 Number of rounds, which is a function of Nk and Nb (which is
fixed). For this standard, Nr = 10, 12, or 14. (Also see Sec. 6.3.)

KeyExpansion(byte key[4*Nk], word w[Nb*(Nr+1)], Nk)
 begin

  word temp
  i = 0

  while (i < Nk)
   w = word(key[4*i], key[4*i+1], key[4*i+2], key[4*i+3])
   i = i+1
  end while

  i = Nk

  while (i < Nb * (Nr+1)]
   temp = w[i-1]
   if (i mod Nk = 0)
    temp = SubWord(RotWord(temp)) xor Rcon[i/Nk]
   else if (Nk > 6 and i mod Nk = 4)
    temp = SubWord(temp)
   end if
   w = w[i-Nk] xor temp
   i = i + 1
  end while

 end
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
5
关闭 站长推荐上一条 /3 下一条