Search

Search papers and lessons

Secret Sharing

Level 3 · 14 min read

Secret sharing splits a secret into pieces so that any k pieces rebuild it while fewer than k reveal nothing, and Shamir's version does this with a random polynomial.

On this page

  • Colour = topic mix
  • Discrete math
  • Abstract algebra
  • Security & cryptography
  • ReadReady to readNot yet

TL;DR

Secret sharing is a way to split one secret, such as a master password or a signing key, into several pieces called shares. You choose a threshold k and a number of shares n. Any k shares rebuild the secret, while any fewer than k shares tell an attacker nothing at all. Shamir's version does this with a random polynomial: the secret is its value at zero, and each share is one more point on its graph.

Builds on: Polynomial, Finite Field · Leads to: Secure Aggregation

Where it's used

Guarding a master key. An organisation that must never let one person control a critical key can split it among five officers and require any three to be present to use it. No single officer, and no pair, can act alone. The key is never assembled until enough people agree to meet.

Recovery of a lost wallet key. Some digital-wallet designs spread a recovery secret across trusted contacts, so that a user who loses a device can still get the key back if enough of the contacts cooperate. A few contacts being compromised, or unavailable, does not expose or lose the key.

Computing on hidden values. In Secure Aggregation, many devices each hold a private number and want only the total. Shamir shares add: if each device shares its number, the sum of the shares is a valid share of the sum of the secrets. The servers can combine the shares without ever seeing an individual number. A related idea that also computes on hidden values is Homomorphic Encryption.

How it works

Take a tiny instance. The arithmetic is done modulo the prime 7, so every number is 0 to 6. The secret is s = 3, the threshold is k = 2, and we make n = 3 shares.

  1. Choose a random line. Pick a random slope a between 0 and 6, here a = 2, and write f(x) = 3 + 2x (mod 7). The constant term is the secret. Check: f(0) = 3, which is the secret.
  2. Make the shares. Give party i the point (i, f(i)). Party 1 gets f(1) = 5, party 2 gets f(2) = 7 mod 7 = 0, and party 3 gets f(3) = 9 mod 7 = 2. Check: the three shares are (1, 5), (2, 0) and (3, 2).
  3. Rebuild from any two. Take parties 2 and 3, with points (2, 0) and (3, 2). A line through two points has slope (2 − 0) / (3 − 2) = 2. Check: the slope is 2, which matches the a we chose.
  4. Read off the secret. Going back from (2, 0) with slope 2 gives f(0) = 0 − 2 × 2 = −4, which is 3 mod 7. Check: the rebuilt secret equals s = 3.
  5. Why one share is not enough. Hold only party 2's point (2, 0). For any candidate secret t from 0 to 6, the line through (0, t) and (2, 0) exists and is unique. So all seven secrets are equally consistent with the one share. Check: a single point on a line says nothing about where the line crosses zero.
  6. Generalise. A polynomial of degree k − 1 is fixed by any k of its points, and no value is fixed by fewer than k of them. With k = 2 that is a line, with k = 3 a parabola, and so on. The secret is always the value at zero.
flowchart LR
  S["Secret s"] --> P["Random polynomial with f(0) equal to s"]
  P --> Sh["Shares: points (i, f(i)) for i = 1 to n"]
  Sh --> K["Any k shares"]
  K --> I["Interpolate to find f"]
  I --> R["Read f(0) = secret"]
  Sh --> F["Fewer than k shares"]
  F --> N["Every secret equally possible"]

The math

Definition: Shamir secret sharing

Let pp be a prime, s∈Z/pZs \in \mathbb{Z}/p\mathbb{Z} the secret, and k≤n<pk \le n \lt p the threshold and share count. Choose coefficients a1,…,ak−1a_1, \dots, a_{k-1} uniformly at random from Z/pZ\mathbb{Z}/p\mathbb{Z}, and define

f(x)=s+a1x+a2x2+⋯+ak−1xk−1(modp).f(x) = s + a_1 x + a_2 x^2 + \cdots + a_{k-1} x^{k-1} \pmod p.

