Generic functions vectorized byte¶
- byte_vector_AND(input)¶
Computes the result of the AND operation
INPUT:
INPUT: -
input– list; A list of numpy byte matrices to be ANDed, each with one row per byte, and one column persample.
- byte_vector_MODADD(input)¶
Computes the result of the MODADD operation.
INPUT:
input– list; A list of numpy byte matrices to be added, each with one row per byte, and one column per sample.
- byte_vector_MODSUB(input)¶
Computes the result of the MODSUB operation.
INPUT:
input– list; A list of 2 numpy byte matrices to be subtracted, each with one row per byte, and one column per sample.
- byte_vector_NOT(input)¶
Computes the result of the NOT operation.
INPUT:
input– list; A list of one numpy byte matrix to be negated, with one row per byte, and one column persample
- byte_vector_OR(input)¶
Computes the result of the OR operation.
INPUT:
INPUT: -
input– list; A list of numpy byte matrices to be ORed, each with one row per byte, and one column persample.
- byte_vector_ROTATE(input, rotation_amount, input_bit_size)¶
Computes the result of the bitwise ROTATE operation.
INPUT:
input– list; A list of one numpy byte matrix to be rotated, with one row per byte, and one column per sample.input_size– integer; size in bits of value to be shiftedrotation_amount– integer; the value of the rotation, positive for right andnegative for left
- byte_vector_SBOX(val, sbox, input_bit_size)¶
Computes the result of the SBox operation.
INPUT:
val– np.array(dtype = np.uint8) A numpy matrix with one row per byte and one column per sample.sbox– np.array(dtype = np.uint8) An integer numpy array representing the SBox.
- byte_vector_SHIFT(input, shift_amount)¶
Computes the result of the bitwise SHIFT operation.
INPUT:
input– list; A list of one numpy byte matrix to be shifted, with one row per byte, and one column per sample.input_size– integer; size in bits of value to be shiftedshift_smount– integer; the value of the shift, positive for right andnegative for left
- byte_vector_SHIFT_BY_VARIABLE_AMOUNT(input, input_size, shift_direction)¶
Computes the bitwise shift by variable amount operation.
INPUT:
input– list; A list of one numpy byte matrix to be shifted, with one row per byte, and one column per sample.input_size– integer; size in bits of value to be shiftedshift_direction– integer; the value of the shift, positive for right andnegative for left
- byte_vector_XOR(input)¶
Computes the result of the XOR operation.
INPUT: -
input– list; A list of numpy byte matrices to be XORed, each with one row per byte, and one column persample.
- byte_vector_is_consecutive(l)¶
Return True if the bits in the list are consecutive.
INPUT:
l– list; a list of bit positions, in reverse order
EXAMPLES:
sage: from claasp.cipher_modules.generic_functions_vectorized_byte import byte_vector_is_consecutive sage: L=[3, 2, 1, 0] sage: byte_vector_is_consecutive(L) == True True
- byte_vector_linear_layer(input, matrix)¶
Computes the linear layer operation.
INPUT:
input– np.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per sample.matrix– list; a list of lists of 0s and 1s
- byte_vector_mix_column(input, matrix, mul_table, word_size)¶
Computes the mix_column operation.
INPUT:
input– np.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per sample.matrix– list; a list of lists of integersmul_tables– dictionary; a dictionary giving the multiplication table by x at key x
- byte_vector_mix_column_poly0(input, matrix, word_size)¶
Computes the mix_column operation, special case where poly=0.
INPUT:
input– np.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per byte.matrix– list; a list of lists of integers
- byte_vector_print_as_hex_values(name, x)¶
Prints a byte vector x as an hex value - used for debugging
INPUT:
name– string The name of the vector, for display purposesx– np.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per word.
- byte_vector_select_all_words(unformated_inputs, real_bits, real_inputs, number_of_inputs, words_per_input, actual_inputs_bits)¶
Parses the inputs from the cipher into a list of numpy byte arrays, each corresponding to one input to the function.
INPUT:
unformatted_inputs– list; the variables involved in the operation, mapped by real_bits and real_inputsreal_bits– list; a list of lists, where real_bits[0] contains all the lists of bits to be used for thefirst input of the operation
real_inputs– list; a list of lists, where real_inputs[0] contains all the indexes of the variables to beused for the first input of the operation
number_of_inputs– integer; an integer representing the number of inputs expected by the operationwords_per_input– integer; the number of 8-bit words to be reserved for each of the inputsactual_inputs_bits– integer; the bit size of the variables in unformatted_inputs
- cipher_inputs_to_evaluate_vectorized_inputs(cipher_inputs, cipher_inputs_bit_size)¶
Converts cipher_inputs from integers to the format expected by evaluate_vectorized. If cipher_inputs is a list of integers (one per input position), then the function returns a list of numpy matrices that can be used to evaluate a single set of inputs to the cipher (with a similar api to cipher.evaluate). If cipher_inputs is a list of lists of integers (one per input position), then the function returns a list of numpy matrices that can be used to evaluate multiple set of inputs to the cipher. The produced matrices contain one row per byte, and one column per value. If needed, the values are padded with zeroes on the left.
INPUT: -
cipher_inputs– list A list of lists of integers (one per cipher input position) -cipher_inputs_bit_size– list The inputs bit sizes of the cipher.
- evaluate_vectorized_outputs_to_integers(evaluate_vectorized_outputs, cipher_output_bit_size)¶
Converts the outputs of evaluate_vectorized (a list containing a single numpy matrix) to a list of integers (one per output/row of the matrix)
INPUT: -
evaluate_vectorized_outputs– list A list containing one numpy array returned by evaluate_vectorized -cipher_output_bit_size– integer The output bit size of the cipher
- generate_formatted_inputs(actual_inputs_bits, i, output, pos, real_bits, real_inputs, unformatted_inputs, words_per_input)¶
- get_number_of_bytes_needed_for_bit_size(bit_size)¶
- get_number_of_consecutive_bits(l)¶
Return the number of consecutive numbers from the start of list l, in decreasing order.
INPUT:
l– list; a list of bit positions, in reverse order
EXAMPLES:
sage: from claasp.cipher_modules.generic_functions_vectorized_byte import get_number_of_consecutive_bits sage: L=[4, 3, 5, 7, 2] sage: get_number_of_consecutive_bits(L) == 1 True
- integer_array_to_evaluate_vectorized_input(values, bit_size)¶
Converts the bit_size integers from the values array to the representation accepted by evaluate_vectorized, a numpy matrix of unsigned 8-bit integers (one row per byte, one column per value). If needed, the values are padded with zeroes on the left. If the cipher takes multiple inputs, this function needs to be called once for each.
INPUT: -
values– list A list of integers -bit_size– integer The bit size of the elements of values.