Component analysis tests

class CipherComponentsAnalysis(cipher)

Bases: object

component_analysis_tests()

Return a list of properties for all the operation used in a cipher

EXAMPLES:

sage: from claasp.ciphers.toys.fancy_block_cipher import FancyBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import CipherComponentsAnalysis
sage: fancy = FancyBlockCipher(number_of_rounds=3)
sage: components_analysis = CipherComponentsAnalysis(fancy).component_analysis_tests()
sage: len(components_analysis['test_results'])
9
get_all_operations()

Return a dictionary for which the keys are all the operations that are used in the cipher.

The attributes are a list containing:
  • a component with the operation under study;

  • number of occurrences of the operation;

  • list of ids of all the components with the same underlying operation.

INPUT:

  • cipherCipher object; a cipher instance

EXAMPLES:

sage: from claasp.ciphers.toys.fancy_block_cipher import FancyBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import CipherComponentsAnalysis
sage: fancy = FancyBlockCipher(number_of_rounds=3)
sage: cipher_operations = CipherComponentsAnalysis(fancy).get_all_operations()
sage: list(cipher_operations.keys())
['sbox', 'linear_layer', 'XOR', 'AND', 'MODADD', 'ROTATE', 'SHIFT']
print_component_analysis_as_radar_charts(results=None)

Return a graph that can be plot to visualize the properties of all the operations of a cipher in a spider graph

EXAMPLES:

sage: from claasp.ciphers.toys.fancy_block_cipher import FancyBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import CipherComponentsAnalysis
sage: fancy = FancyBlockCipher(number_of_rounds=3)
sage: CipherComponentsAnalysis(fancy).print_component_analysis_as_radar_charts()

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=3)
sage: from claasp.cipher_modules.component_analysis_tests import CipherComponentsAnalysis
sage: CipherComponentsAnalysis(speck).print_component_analysis_as_radar_charts()
binary_matrix_of_linear_component(component)

Return the binary matrix of a linear component.

INPUT:

  • componentComponent object; a component from the cipher

EXAMPLES:

sage: from claasp.ciphers.toys.fancy_block_cipher import FancyBlockCipher as fancy
sage: from claasp.cipher_modules.component_analysis_tests import binary_matrix_of_linear_component
sage: fancy = fancy(number_of_rounds=3)
sage: rot_component = fancy.get_component_from_id('rot_1_11')
sage: binary_matrix_of_linear_component(rot_component)
[0 0 0 1 0 0]
[0 0 0 0 1 0]
[0 0 0 0 0 1]
[1 0 0 0 0 0]
[0 1 0 0 0 0]
[0 0 1 0 0 0]
branch_number(component, type, format)

Compute the differential branch number of the given matrix.

INPUT:

  • componentComponent object; a component from the cipher

  • typestring; the type of branch_number we are looking for, ‘linear’ or ‘differential’

  • formatstring; specifies if we are looking for ‘bit’ or ‘word’ branch number

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import branch_number
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: branch_number(mix_column_component, 'differential', 'word')
5
calculate_weights_for_linear_layer(component, format, type)
calculate_weights_for_mix_column(component, format, type)
field_element_matrix_to_integer_matrix(matrix)

Converts a matrix of field elements to the corresponding integer matrix representation

INPUT:

  • matrixMatrix object; a matrix whose entries are field elements

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field, field_element_matrix_to_integer_matrix
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
....: mix_column_component.input_bit_size, mix_column_component.output_bit_size)
sage: mc_matrix
[    a a + 1     1     1]
[    1     a a + 1     1]
[    1     1     a a + 1]
[a + 1     1     1     a]
sage: field_element_matrix_to_integer_matrix(mc_matrix)
[2 3 1 1]
[1 2 3 1]
[1 1 2 3]
[3 1 1 2]
get_inverse_matrix_in_integer_representation(component)

Returns the inverse matrix in its integer representation

INPUT:

  • componentComponent object; a component from the cipher

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import get_inverse_matrix_in_integer_representation
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: get_inverse_matrix_in_integer_representation(mix_column_component)
[14 11 13  9]
[ 9 14 11 13]
[13  9 14 11]
[11 13  9 14]

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import get_inverse_matrix_in_integer_representation
sage: midori = MidoriBlockCipher(number_of_rounds=3)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_20')
sage: m = get_inverse_matrix_in_integer_representation(mix_column_component)
sage: m.dimensions()
(16, 16)
has_maximal_branch_number(component)

INPUT:

  • componentComponent object; a component from the cipher

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.twofish_block_cipher import TwofishBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: twofish = TwofishBlockCipher(number_of_rounds=2)
sage: mix_column_component = twofish.get_component_from_id('mix_column_0_1')
sage: has_maximal_branch_number(mix_column_component)
True

sage: from claasp.ciphers.block_ciphers.twofish_block_cipher import TwofishBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: twofish = TwofishBlockCipher(number_of_rounds=2)
sage: mix_column_component = twofish.get_component_from_id('mix_column_0_19')
sage: has_maximal_branch_number(mix_column_component)
True

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: midori = MidoriBlockCipher()
sage: mix_column_component = midori.get_component_from_id('mix_column_0_20')
sage: has_maximal_branch_number(mix_column_component)
False

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: has_maximal_branch_number(mix_column_component)
True
instantiate_matrix_over_correct_field(matrix, polynomial_as_int, word_size, input_bit_size, output_bit_size)

Return a binary matrix based on the description of a component.

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field
sage: midori = MidoriBlockCipher(number_of_rounds=2)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_20')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
....: mix_column_component.input_bit_size, mix_column_component.output_bit_size)

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field
sage: midori = MidoriBlockCipher(number_of_rounds=2)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_21')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
....: mix_column_component.input_bit_size, mix_column_component.output_bit_size)
int_to_poly(integer_value, word_size, variable)