BL2.ru

Shamir Secret Sharing Online (M of N)

Split a secret (a password, a seed phrase, a whole SSH private key) into N shares. Any M of them restore the secret, while M-1 shares give no information about it. For example, 2 of 3: shares held by three different people, and losing one is harmless.

🔒 Everything is computed in your browser (crypto.getRandomValues); the secret and shares are never sent anywhere.

What Shamir's scheme is

Shamir's secret sharing (1979) splits a secret into N shares so that any M of them (the threshold) restore it, while any M-1 reveal not a single bit. The idea: exactly one polynomial of degree M-1 passes through M points, but infinitely many pass through M-1 points. The secret is the polynomial's value at zero, and the shares are its values at points 1..N. The other coefficients are random, so given M-1 shares every secret is equally likely.

Why split a key

The classic case is backup. A private key, a master password or a wallet phrase must not sit in one place, yet it must not be lost either. Split it 2 of 3 and give the shares to different people or store them in different places (a safe, the cloud, a relative's house). Losing one share is harmless, and stealing one gives nothing. For an SSH key paste it whole, including the BEGIN and END lines; you can create one in the SSH key generator.

How it differs from cutting a key into pieces

If you cut a key into three parts, each part reveals a third of the secret and all three are needed to restore it. Lose one piece and the key is gone, while two pieces greatly narrow the search for the rest. With Shamir's scheme one share (or any number below the threshold) reveals nothing, and the threshold is flexible: losing N-M shares is safe.

How it works here

The secret is processed byte by byte in the field GF(256) with the AES polynomial 0x11b. For each byte M-1 random coefficients are drawn (crypto.getRandomValues), and share number x gets the polynomial's value at x. Restoring is Lagrange interpolation at zero. Before splitting, 4 checksum bytes (the start of the secret's SHA-256) are appended and shared along with it. So a single share does not leak the secret's hash, and a wrong set of shares is detected on restore: you get a message instead of garbage.

Share format

bl2ss1-M-x-data, where M is the threshold, x is the share number (1..255) and data is the share's values for every byte of the secret plus the checksum, in base64url. Example: bl2ss1-2-1-Qm0x9kT2. The format is our own and is not compatible with ssss, Vault or other programs.

Restoring without the site

So that shares do not depend on this site, here is the complete restore algorithm. Decode base64url into bytes, take M shares and call the function.

def mul(a, b):
    r = 0
    while b:
        if b & 1:
            r ^= a
        a <<= 1
        if a & 0x100:
            a ^= 0x11b
        b >>= 1
    return r

def inv(a):
    return next(x for x in range(1, 256) if mul(a, x) == 1)

def restore(points):  # points = [(x, y_bytes), ...], any M shares
    out = []
    for i in range(len(points[0][1])):
        s = 0
        for xi, yi in points:
            num = den = 1
            for xj, _ in points:
                if xj != xi:
                    num = mul(num, xj)
                    den = mul(den, xi ^ xj)
            s ^= mul(yi[i], mul(num, inv(den)))
        out.append(s)
    return bytes(out)  # the last 4 bytes are the checksum

The result is the secret followed by 4 bytes. Check that they equal the first 4 bytes of the secret's SHA-256. For a strong password you can use the password generator.

FAQ

What does a single stolen share give?
Nothing. While there are fewer shares than the threshold M, every secret of the same length remains equally likely. This is a property of the scheme itself, not computational difficulty, so brute force and future computers do not help.
What happens if I paste fewer shares than the threshold?
The math would produce random garbage, so every share stores the threshold and the tool immediately says there are too few shares. If the shares come from different secrets, the checksum will not match and you get an error instead of a wrong result.
Can another program such as ssss or Vault restore the secret?
No. The bl2ss1 format is our own and shares can only be read by this tool. However, the article includes a short open restore algorithm, so the secret can be recovered without the site, in any language.
Which M and N should I choose?
For a personal key, 2 of 3 is usual: losing one share is harmless and an attacker needs two. For a team, 3 of 5 or 4 of 7. Allowed values are 2 ≤ M ≤ N ≤ 255. The higher the threshold, the harder for an attacker and the easier to lose access if shares disappear.
Is my secret sent to a server?
No. The secret and shares are processed only in your browser, and random numbers come from crypto.getRandomValues. On a shared computer, still close the tab afterwards and do not leave shares in the clipboard.