sboxUv2.core.sbox package

This module contains the various utilities needed to store and generate S-boxes.

The idea here is not yet to study S-boxes, only to generate them, and store them in a way that allows calling C++ functions without

Submodules

sboxUv2.core.sbox.cython_functions module

sboxUv2.core.sbox.cython_functions.F2_trans(additive_cstte, field=None, bit_length=None)

Returns an S_box containing the lookup table of a simple XOR over a given field extension of F_2.

If additive_cstte is an integer, then either field or bit_length must be set. If it is a field element, both field and bit_length will be ignored.

Parameters:
  • additive_cstte – the constant to add. Can be a field element or an integer. If an integer, then the field used must be specified.

  • field – the field in which the multiplication must be made if additive_cstte is an integer.

  • bit_length – the bit-length to use for both the input and output if additive_cstte is an integer.

Returns:

An S_box instance

class sboxUv2.core.sbox.cython_functions.S_box

Bases: object

The S_box class stores the lookup table of an vectorial boolean function, and provides useful methods to interact with it.

Objects of this class should be initialized using the :py:func:Sb function.

component(a)

Returns: An S_box instance mapping n bits to 1 corresponding to the component x mapsto S(x) cdot a, where cdot is the standard scalar product.

coordinate(i)
Parameters:

i – the index of the coordinate, where 0 is the bit of lowest weight.

Returns:

An S_box instance mapping n bits to 1 corresponding to the i-th coordinate of S.

derivative(delta)

Returns: An S_box of the same dimension as S corresponding to its derivative in the direction delta, i.e. x mapsto S(x+delta)+S(x).

get_input_length()
get_output_length()
input_space()
input_space_size()
inverse()
Returns:

An S_box instance corresponding to the compositional inverse of the current S_box.

If the current S_box is not invertible, will probably crash.

is_invertible()

Returns: True if the current S_box is a bijection, False otherwise.

lut()
name()
output_space()
output_space_size()
rename(name)
class sboxUv2.core.sbox.cython_functions.S_box_fp

Bases: object

coordinate(i)
Parameters:

i – the index of the coordinate, where 0 is the Fp word of lowest weight.

Returns:

An S_box instance mapping n Fp words to 1 corresponding to the i-th coordinate of S.

derivative(delta)
Parameters:

i – the index of the coordinate, where 0 is the bit of lowest weight.

Returns:

An S_box_fp instance mapping n Fp words to 1 corresponding to the i-th coordinate of S.

get_input_size()
get_name()
get_output_size()
get_p()
input_space()
input_space_size()
lut()
output_space()
output_space_size()
rename(name)
sboxUv2.core.sbox.cython_functions.Sb(s, name=None)

Turns its input into an object of the S_box class.

If it is already an S_box instance, simply returns its input. Otherwise, builds the lookup table, and then create the corresponding S_box instance.

Parameters:
  • s – an object of a class that can be turned into an S_box.

  • name – the name to give the object. If none is provided, one will be picked using sboxU_SBOXES_COUNTER.

sboxUv2.core.sbox.cython_functions.identity_S_box(length)

Returns an S_box instance corresponding to the identity function, i.e. the one mapping x to itself.

sboxUv2.core.sbox.cython_functions.new_sbox_name()

Returns a unique name that can be given to an S-box.

It uses the module variable sboxU_SBOXES_COUNTER to achieve this goal by incrementing it each time it is used.

Returns:

A bytearray corresponding to the next unique S_box name.

sboxUv2.core.sbox.misc module

This module contains pure python methods to generate simple S_box instances.

sboxUv2.core.sbox.misc.F2_mul(coeff, field=None)[source]

Returns an S_box containing the lookup table of a multiplication in an extension of F_2.

Parameters:
  • coeff – the coefficient by which to multiply. Can be a field element or an integer. If an integer, then the field used must be specified.

  • field – the field in which the multiplication must be made. If unspecified, the parent field of coeff is used.

sboxUv2.core.sbox.misc.inverse(s)[source]

Compositional inversion.

Parameters:

s (-) – an S_boxable object.

Returns:

An S_box object corresponding to the compositional inverse of s.

sboxUv2.core.sbox.misc.is_permutation(s)[source]

Returns True if and only if s is an S_boxable object corresponding to a bijective function.

Parameters:

s (-) – an S_boxable object

Returns:

True if and only if s corresponds to a bijection.

sboxUv2.core.sbox.misc.monomial(d, field)[source]

Returns an S_box containing the LUT of a monomial operating on the given field.

Parameters:
  • d – the exponent of the monomial (an integer)

  • field – a finite field instance assumed to be of characteristic 2.

sboxUv2.core.sbox.misc.random_function_S_box(input_bit_length, output_bit_length, name=None)[source]

Uses the standard randint function to generate a random S_box instance that is very unlikely to be bijective.

Parameters:
  • input_bit_length – the bit-length of the input of the function.

  • output_bit_length – the bit-length of its output.

  • name – a string intended to label the output.

Returns:

An S_box instance obtained by picking each output uniformly at random in the set {0, .., 2**output_bit_length-1}.

sboxUv2.core.sbox.misc.random_permutation_S_box(bit_length, name=None)[source]

Uses the standard shuffle function to generate a random bijective S_box instance.

Parameters:
  • bit_length – the bit-length of the input (and output) of the function.

  • name – a string intended to label the output.

Returns:

An S_box instance picked uniformly at random from the set of all permutations operating on the set {0, .., 2**bit_length-1}.