duanbanzhi4419 2018-04-22 11:14
浏览 74
已采纳

Go运行时中级AES加密如何工作?

I learn how AES`s implementation work in Go and I do not understand how middle rounds work while encrypt block in https://github.com/golang/go/blob/master/src/crypto/aes/block.go:

// Middle rounds shuffle using tables.
// Number of rounds is set by length of expanded key.
nr := len(xk)/4 - 2 // - 2: one above, one more below
k := 4
for r := 0; r < nr; r++ {
    t0 = xk[k+0] ^ te0[uint8(s0>>24)] ^ te1[uint8(s1>>16)] ^ te2[uint8(s2>>8)] ^ te3[uint8(s3)]
    t1 = xk[k+1] ^ te0[uint8(s1>>24)] ^ te1[uint8(s2>>16)] ^ te2[uint8(s3>>8)] ^ te3[uint8(s0)]
    t2 = xk[k+2] ^ te0[uint8(s2>>24)] ^ te1[uint8(s3>>16)] ^ te2[uint8(s0>>8)] ^ te3[uint8(s1)]
    t3 = xk[k+3] ^ te0[uint8(s3>>24)] ^ te1[uint8(s0>>16)] ^ te2[uint8(s1>>8)] ^ te3[uint8(s2)]
    k += 4
    s0, s1, s2, s3 = t0, t1, t2, t3
}

I understand that this code do SybButes, ShiftRows, MixColumns and AddRoundKey of AES, but I do not understand how this code do it by using "te0", "te1", "te2", "te3" arrays. It's precomputed arrays which are defined in https://github.com/golang/go/blob/master/src/crypto/aes/const.go.

May someone explain to me how these arrays was precomputed? Thank you so much for you help.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥50 vue router 动态路由问题