The inverse that spreads every difference
Worth reading first: The field with four elements · Every element is a power of one of them.
A substitution box is a fixed shuffle of short words — 8 bits in, 8 bits out — that a cipher applies over and over, and its job is to be unlike anything linear. A linear map turns a change in its input into a predictable change in its output: flip the same input bits and the same output bits flip, whatever the input was — the property that makes lights-out puzzles over two elements solvable by elimination, and that a cipher must avoid. Any trace of that predictability can be exploited, and the best-known way of exploiting it, differential cryptanalysis, works by counting. Fix an input difference , run every input through the box alongside , and tally the output differences. If some output difference turns up unusually often, the box leaks.
The opening figure draws the tally for 16 words of 4 bits, for two different shuffles. On the right is a random permutation; somewhere in its table an input difference produces the same output difference 8 times out of 16. On the left is the map that sends each element of the field of 16 elements to its inverse, with nought sent to nought, and every cell of its table holds 0, 2 or a single 4 per row. Nothing travels together more than four times in sixteen.
The same map on the field of 256 elements, , is the core of the substitution box in the Advanced Encryption Standard, chosen by Joan Daemen and Vincent Rijmen precisely for what the figures below compute. The same field arithmetic splits a secret into shares that individually reveal nothing; here it does a different job. This is not an essay about the cipher. It is about the arithmetic of a finite field, why its inverse spreads differences so evenly — one equation of degree two in every row — and how far that is from what is possible.
Two difference tables for sixteen words
The table has a row for every nonzero input difference and a column for every output difference , and the cell counts the inputs with . Every count is even, since if is counted so is , and every row sums to the number of inputs, 16. The largest count anywhere is the map’s differential uniformity, . It is at least 2, and it would be for a linear map, whose every row puts all its inputs in one cell.
The opening figure’s left table, for inversion in the field of 16 elements, has , and its structure is rigid: each row holds a single 4, six 2s and nine 0s. The random permutation beside it has , its large entries scattered at random — which is exactly what makes them dangerous, since an attacker who knows the box knows where they are.
Why the field matters is not obvious from the pictures. Its nonzero elements are all powers of one of them, so inversion is easy to compute — it subtracts logarithms — and yet, read on the bits, it looks like a shuffle with no pattern at all. The words are 4-bit strings, and the difference is bitwise exclusive-or; inversion is defined through the field’s multiplication, which mixes the bits in a way exclusive-or does not see. But addition in a field of elements is exclusive-or of bit strings — the field’s additive group is the bit strings under — so the difference table asks a question entirely inside the field: how many solutions does have? And that is a question about polynomial equations, which fields answer well.
How the cells fill for 256 elements
For 8-bit words the table has 255 rows and 256 columns, too many to draw, so the figure counts its cells by value. Inversion’s table holds 32,895 zeros, 32,130 twos and 255 fours — one four in every row — and nothing else. A random permutation of the 256 words, averaged over twenty, has about 19,700 twos, nearly 5,000 fours, 836 sixes, 104 eights, and around ten cells of ten.
The random permutation’s counts are what independence would predict. Each of the 128 pairs in a row lands in some output-difference cell more or less at random, so a cell’s count is roughly twice a Poisson variable with mean , and the largest of 65,280 such cells is far out in the tail. Inversion is nothing like random. Its counts are pinned to 0 and 2 with one exception per row, which is not a statistical accident but an algebraic identity, as the next figure shows.
The difference matters out of proportion to its size. An attacker following a difference through several rounds of a cipher multiplies the probabilities of each step: a cell of 10 out of 256 gives a step that succeeds with probability , a cell of 4 one with . Over ten rounds the gap between those is a factor of about ten thousand, and every extra round widens it.
A quadratic behind every row
Fix and and solve for other than and . Multiply through by :
using in characteristic 2. A quadratic over a field has at most two roots, so each cell receives at most two solutions from this part. The figure shows one row: 126 output differences hit exactly twice, 129 not at all.
The two excluded inputs make the exception. At the map’s difference is , since nought is sent to nought, and at it is again. So the cell receives the pair — and in even dimension the quadratic for , which becomes , also has two roots, since its roots are times the cube roots of unity other than 1, which exist in the field exactly when 3 divides , that is, when is even. Two plus two is the single 4 in each row.
That is the whole proof of , and it shows what the field is doing. The difference equation of a random permutation is a table lookup with no structure; the difference equation of inversion is a polynomial of degree 2. The same reasoning applies to any power map , whose difference equation has degree about — and so low-degree power maps are natural candidates, though low degree also makes the map’s algebra simple, which is its own weakness.
Inversion against six hundred random permutations
The second weakness a box can have is to be close to an affine function on some combination of its output bits — the weakness exploited by linear cryptanalysis. For each nonzero mask , the bit is a Boolean function of , and its distance from the nearest affine function, counted in inputs where they disagree — the Hamming distance between two columns of 256 bits — is read off its Walsh transform: the correlations with all linear functions, computed in one sweep by the fast transform that also builds the largest determinants of plus and minus ones. The minimum over all masks is the map’s nonlinearity. It is the same quantity as the distance from a word to the first-order Reed–Muller code, whose codewords are exactly the affine functions.
The figure measures 600 random permutations both ways. Their largest difference counts run from 10 to 18, most at 10 or 12; their nonlinearities from 82 to 98. Inversion, at 4 and 112, is better than every one of them on both measures — and not by a little: no random permutation in the sample came within a factor of two of it on differences, or within 14 of it on nonlinearity.
The nonlinearity of inversion has a closed description. Its Walsh coefficients are Kloosterman sums, the exponential sums of over the field, and André Weil’s bound on such sums, the estimate drawn in give or take twice the square root, says they never exceed . That gives a nonlinearity of at least , and the computation shows it is exactly that. Random permutations have no such bound working for them, because their Walsh coefficients are sums of independent signs, whose largest of 65,000 is several times the typical size.
Every power map of 256 elements
If one power map does this well, perhaps another does better. The figure tries all of them. For each exponent from 1 to 254 it computes the full difference table of on the field of 256 elements. The map is a permutation exactly when shares no factor with 255, which happens for 128 exponents.
The powers of two, , are the field’s automorphisms — raising to a power of two is additive in characteristic 2 — so they are linear and score the worst possible, 256. Among the other permutations the counts scatter between 4 and 64, and exactly eight of them reach 4: inversion, , and its seven conjugates modulo 255, which are inversion followed by a field automorphism and are therefore the same map in disguise. No power permutation reaches 2.
Maps that do reach 2 exist among the powers: and the 23 other exponents in its family. For the difference equation is , a quadratic, and it never has a third solution. Such a map is called almost perfect nonlinear. But 3 divides 255, so sends three elements to every nonzero cube and is not a permutation, and a substitution box that is not a permutation cannot be inverted for decryption. The figure’s lowest row is entirely pale: in the field of 256 elements, every power map that spreads differences perfectly fails to be one-to-one.
Odd dimensions reach two, even ones stop at four
The obstruction is a matter of parity. The extra pair in inversion’s table came from the cube roots of unity, which exist when 3 divides , which is when is even. In odd dimension there are no nontrivial cube roots of unity, the quadratic for has no roots, and every count is 0 or 2. The figure computes it for to 10: largest count 2, 4, 2, 4, 2, 4, 2, 4. In odd dimension inversion is an almost perfect nonlinear permutation; in even dimension, where computers work, it is not.
The nonlinearity row tells a parallel story. In even dimension inversion’s nonlinearity, , equals the best value known for any permutation. In odd dimension it falls a little short of the proved maximum , which other maps — the quadratic ones like , which are permutations when is odd — achieve exactly. Odd dimensions have perfect maps of several kinds; even dimensions are where the difficulty lives.
When two boxes are the same box
The census of power maps found eight permutations at count 4, and called them one map in disguise. The disguise is worth making precise, because it decides what counts as a new answer. Compose a box with an invertible affine map of the bits before it, and another after it: . An input difference for is an input difference for , and an output difference of becomes one of after applying the linear part of ; the cells of the table are permuted and none is changed. So the largest count is unchanged, and the same argument, applied to the Walsh coefficients, leaves the nonlinearity unchanged too. Boxes related this way are affine equivalent, and they are the same box for every purpose the tables measure.
The eight power maps at count 4 are , which is inversion followed by , and squaring in characteristic 2 is a linear map of the bits. So they are affine equivalent to inversion, and the census really found one map. In the same way the Advanced Encryption Standard’s box, which is inversion followed by a fixed affine map, has exactly inversion’s counts — 4 and 112 — while its algebraic description in the field is no longer a single power, which was the reason for adding the affine map.
There is a coarser equivalence that preserves the difference counts as well, due to Claude Carlet, Pascale Charpin and Victor Zinoviev: two maps are equivalent if an affine map of the space of pairs carries the graph of one onto the graph of the other. It is coarser because it can turn a map into one that is not even a permutation, or a permutation into a map that is not, and that is how the open question is usually attacked. The dimension 6 example was found by starting from a known almost perfect nonlinear function that is not a permutation and searching its equivalence class for one that is. In dimension 8 the known almost perfect nonlinear functions have been searched this way, and none of their classes has yielded a permutation — evidence, not proof, since the known functions may not be all there are.
The open question in dimension 8
Do almost perfect nonlinear permutations exist in even dimension? In dimension 2 the answer is trivially yes; in dimension 4, an exhaustive search over the equivalence classes of permutations of 16 words, completed in the 2000s, says no. In 2009 John Dillon and his colleagues at the National Security Agency found one in dimension 6 — a permutation of the 64 words with every count at most 2 — by a computer search guided by structure; it is not a power map and has no simple formula. Dimension 8 is open. The space of permutations of 256 words is far too large to search, no algebraic construction is known, and the problem is called the big APN problem.
The figures show why it is hard rather than why it is true or false. Power maps cannot work in dimension 8, since the census above covers them all. Random permutations are hopeless, at counts of 10 and more. What would be needed is a permutation with structure as rigid as inversion’s — every row a two-to-one pattern — without being a power map. Inversion is the best answer found so far, at 4, and it is the answer the most widely used 8-bit box adopted, which is why cryptographers and algebraists have the same reason to want the question settled.
Two statistics are not a cipher
The figures measure two statistics of a substitution box, and a box’s real strength depends on more. Inversion’s algebraic simplicity is itself a risk: the relation for nonzero is a system of quadratic equations in the input and output bits, and so-called algebraic attacks try to solve such systems for a whole cipher at once. That is why the AES box follows inversion with an affine map over the bits, which changes neither count measured here but breaks the field structure an algebraic attack would use. Whether quadratic systems from real ciphers can be solved efficiently is not settled, and no figure here addresses it.
Nor do the tables show how differences combine across rounds. A single box with largest count 4 bounds one step; the security of a cipher comes from how many boxes a difference must pass through, which depends on the linear layers between them, and that is a design question about the whole cipher rather than about the field.
And the computations here are exhaustive only for the cases drawn — every cell of every table for the fields up to 1,024 elements, every power map for 256. The statements about all random permutations are statements about 600 samples, consistent with the probabilistic estimates, not proofs that no random permutation could do better.
Still open: perfect spreading in even dimension
The question at the heart of this essay is a single, finite-looking one: is there a permutation of the 256 eight-bit words whose difference table has no entry larger than 2? It is equivalent to finding a function from a field of 256 elements to itself, one-to-one, whose every difference equation has at most two solutions. Dimension 6 has one example, found by search; dimension 8 has none known and no proof that none exists. Related questions — whether the nonlinearity can be beaten by any permutation in even dimension, and how many inequivalent almost perfect nonlinear functions exist in each dimension — are also open, and they are among the cleanest unsolved problems connecting finite fields and the design of ciphers.
Degree two in every row
A random shuffle of 256 words is a poor substitution box because its difference table is a table of independent accidents, some of which are large. The inverse in the field of 256 elements is a good one because every row of its table is the solution set of a quadratic, which has at most two roots, plus one exceptional pair that the cube roots of unity force in even dimension. The same arithmetic gives the nonlinearity through Kloosterman sums and Weil’s bound, and the same parity that adds the exceptional pair is why perfect power-map permutations exist in odd dimension and not in even. Four is the best any power map achieves on 8-bit words, and nobody knows whether anything can achieve two.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- Dots that never repeat a step — both name exhaustive search, finite field, permutation
- What a formula keeps when letters are fixed — both name boolean function, exhaustive search, open problem
- A deck where any two cards match once — both name exhaustive search, finite field
- A determinant built from two-by-two pieces — both name exhaustive search, permutation
- A hundred prisoners and one shuffle — both name exhaustive search, permutation
- A plane no field built — both name exhaustive search, finite field
Named objects
A dashed tag is an object no other essay names yet.
Boolean functionExhaustive searchFinite fieldHadamard matrixOpen problemPermutation