ESORICS 2023: Arithmetic Circuit Implementations of S-boxes for SKINNY and PHOTON in MPC

This blog post summarizes this paper which is joint work with Aysajan Abidin and Bart Preneel and was presented at ESORICS 2023.

Code for the paper can be found here.

Takeaway/Summary/tldr

In this paper, we find a new representation of the SKINNY tweakable block cipher and the lightweight permutation PHOTON in arithmetic circuits in the fields \(\mathbb{GF}(2^4)\) and \(\mathbb{GF}(2^8)\). We evaluate the primitive (SKINNY and PHOTON) in a secure multi-party computation protocol where both the input as well as the key is secret-shared and thus not known to any party. Our representation allows the computation of any 4-bit S-box with 2 multiplications and 8 random bits instead of the Boolean representation that would require 4 multiplications. Our benchmark confirms this improvement and we achieve a speed-up of \(\approx\) 18% and send \(\approx\) 50% less data.

Background

Secure Multi-Party Computation (MPC)

We already have excellent introduction posts to MPC such as this on the COSIC blog. However, for the purpose of this blog post, the following will suffice. With MPC protocols, multiple parties can jointly compute a function on private input data. Moreover, in the process, no party learns the private inputs of the other parties.

In this example, \(P_1\) and \(P_2\) want to compute \(f(x,y)\) where \(x\) is a private input of \(P_1\) and \(y\) is a private input of \(P_2\). The MPC protocols guarantee that \(P_1\) and \(P_2\) don’t learn any additional information beyond what can be inferred from the function output. Specifically, \(P_1\) doesn’t learn the other party’s input \(y\) and vice versa.

Function Representation

But how exactly is \(f\) then computed? This depends on the MPC protocol. In general, MPC protocols support basic operations, either Boolean operations such as XOR, AND, NOT, OR, etc…, or arithmetic operations, e.g., addition and multiplication in a field (e.g., modulo a prime). Some MPC protocol (frameworks) also offer specialized sub-protocols, e.g., to convert from Boolean to arithmetic shares, to accelerate certain operations etc.

In general, linear operations (XOR, NOT in Boolean circuits, linear functions in arithmetic circuits) are cheap to compute and are often local operations that the parties compute. Non-linear operations, such as multiplication (AND in Boolean circuits) is the costly operation that usually entails communication cost.

Function representation matters. For the same function, different representations can yield very different circuits and thus costs. Let’s take a 32-bit addition as function \(\mathsf{add}(x,y)\). The inputs \(x\) and \(y\) are two 32-bit numbers, the output should be their sum truncated to 32-bit.
If we now represent this function in a Boolean circuit, we may use 32 full-adders that are connected in a ripple-carry adder [wikipedia]. The primary cost is 32 AND gates. Now, if our MPC protocol supports arithmetic in \(\mathbb{Z}_{32}\), i.e. \(+\)/\(\cdot\) modulo \(2^{32}\), the 32-bit addition now is a linear operation with virtually no cost!

This brings us to the research question of our work. What optimizations in the circuit cost can we find for a certain class of functions (in our case: SPN primitives, what this is we will see later) when we use arithmetic circuits instead of Boolean circuits to represent the function?

In the following, we use arithmetic circuits in \(\mathbb{GF}(2^4)\) and \(\mathbb{GF}(2^8)\) [wikipedia] and assume that the underlying MPC protocol has the following operations. We will also use \([x]\) to denote secret-shared values.

OperationResultCost
Linear: \(a \cdot [x] + [y] + b\)\([a \cdot x + y + b]\)–
Multiplication \([x] \cdot [y]\)\([xy]\)1 multiplication
in 1 round of communication
Bit-Decomposition \([b_0 + b_1 X + \dots + b_m X^m]\)\([b_0], \dots, [b_m]\)\(m\) random bits
in 1 round of communication
Cost of MPC for our protocol

The bit-decomposition allows us to retrieve single bits/coefficients of the value in the field as individual shares. The inverse operation, from multiple bits into a single share is a linear operation.

SPN Primitives

Many symmetric-key primitives follow the “substitution-permutation network” design. Our two implementation targets, SKINNY and PHOTON are SPN primitives.

A state is iteratively changed by a round function. The round function usually follows the same steps. In the following, we briefly discuss the round function of SKINNY.

SKINNY round function from [Cryptology ePrint Archive, Paper 2016/660]

The state is represented as a 4×4 matrix of cells. Each cell contains 4 or 8 bits. The round function first applies the S-box to each cell, then adds round constants and the round (twea)key, permutes the position of a cell in the matrix and finally mixes the cells via a matrix multiplication.

