I have problem with multiplying bytes by 3 in MixColumns (as in Cryptography And Network Security)
$$\begin{bmatrix}02&03&01&01\\01&02&03&01\\01&01&02&03\\03&01&01&02\end{bmatrix}\times\begin{bmatrix}87\\6e\\46\\a6\end{bmatrix}\mapsto \begin{bmatrix}47\\37\\94\\ed\end{bmatrix}$$
87 = 10000111 => SHL = 00001110 => 00001110 XOR 00011011 = 00010101
6e = 01101110 => SHL = 11011100 => XOR it with the byte ibtself 11011100 XOR 01101110 = 10110010
(If XOR it with 0x1b then XOR it with the byte the answer won't be correct)
4e = No changes (Multiply by one)
a6 = No changes (Multiply by one)
00010101 XOR 10110010 XOR 01001110 XOR 10100110 = 01000111 = 0x47
Next One:
87 = No changes (Multiply by one)
6e = 01101110 => SHL = 11011100 => 11011100 XOR 00011011 = 11000111
46 = 01000110 => SHL = 10001100 => XOR with 0x1b = 10001100 XOR 00011011 = 10010111 => XOR with the Byte itself 10010111 XOR 01000110 = 11010001
(for this one I should XOR with 0x1b first to get right answer)
a6 = No changes (Multiply by one)
10000111 XOR 110000111 XOR 11010001 XOR 10100110 = 00110111 = 0x37
As you see for the first one if we XOR it with 0x1b we wouldn't get the right answer but for the second one, we have to do it to get the right answer. why does this happen?
same problem with this case (used in AES Rijndael Cipher explained as a Flash animation)
$$\begin{bmatrix}02&03&01&01\\01&02&03&01\\01&01&02&03\\03&01&01&02\end{bmatrix}\times\begin{bmatrix}d4\\bf\\5d\\30\end{bmatrix}\mapsto \begin{bmatrix}04\\66\\81\\e5\end{bmatrix}$$