AES查找表实现

时间:2015-10-21 15:54:56

标签: c encryption aes

我正在尝试在AES加密(Rijndael)中实现查找表。公式如下(based on their paper):

enter image description here

我的代码是(只有一轮):

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

问题是:

我的代码是否完全符合公式?因为当我使用某个密钥加密纯文本时,我无法得到预期的密码。

2 个答案:

答案 0 :(得分:0)

我已经弄清楚我的代码中出了什么问题...:)

我使用输入作为影响结果的输出。我所做的就是使用另一个数组作为输出,然后在完成一轮后将结果复制回输入。

谢谢你们和我一起努力......

答案 1 :(得分:0)

要创建AES查找表,必须将上述代码应用于每个字节的所有256个输入状态。

相关问题