I was trying to make a software only implementation of AES (Rijndael). At first I was able to implement it using table lookups for the Galois field multiplication and also for the SBox, but, I really wanted to remove all table lookups as they are prone to cache timing attacks. But implementing the Galois field Multiplication opened new avenues of side channel attacks, and also reduced the performance drastically...
This is a sample code I use for Galois field multiplication:
uint8_t GFm(uint8_t a, uint8_t b)
{
uint8_t p = 0;
while(a&&b)
{
if(b&1)
{
p^= a; // I realized this
branching is
vulnerable to power analysis
attacks...
}
if(a&0x80)
{
a = ((uint16_t)a<<1)^0x11b; //
We reduce by using the Rijndael
polynomial.
}else{
a <<=1;
}
b >>= 1;
}
return p;
}
- Does replacing
if(b&1){p^= a;}
withp = p^ (b&1)*a;
offer any protection against power analysis attacks? Should I replace the
while()
withfor(int i = 0; i<8; i++)
, to prevent the leakage of bit length ofb
? (The for loop makes my implementation more slower as it has to run 8 times always.)Is there a way to hide the traces of table lookups... ?
- Is there an even faster method to do $GF(2^{8})$ multiplications? This function is crucial since I use it in calculating the multiplicative inverse of elements in $GF(2^{8})$ by modular exponentiation. Those multiplicative inverses will go through the affine transformation to calculate the S-box.
Every help will be greatly appreciated!!! :)
b
. Is that of any use, or iswhile()
sufficient? $\endgroup$ – Vivekanand V Apr 30 '20 at 13:00