Share ii is the pair (i,f(i))(i, f(i)) for i=1,…,ni = 1, \dots, n.

Here Z/pZ\mathbb{Z}/p\mathbb{Z} is the finite field of integers mod pp, and (modp)\pmod p means every result is reduced to its remainder mod pp. Because pp is prime, every nonzero number has a multiplicative inverse, so the usual solving steps work.

Step 1 in symbols: the polynomial

The secret is the constant term. In the tiny instance, k=2k = 2, so f(x)=s+a1xf(x) = s + a_1 x, and with s=3s = 3, a1=2a_1 = 2, p=7p = 7 we get f(x)=3+2x(mod7)f(x) = 3 + 2x \pmod 7. A Polynomial of this shape is a line, and f(0)=3f(0) = 3.

Step 2 in symbols: the shares

The shares are f(1)=5f(1) = 5, f(2)=0f(2) = 0 and f(3)=2f(3) = 2 (mod 7). Each is computed as an ordinary polynomial value, then reduced mod 7. For example f(3)=3+2⋅3=9≡2f(3) = 3 + 2 \cdot 3 = 9 \equiv 2.

Step 3 in symbols: the slope from two shares

Given points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) with x1≠x2x_1 \ne x_2, the slope is a=(y2−y1)(x2−x1)−1(modp)a = (y_2 - y_1)(x_2 - x_1)^{-1} \pmod p. Here the inverse is needed. Fermat's little theorem, which is the standard result behind Modular Arithmetic inverses, says cp−1≡1(modp)c^{p-1} \equiv 1 \pmod p for c≠0c \ne 0, so c−1≡cp−2c^{-1} \equiv c^{p-2}. For p=7p = 7 and c=1c = 1 this is trivial; for c=2c = 2 we get 2−1≡25=32≡42^{-1} \equiv 2^5 = 32 \equiv 4, and indeed 2⋅4=8≡12 \cdot 4 = 8 \equiv 1. With shares (2,0)(2, 0) and (3,2)(3, 2), the slope is (2−0)⋅(3−2)−1=2⋅1=2(2 - 0) \cdot (3 - 2)^{-1} = 2 \cdot 1 = 2.

Step 4 in symbols: Lagrange's formula at zero

The general reconstruction uses the Lagrange interpolation formula, which is evaluated at x=0x = 0:

f(0)=∑i∈Tyi∏j∈Tj≠i0−xjxi−xj(modp),f(0) = \sum_{i \in T} y_i \prod_{\substack{j \in T \\ j \ne i}} \frac{0 - x_j}{x_i - x_j} \pmod p,

where TT is the set of kk shares used and (xi,yi)(x_i, y_i) are their points. For T={2,3}T = \{2, 3\} this is 0⋅0−32−3+2⋅0−23−2=0+2⋅(−2)=−4≡30 \cdot \frac{0 - 3}{2 - 3} + 2 \cdot \frac{0 - 2}{3 - 2} = 0 + 2 \cdot (-2) = -4 \equiv 3. Check: that is ss.

Step 5 in symbols: one share reveals nothing

Suppose an attacker has k−1k - 1 shares and wants to know s=f(0)s = f(0). For any candidate value t∈Z/pZt \in \mathbb{Z}/p\mathbb{Z}, the polynomials with f(0)=tf(0) = t that match the k−1k - 1 known points number exactly one, because kk constraints fix a polynomial of degree k−1k - 1. Since the coefficients were chosen uniformly, every tt has the same probability. So the known shares give zero information about ss. This is a property of the construction, not of how the shares are stored.

For the tiny instance, the single share (2,0)(2, 0) leaves each of the 7 secrets tt with exactly one line through (0,t)(0, t) and (2,0)(2, 0), which is the claim of Step 5 for k=2k = 2.

Worked examples

Example
Example 1: rebuilding a 2-of-3 split

