Visualizing Shamir’s Secret Sharing

Читать по-русски

What is Shamir’s secret sharing?

Imagine you need to store a password so that no single person knows it. When enough people come together, they can recover it and use it.

You could split the password into pieces and give each person one. But if one person is unavailable, everyone else is stuck. A more useful setup would give shares to ten people and let any six of them recover the password.

The Israeli mathematician Adi Shamir devised a scheme that does exactly that, and it now bears his name.

Wikipedia explains the full algorithm. Here we’ll use graphs to show the idea behind it.

Polynomials

A polynomial is a sum of powers of x multiplied by constants called coefficients.

f(x)= ∑ i=0 n ai xi

The degree is the highest power with a nonzero coefficient. Here are a few examples.

How many points pin down a curve?

The graph of a first-degree polynomial is a straight line. How many lines can you draw through one point?

0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 y x (2, 2)

Infinitely many. Add a second point, and only one straight line passes through both.

0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 y x (2, 2) (3, 5)

A second-degree polynomial gives us a parabola. One point leaves us with infinitely many possibilities.

0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 y x (2, 2)

Even with two points, infinitely many parabolas still fit.

0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 y x (2, 2) (3, 5)

What about three? Only one parabola fits these three points.

0 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 y x (1, 4) (2, 2) (3, 4)

In general, n + 1 points with distinct x-coordinates are enough to recover a polynomial of degree n.

From curves to secret sharing

Shamir’s scheme uses that same idea. The graphs use ordinary numbers so we can see how reconstruction works. The actual scheme uses finite-field arithmetic to protect the secret.

What about text?

Text is encoded as a sequence of bytes. Each byte represents a number from 0 to 255. Apply the secret sharing scheme to each byte separately.

What if the message is large?

For a long message, you can encrypt it with AES and split the encryption key instead. With AES-128, that means sharing a 16-byte key. Send the encrypted message along with the key shares.

Try it with three out of five points

Where the points come from

If we need any k shares to recover the secret, we use a polynomial of degree k − 1. For three shares, that’s a quadratic f(x) = ax2 + bx + C. The constant term C is the secret. We choose the other two coefficients at random.

Take a = 3, b = 7, and a secret of 15. That gives us f(x) = 3x2 + 7x + 15. Evaluating it at five different values of x gives us one point per person.

What if we need 100 out of 500?

Use a polynomial of degree 99 and evaluate it at 500 different nonzero values of x. It has the form ax99 + bx98 + … + kx + S. Any 100 of those points recover the polynomial and its constant term S.