Skip to content
Trapdoor·Lab

Shamir's secret sharing

1Toy

A secret as a point on a polynomial

You split a secret into n shares so that any k of them rebuild it, while k−1 reveal nothing about it. The secret becomes the value of a polynomial of degree at most k−1 at x = 0, and each share is another point on that polynomial — k points determine it uniquely, so k shares give you the secret back. Real Shamir works in a finite field (modulo a prime or in GF(256)); the graph over real numbers is there for intuition.

Shamir’s secret sharing

11 / 1024 B

Limit 1 KB. We count UTF-8 bytes — “é” is 2 bytes.

The secret is empty. Type at least one character.

5
3

Splitting the secret…

2Break it

Guess the secret from k−1 shares

Through k−1 shares and any guessed secret passes exactly one polynomial of degree at most k−1, so every secret is equally likely. This is perfect secrecy: it does not rest on any hard computation, so neither computing power nor a quantum computer helps — try it in the “Break it” mode of the toy above. Shamir hides the content of the secret, though, not its length, and it does not protect integrity: a forged share silently changes the rebuilt result, which is why real systems add checksums or a MAC — SLIP-0039, for example, stores a digest of the secret in the polynomial and appends a checksum to every share.

3In the real world

Where secrets get shared

  • HashiCorp VaultIn the default configuration vault operator init splits the key needed to unseal Vault with Shamir’s scheme — into 5 shares, any 3 of which rebuild it.Source (HashiCorp Vault)
  • Vault's shamir packageThe Go implementation splits the secret byte by byte in GF(256): each share is one byte longer than the secret (that byte is the x coordinate), and Combine does not detect forged shares.Source (Vault's shamir package)
  • SLIP-0039The SatoshiLabs standard writes Shamir shares as word lists; the polynomial also stores a digest of the secret (HMAC-SHA256) that lets you check the secret was rebuilt correctly, and the last three words of every share are an RS1024 checksum.Source (SLIP-0039)
  • Trezor Multi-share BackupMulti-share backup of Trezor wallets is based on SLIP-0039: with a 3-of-5 split, any three shares recover the wallet.Source (Trezor Multi-share Backup)
  • DNSSEC — root zoneThe backup of the key that encrypts the backup copies of the DNS root zone KSK is protected by a 5-of-7 threshold scheme: the shares are held by Recovery Key Share Holders — people outside ICANN, PTI and Verisign.Source (DNSSEC — root zone)
4Take it to your project

Split the key, not the data

Good practice

Encrypt the data with an AEAD such as AES-GCM and split only the key — this is the envelope encryption pattern. Use a vetted implementation, such as the shamir package from Vault (Go) or the audited shamir-secret-sharing library (JS), instead of writing your own. Hand the shares to different people over different channels and add an integrity check (a checksum or a MAC), because plain Shamir does not detect a bad share.

JavaScript
import { split } from 'shamir-secret-sharing';

const key = await crypto.subtle.generateKey(
  { name: 'AES-GCM', length: 256 },
  true,
  ['encrypt', 'decrypt'],
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const ciphertext = await crypto.subtle.encrypt(
  { name: 'AES-GCM', iv },
  key,
  data,
);
const raw = new Uint8Array(
  await crypto.subtle.exportKey('raw', key),
);
// 5 shares, any 3 rebuild the key
const shares = await split(raw, 5, 3);
Anti-pattern

Don’t cut a password or a key into pieces: each piece gives away part of the secret — whoever holds half of a 128-bit key only has 64 bits left to guess. Don’t draw the coefficients with Math.random(): whoever predicts the generator’s output knows the polynomial and computes the secret from a single share (see the Randomness station). Don’t hand out a share at x = 0 — in the classic scheme the value at zero is the secret itself.

JavaScript
// ✕ each half gives away 64 of the key's 128 bits
const key = crypto.getRandomValues(new Uint8Array(16));
const forAlice = key.slice(0, 8);
const forBob = key.slice(8);