Shares: (1,5)(1, 5), (2,0)(2, 0), (3,2)(3, 2) over Z/7Z\mathbb{Z}/7\mathbb{Z}. Rebuild using only the last two.

  1. Points: (2,0)(2, 0) and (3,2)(3, 2).
  2. Slope: (2−0)⋅(3−2)−1=2⋅1=2(2 - 0) \cdot (3 - 2)^{-1} = 2 \cdot 1 = 2.
  3. Line: f(x)=0+2(x−2)=2x−4≡2x+3(mod7)f(x) = 0 + 2(x - 2) = 2x - 4 \equiv 2x + 3 \pmod 7.
  4. Constant term: f(0)=3f(0) = 3.
  5. Check with the first share: f(1)=2+3=5f(1) = 2 + 3 = 5, which matches party 1's share.

The secret is 3. Party 1's share was not needed, but it agrees with the rebuilt line, which confirms the shares are consistent.

Example
Example 2: a 3-of-5 split over the prime 11

Secret s=7s = 7, threshold k=3k = 3, prime p=11p = 11. Take f(x)=7+4x+9x2(mod11)f(x) = 7 + 4x + 9x^2 \pmod{11}.

  1. Shares: f(1)=7+4+9=20≡9f(1) = 7 + 4 + 9 = 20 \equiv 9; f(2)=7+8+36=51≡7f(2) = 7 + 8 + 36 = 51 \equiv 7; f(3)=7+12+81=100≡1f(3) = 7 + 12 + 81 = 100 \equiv 1.
  2. Use the three shares (1,9)(1, 9), (2,7)(2, 7) and (3,1)(3, 1).
  3. Lagrange weight for x=1x = 1: (0−2)(0−3)(1−2)(1−3)=62=3\frac{(0 - 2)(0 - 3)}{(1 - 2)(1 - 3)} = \frac{6}{2} = 3.
  4. Lagrange weight for x=2x = 2: (0−1)(0−3)(2−1)(2−3)=3−1=−3≡8\frac{(0 - 1)(0 - 3)}{(2 - 1)(2 - 3)} = \frac{3}{-1} = -3 \equiv 8.
  5. Lagrange weight for x=3x = 3: (0−1)(0−2)(3−1)(3−2)=22=1\frac{(0 - 1)(0 - 2)}{(3 - 1)(3 - 2)} = \frac{2}{2} = 1.
  6. Combine: f(0)=9⋅3+7⋅8+1⋅1=27+56+1=84f(0) = 9 \cdot 3 + 7 \cdot 8 + 1 \cdot 1 = 27 + 56 + 1 = 84.
  7. Reduce: 84=7⋅11+784 = 7 \cdot 11 + 7, so f(0)≡7f(0) \equiv 7.

The rebuilt secret is 7, which is the original. Any other three of the five shares would give the same answer.

Example
Example 3: a family key split among five people

A family keeps a 256-bit key that must be usable if any three of five trusted adults agree, and must reveal nothing if only two cooperate. Real systems use a prime just above 22562^{256}, but the steps are the same as in the small cases.

  1. Choose a random polynomial of degree 2 whose constant term is the key. Its two other coefficients are random numbers of the same size.
  2. Compute five shares, one for each adult. Each share is a number of the same size as the key, so the five shares together take about five times the storage of the key.
  3. Give one share to each adult, through a secure channel, and destroy the polynomial.
  4. Suppose Ana, Ben and Chloe meet. Each reads their point. Any three points determine the parabola, and Lagrange's formula at zero returns the key.
  5. Suppose Ana and Ben only have their shares. For each candidate key, exactly one parabola passes through their two points and that candidate, so neither can tell which key is real.

Try it: the same family wants a 3-of-5 split, but two adults leave the country and their shares are lost. Can the key still be rebuilt, and how many shares may be lost in total before it cannot be? Answer: yes, the key can still be rebuilt, because three shares remain. Losing a third share, leaving two, makes it impossible, so the scheme tolerates exactly two lost shares.

Common mistakes and tradeoffs

It is tempting to think that secret sharing is a kind of encryption, so the shares are safe to store anywhere. In fact the secrecy comes from the arithmetic of the polynomial, and the shares still need to be delivered and stored with care. A share holder can still lose a share, sell it, or hand it to someone else, and if k holders collude the secret is gone, so the protection is only as strong as the holders' discipline.

