我正在尝试在 AES 加密(Rijndael)中实现查找表。公式如下(based on their paper):
我的代码是(仅一轮):
for(j = 0; j < 4; ++j)
{
unsigned int xorOperation;
xorOperation = T_0_enc_2[input[0][j]]
^ T_1_enc_2[input[1][(j-C1) % Nb]] // Nb = 4, C1 = 1, C2 = 2, C3 = 3
^ T_2_enc_2[input[2][(j-C2) % Nb]]
^ T_3_enc_2[input[3][(j-C3) % Nb]];
xorOperation ^= (w[0][j + (Nb * (i+1))] << 24) // w[x] is the key array, (i+1) is the round number
| (w[1][j + (Nb * (i+1))] << 16)
| (w[2][j + (Nb * (i+1))] << 8)
| (w[3][j + (Nb * (i+1))]);
input[0][j] = xorOperation >> 24;
input[1][j] = xorOperation >> 16;
input[2][j] = xorOperation >> 8;
input[3][j] = xorOperation;
}
问题是:
我的代码是否准确地映射了公式?因为当我用某个 key 对纯文本进行加密时,我没有得到预期的密码。
最佳答案
我已经弄清楚我的代码出了什么问题......:)
我使用输入作为输出,这会影响结果。我所做的就是使用另一个数组作为输出,然后在一轮完成后将结果复制回输入。
谢谢你们和我一起尝试......
关于c - AES 查找表实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33263877/