如果我没记错的话,对于AES128,我们会生成16个字节的数据,因此其代码如下所示。
void KeyExpansion(unsigned char inputKey[16], unsigned char expandedKeys[176])
{
for(int i=0; i<16; i++)
expandedKeys[i] = inputKey[i];
int bytesGenerated = 16;
int rconIteration = 1;
unsigned char temp[4];
while(bytesGenerated <176)
{
for(int i=0; i<4; i++)
temp[i] = expandedKeys[i + bytesGenerated - 4];
if(bytesGenerated % 16 == 0)
{
keyExpansionCore(temp, rconIteration);
rconIteration++;
}
for(unsigned char a=0; a<4; a++)
{
expandedKeys[bytesGenerated] = expandedKeys[bytesGenerated - 16] ^ temp[a];
bytesGenerated++;
}
}
}
但是,我对AES256不太确定。我们还会生成16个字节的数据还是32个字节的数据?如果它生成32个字节的数据,我必须将我的inputKey [16]更改为inputKey [32]吗?那ExpandedKey又如何呢?当我看到expandedKey [176]和inputKey [16]时,我感到很困惑,不是变成192个字节吗? (但是我在搜索AES128时看到了这段代码。)