You cannot use (just) a bit shift to multiply by $7$. Not in ${\rm GF}(2^n)$, and not in normal arithmetic either.
Shifting a number left by one bit always multiplies it by two, and shifting a number left by multiple bits is just equivalent to shifting it left by one bit several times. So shifting a number left (by one or more bits) always multiplies it by a power of two.
To multiply a number by a factor that is not a power of two, you need both shifting and addition (which in ${\rm GF}(2^n)$ is actually bitwise XOR). For example, $7 = 111_2 = 4 + 2 + 1$, so $7a = 4a + 2a + a$ for any $a$. So, to multiply some number $a$ by $7$, you can first calculate $2a$ and $4a$ by shifting $a$ left, and then add those together with $a$ itself (always remembering that, in ${\rm GF}(2^n)$, addition is actually XOR and that any results with more than $n$ bits will need to be reduced modulo the field polynomial).
More generally, we can do general multiplication in ${\rm GF}(2^n)$ by splitting one of the numbers being multiplied into a sum of powers of two (which is really easy if we're working on a binary computer), use bit shifting (and modular reduction) to multiply the other number by those powers of two, and then add the results together. Here's some pseudo-C code to illustrate this:
const int overflow = 0x100, modulus = 0x11B; // AES GF(2^8) representation
int gf2n_multiply(int a, int b) {
int sum = 0;
while (b > 0) {
if (b & 1) sum = sum ^ a; // if last bit of b is 1, add a to the sum
b = b >> 1; // divide b by 2, discarding the last bit
a = a << 1; // multiply a by 2
if (a & overflow) a = a ^ modulus; // reduce a modulo the AES polynomial
}
return sum;
}
Note that you could easily turn the code above into a normal integer multiplication routine by replacing sum ^ a
with sum + a
and removing the last line in the while
loop that reduces a
modulo the AES polynomial after it has been shifted left. Those are the only ways in which Galois field arithmetic, as used in this code, differs from normal integer arithmetic.
Also note that, while the code above should work (in the sense of producing the correct results), it's probably not something you should use in production crypto code. Not only is it not particularly well optimized, but its running time depends on the value of b
, which is generally not desirable if b
might contain sensitive data that you don't want to leak.
(BTW, at this point you might be wondering if it wouldn't be more efficient, for example, to calculate $7a$ as $8a - a$ instead. Unfortunately, while that would work fine in normal integer arithmetic, addition and subtraction in ${\rm GF}(2^n)$ work differently, and we actually have $8 - 1 = 8 + 1 = 9 \ne 7$. But adding together distinct powers of two still works the same way in ${\rm GF}(2^n)$ as it does with normal integers, so we can still usefully work with the binary representation of numbers.)