I'm coding AES Invert mixcolumns operation and I need to multiply numbers by 14 in GF(256). This is what I have come up with (p is the result and q the number to multiply by 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;
}
It works but I think there is a simpler way to do this but I cannot seem to find it. My main issue here is that I make 6 comparisons.