sboxUv2.core.f2functions package
Dealing with basic operations over the vector space (F_2)^n (and the finite field F_(2^n).
Submodules
sboxUv2.core.f2functions.cython_functions module
- class sboxUv2.core.f2functions.cython_functions.BinLinearMap
Bases:
objectThis class models a linear mapping defined over F_2. It encapsulates a C++ class, cpp_BinLinearMap, 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 Blm factory.
- get_image_vectors(self)
- get_input_length(self) int
- get_output_length(self) int
- inverse(self) BinLinearMap
- rank(self) int
- transpose(self) BinLinearMap
- sboxUv2.core.f2functions.cython_functions.Blm(l, input_length=None, output_length=None) BinLinearMap
- sboxUv2.core.f2functions.cython_functions.block_diagonal_BinLinearMap(A, B) BinLinearMap
- sboxUv2.core.f2functions.cython_functions.circ_shift(x: int, n: int, shift: int) BinWord
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.
- sboxUv2.core.f2functions.cython_functions.circ_shift_BinLinearMap(n: int, shift: int) BinLinearMap
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 BinLinearMap 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.
- sboxUv2.core.f2functions.cython_functions.from_bin(l: vector[int]) BinWord
- sboxUv2.core.f2functions.cython_functions.hamming_weight(x: int) int
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.
- sboxUv2.core.f2functions.cython_functions.identity_BinLinearMap(n: int) BinLinearMap
- sboxUv2.core.f2functions.cython_functions.linear_combination(v: vector[uint64_t], mask: int) BinWord
- sboxUv2.core.f2functions.cython_functions.lsb(x: int) int
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.
- sboxUv2.core.f2functions.cython_functions.msb(x: int) int
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.
- sboxUv2.core.f2functions.cython_functions.oplus(x: int, y: int) BinWord
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.
- sboxUv2.core.f2functions.cython_functions.rank_of_vector_set(l: vector[uint64_t]) int
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.
- sboxUv2.core.f2functions.cython_functions.scal_prod(x: int, y: int) BinWord
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.
- sboxUv2.core.f2functions.cython_functions.to_bin(x: int, n: int) list
- sboxUv2.core.f2functions.cython_functions.xor(*args) BinWord
- sboxUv2.core.f2functions.cython_functions.zero_BinLinearMap(n: int, m: int) BinLinearMap
sboxUv2.core.f2functions.field_arithmetic module
- sboxUv2.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)