If we represent the state as \(\vec{M}\), all but the first step in the round function are linear:

  • AddRoundTweakey: \([\vec{M}] + \vec{C} + [\vec{RK}]\) (note that the round key matrix \(RK\) is also secret-shared since the key is.
  • ShiftRows: Since this step only permutes the position of a cell in \(\vec{M}\), this essentially only “re-wires” the circuit.
  • MixColumns: \(\vec{A} \cdot [\vec{M}]\) where \(\vec{A}\) is a fixed matrix.

Therefore, we focus on computing the S-box.

Baseline: Representation as Boolean Circuit

At first, let’s setup a baseline. We encode the state as a matrix of cells where each cell contains 4 or 8 shares (depending on the SKINNY instance) that each hold one bit. In this representation, multiplication naturally turns to AND and addition is bit-wise XOR. The linear steps in the SPN primitive, ART, ShiftRows and MixColumns, are linear and can be expressed with XOR/addition only.
In the SKINNY reference, the authors already identify a Boolean formula to compute the S-box. This formula is depicted below and requires the computation of 4 multiplications per evaluation.

Computing the SKINNY 4-bit S-box when having Boolean shares

Computing the S-box via Polynomial Decomposition

Now, we represent each cell in the state matrix as a single share. The bits \(b_0, \dots, b_3\) will be encoded into a field element by putting bit 0 as coefficient 0, bit 1 as coefficient 1 and so on.
For example, 0111 is encoded as \(0 \cdot 1 + 1 \cdot X + 1 \cdot X^2 + 1 \cdot X^3\). We refer to this encoding when writing numbers in hex, e.g., 0x7.

Then we interpolate the S-box by mapping all inputs 0x0 .. 0xf to \(\mathcal{S}(\)0x0\()\) .. \(\mathcal{S}(\)0xf\()\) and \(\mathcal{S}(\cdot)\) is the S-box. The resulting polynomial \(P(z)\) can be evaluated directly. Details can be found in the paper. However, a direct evaluation requires more multiplications than 4 and thus doesn’t beat the baseline.
We therefore use a different approach by decomposing the polynomial \(P(z)\) into smaller polynomials where we can re-use the intermediate computation results from one evaluation for the other polynomials.

The decomposition from Coron, Roy and Vivek (eprint) can be used for this. For the 4-bit to 4-bit S-box, we set \(P(z) = p_0(z) \cdot q_0(z) + p_1(z)\) under the constraint that the smaller polynomials \(p_0, q_0, p_1\) only contain the monomials \(1,z^2,z^3,z^4,z^6,z^8,z^9,z^{12}\). We sample random coefficients for \(q_0\) and find that the resulting linear system admits a solution. Further, the system has full rank and therefore any 4-bit to 4-bit S-box can be decomposed this way.

This leaves us to compute the monomials. For this, we use another beneficial property of the field \(\mathbb{GF}(2^\ell)\). We can compute the coefficients of a squared value as a linear operation if the coefficients are available separately.

  1. The share \([z] = [b_0 + b_1 X + b_2 X^2 + b_3 X^3]\) is bit-decomposed into four shares \([b_0]\), \([b_1]\), \([b_2]\) and \([b_3]\).
  2. The coefficients of the square \(z^2\) can be computed using a linear operation: \(\vec{A}_{\mathsf{sq}} \cdot ([b_0], [b_1], [b_2], [b_3])^T\). Now we have \([z^2]\).
  3. Repeat step 2 to obtain \(z^4\) and \(z^8\).
  4. To compute powers of \(z^3\), we use regular MPC multiplication to obtain a share of \([z^3]\) by multiplying \([z] \cdot [z^2]\).
  5. Repeat steps 1-3 to compute \(z^6, z^{12}, z^{9}\).

Results

We implemented the baseline, the approach using polynomial decomposition and a few other approaches (see paper) in a three-party setting using MASCOT which is a MPC protocol that tolerates a dishonest majority of malicious adversaries. The approach using polynomial decomposition (denoted CRV decomposition in the figure below) improves over the baseline with \(\approx 49\)% less communication and \(\approx 18\)% faster execution.

Benchmark results

This blog post simplified certain aspects. For instance, MASCOT cannot directly compute in \(\mathbb{GF}(2^4)\) since this would be insecure as it reduces the probability of successful cheating to \(2^{-4}\). Instead, we embed \(\mathbb{GF}(2^4)\) into \(\mathbb{GF}(2^{40})\). We selected embeddings that require the least linear operations for computing the embedding and inversing it.
More details can be found in the paper. We published code for the MPC implementation but also SageMath notebooks to

  • find interpolating polynomials,
  • construct various addition chains,
  • decompose polynomials using CRV decomposition and
  • compute embeddings for arbitrary binary extension fields.

The code can be found here.