From 4cce1f5430b8798abb705b692724d20c02e96ff2 Mon Sep 17 00:00:00 2001 From: "Rusydi H. Makarim" Date: Fri, 10 Jan 2025 12:05:54 +0700 Subject: [PATCH 1/2] Add inversion function for sage.crypto.sboxes Add inversion mapping in GF(2^n) extending 0 -> 0. Such mapping is used for instance in the AES S-Box. --- src/sage/crypto/sboxes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/sage/crypto/sboxes.py b/src/sage/crypto/sboxes.py index ab0f2759573..cd628632122 100644 --- a/src/sage/crypto/sboxes.py +++ b/src/sage/crypto/sboxes.py @@ -399,6 +399,27 @@ def monomial_function(n, e): return SBox(X**e) +def inversion(n): + r""" + Return the S-Box constructed from the inversion mapping over `\GF{2^n}` extending `0 \mapsto 0` + + INPUT: + + - ``n`` -- size of the S-Box (i.e. the degree of the finite field extension) + + EXAMPLES:: + + sage: from sage.crypto.sboxes import inversion + sage: S4 = inversion(4) + sage: S4.differential_uniformity() + 4 + sage: S5 = inversion(5) + sage: S5.differential_uniformity() + 2 + """ + return monomial_function(n, 2**n - 2) + + # Bijective S-Boxes mapping 9 bits to 9 # ===================================== From 3589aa62521e66c5f4f9cb98e90c7be23840212c Mon Sep 17 00:00:00 2001 From: "Rusydi H. Makarim" Date: Fri, 17 Jan 2025 14:18:33 +0700 Subject: [PATCH 2/2] adjustment to comply with PEP8 --- src/sage/crypto/sboxes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/crypto/sboxes.py b/src/sage/crypto/sboxes.py index cd628632122..e1a1172baad 100644 --- a/src/sage/crypto/sboxes.py +++ b/src/sage/crypto/sboxes.py @@ -401,11 +401,12 @@ def monomial_function(n, e): def inversion(n): r""" - Return the S-Box constructed from the inversion mapping over `\GF{2^n}` extending `0 \mapsto 0` + Return the S-Box constructed from the inversion mapping over `\GF{2^n}` + extending `0 \mapsto 0`. INPUT: - - ``n`` -- size of the S-Box (i.e. the degree of the finite field extension) + - ``n`` -- size of the S-Box EXAMPLES::