SBox module
This module implements SBox functionality for generating all types of keys.
It implements core operations for cryptographic key generation using an SBox and the Galois Field for bitwise arithmetic.
Key functions include multiplication, finding inverses, circular bit shifts, and non-linear transformations.
How it works?
Represents the primitive polynomial (0x11b) used in Galois Field arithmetic.
Calculates the multiplication of two numbers in the GF using bitwise operations and the primitive polynomial:
Computes the inverse of a number in the Galois Field using the extended Euclidean algorithm.
Performs a circular left shift operation on a binary number: \begin{align*} \text{rotate_left}(x, n) &= \text{result} \\ \text{n_int} &= \text{to_int}(n) \\ \text{shift_amount} &= \text{to_int}(8 - n) \\ \text{result} &= (x \ll n\_int) \,|\, (x \gg \text{shift_amount}) \end{align*}
Applies an affine transformation used in the SBox for non-linearity: \begin{align*} \text{affine_transformation}(x) &= \text{result} \\ \text{operations} &= [0, 1, 2, 3, 4, 5, 6, 7] \\ \text{b} &= 0x63 \\ \text{result} &= \text{fold_left}(\text{operations}, b, \lambda \text{acc}, i \rightarrow (\text{bit} = (x \gg i) \& 1) \,?\, (\text{acc} \oplus (bit \ll i)) \,:\, \text{acc}) \end{align*}
Generates an S-Box table by applying the affine transformation to a range of values: \begin{align*} \text{create_sbox_table}() &= \text{result} \\ \text{range} &= [0, 1, 2, \ldots, 255] \\ \text{result} &= \text{map}(\text{range}, \lambda i \rightarrow \text{inv} = (i = 0) \,?\, 0 \,:\, \text{gf_inv}(i), \text{affine_transformation}(\text{inv})) \end{align*}
Last updated