It is tempting to think that any honest-looking share is correct. In fact a dishonest holder can submit a wrong share, and plain Shamir reconstruction will return a wrong secret without any warning. Detecting this needs verifiable secret sharing, where each share comes with a public check such as a hash commitment.

It is tempting to think that any prime will do. In fact the secret must be smaller than the prime, and the prime must be larger than the number of shares. A 4-bit prime cannot hold a 128-bit key, so the prime has to be chosen for the size of the secret.

It is tempting to think that secret sharing and the one-time pad are the same kind of secrecy. In fact the One-Time Pad is perfectly secret for one message with a key as long as the message, and Shamir sharing is perfectly secret for fewer than k shares with shares as long as the secret. The idea is related, but the setting differs.

When to use it: you have several parties, you need any k of them to be able to act, and you need fewer than k to learn nothing. When not to use it: you only need all parties to agree, where a simpler additive split of the secret into random pieces that sum to it is enough, or you must detect cheating without verifiable extras. Alternatives include threshold signatures, which never rebuild the key at all, and hardware modules that keep the key inside one device.

History

In 1979, Adi Shamir published "How to Share a Secret", giving the polynomial construction described here. In the same year George Blakley proposed a different threshold scheme based on intersecting hyperplanes. Both appeared in the same year, each as a way to split a key among a group.

Lagrange's interpolation formula, which lets a polynomial be rebuilt from enough of its points, was known from the 1700s, long before anyone applied it to keys. Shamir's contribution was to see that the constant term of a random polynomial makes a clean secret, and that the fewer-than-k case can be proved to reveal nothing.

Secret sharing caught on because it solved a practical problem with one key controlled by one person. It later became a building block in multi-party computation and in protocols where many devices compute a total without revealing their own inputs.

Recap

  • A threshold scheme lets any k of n shares rebuild the secret, and fewer than k reveal nothing.
  • Shamir's scheme hides the secret as the constant term of a random polynomial of degree k − 1 over a prime field, and gives each party one point on it.
  • Any k points fix the polynomial, and Lagrange's formula at zero returns the secret. Fewer than k points leave every secret equally possible.
  • Shares add, which is why the scheme is used in secure aggregation. Shares still need careful delivery, and verifiable versions catch dishonest holders.
  • Read next: Secure Aggregation, which combines shares to compute totals without revealing inputs.

Check yourself

QuestionRecall: what is the secret in Shamir's scheme, and where does it sit on the polynomial?Show answer

The secret is the constant term f(0)f(0). The shares are points (i,f(i))(i, f(i)) for i=1,…,ni = 1, \dots, n, and the secret is recovered as the value at zero.

QuestionComputation: over the prime 7, shares (1, 5) and (3, 2) come from a line f(x)=s+axf(x) = s + a x. Find aa and ss.Show answer

The slope is a=(2−5)(3−1)−1=−3⋅2−1=−3⋅4=−12≡2(mod7)a = (2 - 5)(3 - 1)^{-1} = -3 \cdot 2^{-1} = -3 \cdot 4 = -12 \equiv 2 \pmod 7. Then s=f(0)=5−2⋅1=3s = f(0) = 5 - 2 \cdot 1 = 3. So a=2a = 2 and s=3s = 3.

QuestionWhy: why does holding k minus one shares reveal nothing about the secret, even though the scheme is public?Show answer

With k−1k - 1 points, every candidate secret tt can be extended to exactly one polynomial of degree k−1k - 1 that passes through those points and has f(0)=tf(0) = t. Since the coefficients were chosen at random, all candidates are equally likely, so the points give no information about which one is real.

QuestionApplied: a team uses a 3-of-5 Shamir split for a backup key. One holder submits a wrong share during reconstruction, and the rebuilt key is wrong without any error message. What went wrong, and what would catch it?Show answer

Plain Shamir reconstruction trusts every share it receives, so a single bad share silently corrupts the result. A verifiable scheme, where each share comes with a public commitment that can be checked, would reject the bad share. Alternatively, the team can check the rebuilt key against a known fingerprint of the key, or reconstruct from different subsets and compare.

Sources