Computation

The inverse that spreads every difference

Change the input of a map on 8-bit words by a fixed amount and count how often the output changes by each amount. A random shuffle of the 256 words concentrates some differences: one input change produces one output change ten or twelve times. Taking the inverse in the field of 256 elements never does it more than four times. That is why the map sits at the heart of a widely used cipher. Whether any shuffle of 8-bit words can do it only twice is an open question.

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 aa, run every input xx through the box alongside x⊕ax \oplus a, 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.

Two difference tables for sixteen words. n=4: inversion delta 4; random permutation delta 8
Fig. 1 Difference tables for 16 words of 4 bits. Inversion in the field of 16 elements puts 0, 2 or a single 4 in every row; a random permutation of the same words reaches 8.

The same map on the field of 256 elements, x↦x254x \mapsto x^{254}, 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 aa and a column for every output difference bb, and the cell counts the inputs xx with S(x⊕a)⊕S(x)=bS(x \oplus a) \oplus S(x) = b. Every count is even, since if xx is counted so is x⊕ax \oplus a, and every row sums to the number of inputs, 16. The largest count anywhere is the map’s differential uniformity, δ\delta. It is at least 2, and it would be 2n2^n 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 δ=4\delta = 4, and its structure is rigid: each row holds a single 4, six 2s and nine 0s. The random permutation beside it has δ=8\delta = 8, 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 ⊕\oplus 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 2n2^n elements is exclusive-or of bit strings — the field’s additive group is the bit strings under ⊕\oplus — so the difference table asks a question entirely inside the field: how many solutions does (x+a)−1+x−1=b(x + a)^{-1} + x^{-1} = b have? And that is a question about polynomial equations, which fields answer well.

How the cells fill for 256 elements

How the cells fill for 256 elements. inversion counts 0:32895 2:32130 4:255; random averages 0:39630.4 2:19740.5 4:4957.3 6:835.8 8:104.2 10:10.8 12:1.1
Fig. 2 The 65,280 cells of the difference table for 8-bit words, on a logarithmic scale: inversion has exactly one 4 and 126 2s in every row and nothing larger; a random permutation has cells of 6, 8 and sometimes 10.

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 {x,x⊕a}\{x, x \oplus a\} 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 1/21/2, 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 10/25610/256, a cell of 4 one with 4/2564/256. 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

A quadratic behind every row. a=83: 126 twos, 129 zeros, one 4 at b=202; solutions 0,62,83,109
Fig. 3 One row of inversion’s table, a=83a = 83: clearing denominators turns 1/(x+a)+1/x=b1/(x + a) + 1/x = b into the quadratic bx2+abx+a=0b x^2 + a b x + a = 0, so 126 values of bb are hit twice and 129 not at all. At b=1/ab = 1/a, the inputs x=0x = 0 and x=ax = a add a pair of their own, and the count is 4.

Fix aa and bb and solve (x+a)−1+x−1=b(x + a)^{-1} + x^{-1} = b for xx other than 00 and aa. Multiply through by x(x+a)x(x + a):

x+(x+a)=b x(x+a),that is,bx2+abx+a=0,x + (x + a) = b\,x(x + a), \quad\text{that is,}\quad b x^2 + a b x + a = 0,

using x+x=0x + x = 0 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 x=0x = 0 the map’s difference is a−1+0=a−1a^{-1} + 0 = a^{-1}, since nought is sent to nought, and at x=ax = a it is 0+a−10 + a^{-1} again. So the cell b=1/ab = 1/a receives the pair {0,a}\{0, a\} — and in even dimension the quadratic for b=1/ab = 1/a, which becomes x2+ax+a2=0x^2 + ax + a^2 = 0, also has two roots, since its roots are aa times the cube roots of unity other than 1, which exist in the field exactly when 3 divides 2n−12^n - 1, that is, when nn is even. Two plus two is the single 4 in each row.

That is the whole proof of δ=4\delta = 4, 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 xdx^d, whose difference equation has degree about dd — 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

