Improve Multiply() macro by adding parentheses around macro args for additional safety.

This commit is contained in:
w3lld0ne 2024-03-15 22:27:38 +01:00
parent f06ac37fc3
commit a706192128

12
aes.c
View File

@ -326,12 +326,12 @@ static uint8_t Multiply(uint8_t x, uint8_t y)
((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */
}
#else
#define Multiply(x, y) \
( ((y & 1) * x) ^ \
((y>>1 & 1) * xtime(x)) ^ \
((y>>2 & 1) * xtime(xtime(x))) ^ \
((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \
((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
#define Multiply(x, y) \
( (((y) & 1) * (x)) ^ \
(((y)>>1 & 1) * xtime((x))) ^ \
(((y)>>2 & 1) * xtime(xtime((x)))) ^ \
(((y)>>3 & 1) * xtime(xtime(xtime((x))))) ^ \
(((y)>>4 & 1) * xtime(xtime(xtime(xtime((x))))))) \
#endif