go - Go 运行时中的中间轮 AES 加密是如何工作的?

标签 go encryption cryptography runtime aes

我了解了 AES 在 Go 中的实现方式,但我不明白在 https://github.com/golang/go/blob/master/src/crypto/aes/block.go 中加密 block 时中间轮次是如何工作的:

// 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
}

我知道这段代码执行 AES 的 SybButes、ShiftRows、MixColumns 和 AddRoundKey,但我不明白这段代码是如何通过使用 “te0”、“te1”、“te2”、“te3”数组。它是在 https://github.com/golang/go/blob/master/src/crypto/aes/const.go 中定义的预先计算的数组.

有人可以向我解释这些数组是如何预先计算的吗?非常感谢您的帮助。

最佳答案

关于go - Go 运行时中的中间轮 AES 加密是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49965280/

相关文章:

c# - 如何在 Windows 上的 .net 框架中使用来自 ECC X509 证书的公钥加密数据?

mongodb - Revel+mgo golang - 如何定义结构类型来处理来自数据库的嵌套对象?

ios - 验证加密数据是否未被篡改

variables - Go err : cannot use cur (type *user. User) 作为 f.WriteString 参数中的类型字符串

linux - Linux 中的加密

c - 对套接字使用 AES_ctr128_encrypt 时出现 SIGSEGV 错误

java - GuardedString 和 JVM 的内存持久性

algorithm - 在任何一方都不知道盒子内容的情况下使用密码学随机播放

go - 客户端断开连接时如何正确使用 ctx.Done()?

go - exec ffmpeg 标准输出管道停止