Inversion against six hundred random permutations. random delta 10:243 12:325 14:30 16:1 18:1; NL 82:2 84:1 86:11 88:22 90:85 92:180 94:220 96:78 98:1; inversion 4, 112
Fig. 4 Six hundred random permutations of the 256 bytes: left, the largest count in each one’s difference table, from 10 to 18; right, each one’s nonlinearity, at most 98. Inversion beats every one of them on both, at 4 and 112.

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 mm, the bit m⋅S(x)m \cdot S(x) is a Boolean function of xx, 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 2n2^n 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 x+a/xx + a/x 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 2⋅2n/22 \cdot 2^{n/2}. That gives a nonlinearity of at least 2n−1−2n/2=128−16=1122^{n-1} - 2^{n/2} = 128 - 16 = 112, 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

Every power map of 256 elements. power permutations min delta 4 (8 of 128); delta-2 powers 3,6,9,12,18,24,33,36,39,48,57,66,72,78,96,114,129,132,144,147,156,192,201,228
Fig. 5 The largest difference count of every power map x↦xdx \mapsto x^d on the field of 256 elements. Dark dots are permutations, pale ones are not. The powers 2k2^k are linear and score 256; the permutations never go below 4, and the powers scoring 2 are all three-to-one.

If one power map does this well, perhaps another does better. The figure tries all of them. For each exponent dd from 1 to 254 it computes the full difference table of x↦xdx \mapsto x^d on the field of 256 elements. The map is a permutation exactly when dd shares no factor with 255, which happens for 128 exponents.

The powers of two, d=1,2,4,…,128d = 1, 2, 4, \ldots, 128, 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, d=254d = 254, and its seven conjugates 254⋅2k254 \cdot 2^k 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: x3x^3 and the 23 other exponents in its family. For x3x^3 the difference equation (x+a)3+x3=b(x + a)^3 + x^3 = b is ax2+a2x+a3=ba x^2 + a^2 x + a^3 = b, a quadratic, and it never has a third solution. Such a map is called almost perfect nonlinear. But 3 divides 255, so x3x^3 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

Odd dimensions reach two, even ones stop at four. n=3: delta 2, NL 2; n=4: delta 4, NL 4; n=5: delta 2, NL 10; n=6: delta 4, NL 24; n=7: delta 2, NL 54; n=8: delta 4, NL 112; n=9: delta 2, NL 234; n=10: delta 4, NL 480
Fig. 6 Inversion in the field of 2n2^n elements for n=3n = 3 to 10. In odd dimension every count is 0 or 2; in even dimension the largest is 4. The last row gives the best nonlinearity known for a permutation in each dimension.

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 2n−12^n - 1, which is when nn is even. In odd dimension there are no nontrivial cube roots of unity, the quadratic for b=1/ab = 1/a has no roots, and every count is 0 or 2. The figure computes it for n=3n = 3 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, 2n−1−2n/22^{n-1} - 2^{n/2}, equals the best value known for any permutation. In odd dimension it falls a little short of the proved maximum 2n−1−2(n−1)/22^{n-1} - 2^{(n-1)/2}, which other maps — the quadratic ones like x3x^3, which are permutations when nn 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: S′(x)=A(S(B(x)⊕c))⊕dS'(x) = A(S(B(x) \oplus c)) \oplus d. An input difference aa for S′S' is an input difference B(a)B(a) for SS, and an output difference of SS becomes one of S′S' after applying the linear part of AA; 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 x↦x254⋅2kx \mapsto x^{254 \cdot 2^k}, which is inversion followed by y↦y2ky \mapsto y^{2^k}, 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 (x,S(x))(x, S(x)) 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 x⋅S(x)=1x \cdot S(x) = 1 for nonzero xx 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 2n−1−2n/22^{n-1} - 2^{n/2} 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.

Named objects

A dashed tag is an object no other essay names yet.

Boolean functionExhaustive searchFinite fieldHadamard matrixOpen problemPermutation