我正在编写 AES Invert mixcolumns 操作,我需要在 GF(256) 中将数字乘以 14。这就是我想出的(p 是结果,q 是要乘以 14 的数字):
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
int main()
{
uint8_t p=1, q=0x02;
p = (q<<1) ^ (q<<2) ^ (q<<3);//*(x³+x²+x)
//modulo x⁸+x⁴+x³+x+1
if((q>>5)<5&&(q>>5)!=0&&(q>>5)!=3)
p^=0x1B;
if((q>>5)>1&&(q>>5)<6)
p^=0x36;
if((q>>5)>3)
p^=0x6C;
printf("\n\n\t%2.2X\n\n",p);
return 0;
}
它有效,但我认为有一种更简单的方法可以做到这一点,但我似乎找不到它。我的主要问题是我进行了 6 次比较。