Generic functions vectorized byte

byte_vector_AND(input)

Computes the result of the AND operation

INPUT:

INPUT: - inputlist; A list of numpy byte matrices to be ANDed, each with one row per byte, and one column per

sample.

byte_vector_MODADD(input)

Computes the result of the MODADD operation.

INPUT:

  • inputlist; 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:

  • inputlist; 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:

  • inputlist; A list of one numpy byte matrix to be negated, with one row per byte, and one column per

    sample

byte_vector_OR(input)

Computes the result of the OR operation.

INPUT:

INPUT: - inputlist; A list of numpy byte matrices to be ORed, each with one row per byte, and one column per

sample.

byte_vector_ROTATE(input, rotation_amount, input_bit_size)

Computes the result of the bitwise ROTATE operation.

INPUT:

  • inputlist; A list of one numpy byte matrix to be rotated, with one row per byte, and one column per sample.

  • input_sizeinteger; size in bits of value to be shifted

  • rotation_amountinteger; the value of the rotation, positive for right and

    negative for left

byte_vector_SBOX(val, sbox, input_bit_size)

Computes the result of the SBox operation.

INPUT:

  • valnp.array(dtype = np.uint8) A numpy matrix with one row per byte and one column per sample.

  • sboxnp.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:

  • inputlist; A list of one numpy byte matrix to be shifted, with one row per byte, and one column per sample.

  • input_sizeinteger; size in bits of value to be shifted

  • shift_smountinteger; the value of the shift, positive for right and

    negative for left

byte_vector_SHIFT_BY_VARIABLE_AMOUNT(input, input_size, shift_direction)

Computes the bitwise shift by variable amount operation.

INPUT:

  • inputlist; A list of one numpy byte matrix to be shifted, with one row per byte, and one column per sample.

  • input_sizeinteger; size in bits of value to be shifted

  • shift_directioninteger; the value of the shift, positive for right and

    negative for left

byte_vector_XOR(input)

Computes the result of the XOR operation.

INPUT: - inputlist; A list of numpy byte matrices to be XORed, each with one row per byte, and one column per

sample.

byte_vector_is_consecutive(l)

Return True if the bits in the list are consecutive.

INPUT:

  • llist; 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:

  • inputnp.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per sample.

  • matrixlist; a list of lists of 0s and 1s

byte_vector_mix_column(input, matrix, mul_table, word_size)

Computes the mix_column operation.

INPUT:

  • inputnp.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per sample.

  • matrixlist; a list of lists of integers

  • mul_tablesdictionary; 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:

  • inputnp.array(dtype = np.uint8) A numpy matrix with one row per byte, and one column per byte.

  • matrixlist; 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:

  • namestring The name of the vector, for display purposes

  • xnp.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_inputslist; the variables involved in the operation, mapped by real_bits and real_inputs

  • real_bitslist; a list of lists, where real_bits[0] contains all the lists of bits to be used for the

    first input of the operation

  • real_inputslist; a list of lists, where real_inputs[0] contains all the indexes of the variables to be

    used for the first input of the operation

  • number_of_inputsinteger; an integer representing the number of inputs expected by the operation

  • words_per_inputinteger; the number of 8-bit words to be reserved for each of the inputs

  • actual_inputs_bitsinteger; 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_inputslist A list of lists of integers (one per cipher input position) - cipher_inputs_bit_sizelist 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_outputslist A list containing one numpy array returned by evaluate_vectorized - cipher_output_bit_sizeinteger 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:

  • llist; 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: - valueslist A list of integers - bit_sizeinteger The bit size of the elements of values.