Secret Sharing

The Task, a use case

The Problem, in general

Easy Cases

General Case, with interactive graphics

Share Computation

Wrong Numbers

Finite Fields

Matrices

Demo

—Mike Speciner

The Task

I’m an engineer tasked with building a system to launch nuclear missiles, and I want to make sure that the missiles aren’t launched by mistake. But I also want to make sure that they will be launched when properly authorized, so that they can serve as a credible deterrent. To do this, I want to give out launch codes to a number of trusted individuals (for redundancy) but require the cooperation of a few of them in order to launch (so one or two of them can’t go rogue).

The Problem

I have a b-bit secret s that I want to break into n shares so that any k of those shares can be combined to reconstruct the secret, but no k−1 of them can give any information about the secret.

Easy Cases

k = 1:  Each share is the secret itself:

si = s

k = nn−1 shares are random b-bit numbers, and the remaining share is the xor of those numbers and the secret s:

si = ri  for 0 < i < k

s0 = sr1 ⊕ ⋯ ⊕ rk−1

General Case

Observation: A line is determined by 2 points. More generally a polynomial curve of degree k−1 is determined by k points on that curve.

So, if we give a point on a k−1 degree curve to each of our n sharers, any k of them can together determine the curve. If we make y at x = 0 be our secret s, and choose the other k−1 coefficients randomly, we’ve mostly solved our problem.

Share computation

s0
sn−1
=
1 x0 x02 x0k−1
1 xn−1 xn−12 xn−1k−1
s
r1
rk−1

To compute the secret s from k of the shares si, take the corresponding k rows from the matrix (leaving a k×k Vandermonde matrix), invert it and then multiply by the vector of k shares. The first element of the resulting vector is the secret s, the remaining elements are the random numbers ri.

What’s Wrong With This Scheme?

So far, I’ve described the scheme using “real” numbers, but those are problematic on a computer. We could use rational numbers, but those get expensive to compute. Also, the notion of a random number gets a bit dicey. Integers don’t work, because they’re mostly hard to invert. The numbers we really want to use are those from a finite field.

Real numbers (int, float)BAD
Finite field numbersGOOD

The Right Kind of Numbers

In order for numbers to be usable for our secret sharing scheme, they have to satisfy certain properties:

+ − × / 0 1  ∞ 

Numbers with these properties are called finite fields, and lucky for us, there are lots of them. For each prime p and each positive integer n, there is exactly one finite field, written GF(pn); it has pn numbers in it.

Computing with Finite Fields

ffield.py

I’ve written a finite field module, ffield.py, for computing with finite fields. It has a single class, called ffield, which takes three arguments: a prime p, a positive integer n, and an irreducible polynomial encoded as a number or tuple, and returns a class implementing the specified finite field. The reason for the third argument is that, while there is only a single finite field for a given p and n, its numbers can be represented by nonegative integers less than pn in many different ways, depending on that third argument. But 0 and 1 are always represented as themselves.

ffield(2,4,15)

+0123456789abcdef
00123456789abcdef
11032547698badcfe
223016745ab89efcd
332107654ba98fedc
445670123cdef89ab
554761032dcfe98ba
667452301efcdab89
776543210fedcba98
889abcdef01234567
998badcfe10325476
aab89efcd23016745
bba98fedc32107654
ccdef89ab45670123
ddcfe98ba54761032
eefcdab8967452301
ffedcba9876543210
×0123456789abcdef
00000000000000000
10123456789abcdef
202468acefdb97531
30365cfa97412b8de
4048cfb73159dea62
505afbe149c36278d
606ca71bde8249f53
707e934da618f52bc
808f719e62ad53bc4
909d45c81a37ef62b
a0ab19328d76c4ef5
b0b92d64f5ec7831a
c0c7be2953f48d1a6
d0d58a7f2b6e31c49
e0e3d685bc2f1a497
f0f1e2d3c4b5a6978

Computing with Matrices

matrix.py

I’ve written a matrix module, matrix.py, for computing with matrices whose elements may be regular Python numbers or Python number-like class instances. In particular, it works with ffield.py and rational.py (an implementation of the field of rational numbers). It has a single class, called matrix, which takes arguments specifying the dimensions of the matrix and its contents, and returns the corresponding vector or matrix, or higher-dimensional array (but we can ignore that). It provides the usual matrix operations, such as addition, subtraction, multiplication, division, negation, inverse, transpose, trace, determinant.

Secret Sharing with Finite Fields

(Demonstration)

I’ve written a little module, share.py, for demonstrating the use of finite fields for secret sharing. If we have a b-bit secret, GF(2b) is a natural choice. By default, share.py uses b = 256, and in particular F=ffield(2,256,1061).

Questions?

All of the python modules mentioned, as well as this presentation, are available on https://github.com/ms0/. The python modules can be imported from the msmath package (pip install msmath).