I'm trying to understand how Shamir's Secret Sharing algorithm is applied to AES when doing threshold masking.
I understand how the secrets are created and the secret is calculated and I'm now trying to figure out how the math operations (that are needed for AES) work when you have the shares. To do that I'm reading this source: Goubin et al, Protecting AES with Shamir's Secret Sharing Scheme. (pages 79-94 in isbn 978-3-642-23951-9)
It says: addition of shares with an unmasked value: $$\{(x_i', y_i') \leftarrow (x_i,y_i \oplus u) | \forall (x_i, y_i) \in shares\}$$ Where $u$ is the to be added value and $(x_i, y_i)$ is an original share. Addition results in a new $(x_i', y_i')$ share.
I've implemented this in python (not in a finite field) in this way:
def add_unmasked(self, shares, value):
return [{'x': share['x'], 'y': share['y'] ^ value} for share in shares]
However I don't see the correct results, if I have a secret of 20 being shared and unshared results it in 20, but if I add 1, I get the wrong result 80% of the time.
For completeness sake my code:
def create_shares(self, to_create):
if to_create < self.degree + 1:
raise Exception('shares don\'t cover the order')
coefficients = self.generate_polynomial(self.degree, self.secret)
points = random.sample(range(self.finite_field), to_create)
shares = [{'x': point, 'y': sum(coefficient * point ** n for n, coefficient in enumerate(coefficients))} for
point in points]
return shares
def tell_secret(self, shares):
# doing a polynomial interpolation using the basic definition. sum y * l where l is the product of x - xi / xm - xi. x is 0 in our case
xs = [share['x'] for share in shares]
y = 0
for share in shares:
l = 1
for x in xs:
if x != share['x']:
l *= (- x) / (share['x'] - x)
y += share['y'] * l
return int(round(y))
edit: Reading wikipedia about the definitions of operators in a finite field, I've found this:
A particular case is GF(2), where addition is exclusive OR (XOR) and multiplication is AND.
AES uses a $GF(2)$ finite field, the Galois field $GF(2^8)$ So when my paper says: $\oplus$ they mean the addition operator for the finite field GF(2). This is confirmed by my test when doing an addition in my non finite field program.
edit 2:
As such I read this as doing a $GF(2^8)$ addition to all the shares. It is using the word XOR and I've read that it should be XOR in the finite field but when I do this in my testing program, I don't get the correct result. This seems to be because of at least one share having an y value which overflows with the addition.
edit 3:
So I've found the following lines in the referenced paper:
Our scheme maintains the same compatibility as Boolean masking with the linear transformations of the algorithm
So it seems that the paper proposes some kind of SSS mixed with boolean masking on an AES implementation. I still don't get it completely but I'm moving on and maybe if I come back to it later my understanding will have improved.