题目
AES S 盒是 FIPS-197 第 5.1.1 节定义的 256 个字节上的固定置换 S:先在模 x^8 + x^4 + x^3 + x + 1 的 GF(2^8) 中取乘法逆元(0 映射为 0),再作 GF(2) 上的仿射变换。例如 S(0x00) = 0x63,S(0x01) = 0x7c,S(0x53) = 0xed。
找出一个在全部 256 个输入上计算 S、门数尽可能少的电路。门基为二输入 AND、XOR 和 XNOR 门(XNOR(a, b) = 1 ⊕ a ⊕ b),每个门计为 1 个门,扇出不限。深度不计分。没有 NOT 门,也没有常数输入;取反必须并入 XNOR 门。这是 Boyar 和 Peralta、Circuit Minimization Team 页面以及 NIST 电路复杂度列表所采用的模型。
在更丰富的门基中得到的门数与本门基下的门数不可比。Maximov 和 Ekdahl(2019)报告了一个使用 NAND、NOR 和 MUX 门的 102 门电路,Reyhani-Masoleh、Taha 和 Ashmawy(2018)使用了更丰富的门库。这类电路只有在改写为 AND、XOR 和 XNOR 电路后才被接受,改写后每个门都计数。
为什么重要
S 盒是 AES 唯一的非线性步骤。AES 是部署最广泛的分组密码,在 AES 的硬件实现和位切片软件实现中,S 盒电路占成本的主要部分。更小的电路意味着更小、功耗更低的 AES 核,以及更快的常数时间软件实现。对于掩码(抗侧信道)实现,AND 门的数量决定主要成本。S 盒所需的最少 AND 门数,即其乘法复杂度,是一个相关的未解决问题:Boyar 和 Peralta 的电路用 32 个 AND 门即可实现,2026 年 NIST 列表中加入了含 28 个 AND 门的电路(Nasr)。
该门基下的已知最小规模从 115 个门(Boyar 和 Peralta,2010)降到 113 个(Calik,发布在 Circuit Minimization Team 页面上),再降到 110 个(NIST 列表,2026)和 106 个(Jain,2026)。门数不超过 105 的电路将是该模型下 AES S 盒的已知最小电路。
Few Shots 上的推进
从预设基线开始,每一行是一次经验证器复算的有效突破
- #0106预设基线
- #1?等待挑战者
证书格式
- 文件名为
certificate.json,形如 {"gates": [g1, g2, …], "outputs": [w0, …, w7]},不含其他键。 - 输入线为
x0 … x7,其中 xi 是输入字节的第 i 位:x7 是最高有效位,x0 是最低有效位(即 FIPS-197 中的 b7 … b0)。 - 每个门是一个对象
{"op": "AND" | "XOR" | "XNOR", "a": <wire>, "b": <wire>, "out": <new wire>},不含其他键。a 和 b 必须是输入线或列表中前面某个门的输出线,且必须是两条不同的线。out 必须是一个新名字:每条线恰好赋值一次,门的输出线不能与输入线同名。 - 线名匹配
[A-Za-z_][A-Za-z0-9_]{0,31}(ASCII)。 outputs 恰好列出 8 条线;第 i 项是输出位 yi(S(x) 的第 i 位)对应的线,因此最后一项是最高有效位。输出可以是任何输入线或门的输出线,两个输出可以共用一条线。- 验证器一次性在全部 256 个输入上对电路求值(每条线是一个 256 位整数),要求每个输出位都等于内嵌的 FIPS-197 表;测试会根据 GF(2^8) 求逆和仿射变换重新计算该表。
- 门数至多 2000。得分为门数,包括输出未被使用的门。
- 文件为 UTF-8 编码的 JSON,大小不超过 256 KiB,嵌套不超过 8 层,不含重复键。
- 规范形式:按固定的拓扑顺序对线重新编号(输入为 0 … 7,门依次为 8, 9, …):反复在操作数均已编号的门中,选取 (op, 较小的操作数编号, 较大的操作数编号) 最小的门,其中 AND < XOR < XNOR。每个门写成
[op, smaller operand, larger operand],其后是 8 个输出编号。canonical_hash 是规范 JSON 的 sha256,因此重命名线、交换一个门的两个操作数,或以其他顺序列出相互独立的门,都不改变它。
基线
一个含 106 个门(34 个 AND、69 个 XOR、3 个 XNOR)、深度为 24 的电路,来自 Jain(2026)的预印本“Smaller Gate Counts for the AES S-box and Inverse S-box in the AND/XOR/XNOR Model”。它是该门基下已发表的最小电路;论文还给出了第二个 106 门电路(32 个 AND,深度 34)。已发表的更小门数,例如 Maximov 和 Ekdahl 的 102 个门,使用的是更丰富的门基,不适用于此处。
证书由论文仓库中的文件 sbox/circuits/sbox106_d24.json 转换为本格式:其中的信号 U0 … U7(U0 为最高有效位)对应这里的 x7 … x0,输出 S0 … S7(S0 为最高有效位)对应 y7 … y0,第 i 个门对应线 ti。测试还检查了 Circuit Minimization Team 页面上的 113 门电路。
证书为 baseline/certificate.json。复现方法:
python3 problems/p008-aes-sbox-circuit/verify/verify.py problems/p008-aes-sbox-circuit/baseline
来源:FIPS-197;Circuit Minimization Team 页面,113 门电路;Boyar 和 Peralta,SEA 2010;Boyar、Matthews 和 Peralta,J. Cryptology 2013;NIST 电路复杂度,AES S 盒电路;Jain 2026,论文与电路;Maximov 和 Ekdahl,TCHES 2019;Reyhani-Masoleh、Taha 和 Ashmawy,TCHES 2018。
Problem
The AES S-box is the fixed permutation S of the 256 bytes defined in FIPS-197, Section 5.1.1: the multiplicative inverse in GF(2^8) modulo x^8 + x^4 + x^3 + x + 1 (with 0 mapped to 0), followed by an affine map over GF(2). For example S(0x00) = 0x63, S(0x01) = 0x7c, S(0x53) = 0xed.
Find a circuit that computes S on all 256 inputs with as few gates as possible. The gate basis is two-input AND, XOR and XNOR (XNOR(a, b) = 1 ⊕ a ⊕ b), each costing one gate, with unlimited fan-out. Depth is not scored. There is no NOT gate and no constant input; negations have to be absorbed into XNOR gates. This is the model of Boyar and Peralta, of the Circuit Minimization Team page and of the NIST circuit-complexity list.
Gate counts in richer bases are not comparable with this one. Maximov and Ekdahl (2019) report 102 gates with NAND, NOR and MUX gates, and Reyhani-Masoleh, Taha and Ashmawy (2018) use a richer gate library. Such circuits are accepted here only after they are rewritten over AND, XOR and XNOR, and then each gate counts.
Why it matters
The S-box is the only non-linear step of AES, the most widely deployed block cipher, and its circuit dominates the cost of AES in hardware and in bitsliced software. A smaller circuit gives a smaller, lower-power AES core and faster constant-time software. For masked (side-channel protected) implementations the number of AND gates dominates the cost. The fewest AND gates for the S-box, its multiplicative complexity, is a related open problem: 32 AND gates suffice in the circuits of Boyar and Peralta, and circuits with 28 AND gates were added to the NIST list in 2026 (Nasr).
The smallest known size in this basis went from 115 gates (Boyar and Peralta, 2010) to 113 (Calik, posted on the Circuit Minimization Team page), then 110 (NIST list, 2026) and 106 (Jain, 2026). A circuit with 105 gates or fewer would be the smallest known circuit for the AES S-box in this model.
Progress on Few Shots
From the preset baseline, one row per valid breakthrough recomputed by the verifier
- #0106Preset baseline
- #1?Awaiting a challenger
Certificate
- File name
certificate.json, shaped like {"gates": [g1, g2, …], "outputs": [w0, …, w7]}, with no other keys. - The input wires are
x0 … x7, where xi is bit i of the input byte: x7 is the most significant bit and x0 the least significant (bits b7 … b0 in FIPS-197). - Each gate is an object
{"op": "AND" | "XOR" | "XNOR", "a": <wire>, "b": <wire>, "out": <new wire>} with no other keys. a and b must be input wires or outputs of earlier gates in the list, and they must be two different wires. out must be a new name: every wire is assigned exactly once, and no gate output may be named like an input. - Wire names match
[A-Za-z_][A-Za-z0-9_]{0,31} (ASCII). outputs lists exactly 8 wires; entry i is the wire for output bit yi, bit i of S(x), so the last entry is the most significant bit. An output may be any input or gate wire, and two outputs may share a wire.- The verifier evaluates the circuit on all 256 inputs at once (each wire is a 256-bit integer) and requires every output bit to equal the embedded FIPS-197 table, which the tests recompute from GF(2^8) inversion and the affine map.
- At most 2000 gates. The score is the number of gates, including gates whose outputs are not used.
- The file is UTF-8 JSON, at most 256 KiB, nested at most 8 levels, with no duplicate keys.
- Canonical form: wires are renumbered (inputs 0 … 7, then gates 8, 9, …) in a fixed topological order: repeatedly take, among the gates whose operands are already numbered, the one with the smallest (op, smaller operand number, larger operand number), with AND < XOR < XNOR. Each gate is written as
[op, smaller operand, larger operand], followed by the 8 output numbers. canonical_hash is the sha256 of the canonical JSON, so renaming wires, swapping the two operands of a gate or listing independent gates in another order does not change it.
Baseline
A circuit with 106 gates (34 AND, 69 XOR, 3 XNOR) and depth 24, from Jain (2026), "Smaller Gate Counts for the AES S-box and Inverse S-box in the AND/XOR/XNOR Model", preprint. It is the smallest published circuit in this basis; the paper also gives a second 106-gate circuit (32 AND, depth 34). Smaller published counts, such as the 102 gates of Maximov and Ekdahl, use a richer basis and do not apply here.
The certificate is the file sbox/circuits/sbox106_d24.json of the paper's repository, converted to this format: signals U0 … U7 there (U0 most significant) are x7 … x0 here, outputs S0 … S7 there (S0 most significant) are y7 … y0, and gate i is wire ti. The tests also check the 113-gate circuit of the Circuit Minimization Team page.
The certificate is baseline/certificate.json. To reproduce:
python3 problems/p008-aes-sbox-circuit/verify/verify.py problems/p008-aes-sbox-circuit/baseline
Sources: FIPS-197; Circuit Minimization Team page, 113-gate circuit; Boyar and Peralta, SEA 2010; Boyar, Matthews and Peralta, J. Cryptology 2013; NIST circuit complexity, AES S-box circuits; Jain 2026, paper and circuits; Maximov and Ekdahl, TCHES 2019; Reyhani-Masoleh, Taha and Ashmawy, TCHES 2018.