If you look at the code in the Wikipedia we will see this part of the code;
h = (unsigned char)((signed char)r[c] >> 7);b[c] = r[c] << 1;[c] ^= 0x1B & h;
h stores the leftmost bit of c
c is not x-or'ed with 0x1b but not with 0x11b why why?
When shifting r left by one, the MSB value is discarded. Before discarding, we hold this value with h holds the value.
- If
h==0than modulus operation is not required. The0x1B & h = 0x0so there is0ifh=0. Nono x-or with0x11B0x1b - If
h=1than modulus operation is required. The0x1B & his= 0x1Bifh=1. The x-or with0x1bis performed. Note that - Note that: it is not x-or with
0x11B0x11bit is with0x1B0x1bsince we discarded the MSB1while shifting therefor no. Therefore, there is no need to xorx-or with0x11B0x11b, x-oring with0x1B0x1bis enough. Now, it is clear that everthing is in BytsBytes.
A small example;
A small example;Here [ ] represents 8-bit.
Let multiply $a = (x^7+x^6+x^3+x)$ by $\{2\}$
- represent $a$ as binary $a = 11001010b$representation of $a = [11001010]$
h = 1$h = 1 = [00000001]$- $b = a \ll 1 = 110010100b$$b = a \ll 1 = 1[10010100]$ but everthing is in Bytes, therefore
- $b = 10010100b$$b = [10010100]$
- $h \wedge 0x1b = 1 \wedge 0x1b = 0x1b$$h \wedge 0x1b = [00000001] \wedge [00011011] = [00011011] = 0x1b$
- $b \oplus 0x1b = 1001 0100b \oplus 0x00011011b = 10001111b$$b \oplus 0x1b = [10010100] \oplus [00011011] = [10001111] = 0x8f$