sboxU.core.f2functions package

Dealing with basic operations over the vector space (F_2)^n (and the finite field F_(2^n).

Submodules

sboxU.core.f2functions.cython_functions module

class sboxU.core.f2functions.cython_functions.F2AffineMap

Bases: object

This class models a linear mapping defined over F_2. It encapsulates a C++ class, cpp_F2AffineMap, for speed.

While it implements methods corresponding to matrix operations, such as transpose, it does not rely on a matrix representation internally. Instead, it stores the vectors corresponding to the images of the canonical basis of F_2^n, and operates on these.

Unless you are working on (rather than with sboxU), do not use the constructor of this class. Instead, you should rely on the get_F2AffineMap factory.

get_S_box()
get_image_vectors()
get_input_length()
get_output_length()
inverse()
is_linear()
rank()
transpose()
sboxU.core.f2functions.cython_functions.bit_permutation_F2AffineMap()

A bit permutation is the operation of rearranging the entries in a F2 vector, according to a given permutation.

Args :

p : The lut of the bit permutation.

Returns :

A BinLinearMap corresponding to bit permutation associated to p.

sboxU.core.f2functions.cython_functions.block_diagonal_F2AffineMap()
sboxU.core.f2functions.cython_functions.circ_shift()

A circular shift is the operation of rearranging the entries in a vector, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation.

Args :

x(BinWord) : a positive integer n(int) : the bit length of x shift(int) : a signed integer

Returns :

The integer whose binary decomposition is the result of a circular shift on the binary decomposition of x by ‘shift’ positions. The LSB-first decomposition of x is shifted to the left if shift is positive and to the right otherwise.

sboxU.core.f2functions.cython_functions.circ_shift_F2AffineMap()

A circular shift is the operation of rearranging the entries in a vector, either by moving the final entry to the first position, while shifting all other entries to the next position, or by performing the inverse operation.

Args :
  • n : a positive integer

  • shift : a signed integer

Returns :

A F2AffineMap object which encodes the circular shift by ‘shift’ positions. This linear map is an automorphism of (F_2)^n. As for circ_shift, the LSB-first decomposition of a vector x is shifted to the left if shift is positive and to the right otherwise.

sboxU.core.f2functions.cython_functions.from_bin()
sboxU.core.f2functions.cython_functions.get_F2AffineMap()
sboxU.core.f2functions.cython_functions.hamming_weight()

Ultimately call a C++ intrinsic to return the Hamming weight of the vector corresponding to the binary representation of x.

Parameters:

x (BinWord) – a positive integer

Returns:

The number of bits set to 1 in the binary representation of x.

sboxU.core.f2functions.cython_functions.identity_F2AffineMap()
sboxU.core.f2functions.cython_functions.linear_combination()
sboxU.core.f2functions.cython_functions.lsb()

The least significant bit.

Parameters:

x (BinWord) – a positive integer

Returns:

The integer giving the position of the least significant bit set to 1 of x, unless x is 0. In this case, returns 0.

sboxU.core.f2functions.cython_functions.msb()

The most significant bit.

Parameters:

x (BinWord) – a positive integer

Returns:

The integer giving the position of the most significant bit of x, so that x >> msb(x) is always 1, unless x is 0. In this case, returns 0.

sboxU.core.f2functions.cython_functions.oplus()

Essentially a wrapper for the operation ^ in C++. Its purpose is to ensure that a XOR is performed regardless of the extension of the script.

Parameters:
  • x (BinWord) – a positive integer

  • y (BinWord) – a positive integer

Returns:

A positive integer equal to the XOR of x and y.

sboxU.core.f2functions.cython_functions.rank_of_vector_set()

Computes the rank of a set of integers interpreted as binary vectors.

Parameters:

l – a list of positive integers whose binary representation corresponds to the vector we investigate.

Returns:

An integer equal to the rank of the matrix obtained by concatenating these vectors. Equivalently, returns the dimension of their span.

sboxU.core.f2functions.cython_functions.scal_prod()

The canonical scalar product in F_2. Wraps a C++ function relying on specific intrinsincs.

Parameters:
  • x (BinWord) – a positive integer

  • y (BinWord) – a positive integer

Returns:

The scalar product x⋅y, i.e. the modulo 2 sum of the products x_i y_i, where i goes from 0 to 63.

sboxU.core.f2functions.cython_functions.to_bin()
sboxU.core.f2functions.cython_functions.xor()
sboxU.core.f2functions.cython_functions.zero_F2AffineMap()

sboxU.core.f2functions.field_arithmetic module

sboxU.core.f2functions.field_arithmetic.ffe_from_int(x, gf)[source]
sboxU.core.f2functions.field_arithmetic.ffe_to_int(x)[source]
sboxU.core.f2functions.field_arithmetic.i2f_and_f2i(gf)[source]

A Helper function to deal with finite field elements and their integer representations.

Returns:

A pair of functions, namely the functions mapping field elements to integers (f2i) and the one mapping integers to field elements (i2f).

Parameters:

gf – the finite field with which we want to interact. Could have been obtained using e.g. GF(q)