Shift component

class SHIFT(current_round_number, current_round_number_of_components, input_id_links, input_bit_positions, output_bit_size, parameter)

Bases: Component

algebraic_polynomials(model)

Return a list of polynomials for bitwise SHIFT.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.fancy_block_cipher import FancyBlockCipher
sage: from claasp.cipher_modules.models.algebraic.algebraic_model import AlgebraicModel
sage: fancy = FancyBlockCipher(number_of_rounds=2)
sage: shift_component = fancy.get_component_from_id("shift_1_12")
sage: algebraic = AlgebraicModel(fancy)
sage: shift_component.algebraic_polynomials(algebraic)
[shift_1_12_y0,
 shift_1_12_y1,
 shift_1_12_y2,
 shift_1_12_y3 + shift_1_12_x0,
 shift_1_12_y4 + shift_1_12_x1,
 shift_1_12_y5 + shift_1_12_x2]
as_python_dictionary()
check_output_size(available_word_sizes, fixed, word_size)
cms_constraints()

Return a list of variables and a list of clauses for shift in CMS CIPHER model.

See also

SAT standard of Cipher for the format.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.cms_constraints()
(['shift_0_0_0',
  'shift_0_0_1',
  'shift_0_0_2',
  ...
  '-shift_0_0_29',
  '-shift_0_0_30',
  '-shift_0_0_31'])
cms_xor_differential_propagation_constraints(model=None)
cms_xor_linear_mask_propagation_constraints(model=None)
cp_constraints()

Return a list of CP declarations and a list of CP constraints for SHIFT component for CP CIPHER model.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.cp_constraints()
([],
 ['constraint shift_0_0[0] = plaintext[36];',
  ...
  'constraint shift_0_0[27] = plaintext[63];',
  'constraint shift_0_0[28] = 0;',
  'constraint shift_0_0[29] = 0;',
  'constraint shift_0_0[30] = 0;',
  'constraint shift_0_0[31] = 0;'])
cp_deterministic_truncated_xor_differential_trail_constraints()
cp_inverse_constraints()

Return a list of CP declarations and a list of CP constraints for SHIFT component for CP INVERSE CIPHER model.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.cp_inverse_constraints()
([],
 ['constraint shift_0_0_inverse[0] = plaintext[36];',
  ...
  'constraint shift_0_0_inverse[27] = plaintext[63];',
  'constraint shift_0_0_inverse[28] = 0;',
   ...
  'constraint shift_0_0_inverse[31] = 0;'])
cp_wordwise_deterministic_truncated_xor_differential_constraints(model)

Return a list of CP declarations and a list of CP constraints for shift component.

This is for CP wordwise deterministic truncated xor differential trail search.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_model import CpModel
sage: from claasp.components.shift_component import SHIFT
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: cp = CpModel(aes)
sage: shift_component = SHIFT(0, 18, ['sbox_0_2', 'sbox_0_6', 'sbox_0_10', 'sbox_0_14'], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], 32, -8)
sage: shift_component.cp_wordwise_deterministic_truncated_xor_differential_constraints(cp)
([],
 ['constraint shift_0_18_active[0] = sbox_0_6_active[0];',
   ...
  'constraint shift_0_18_value[3] = 0;'])
cp_xor_differential_first_step_constraints(model)

Return lists of declarations and constraints for SHIFT component for the CP xor differential first step model.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.models.cp.cp_model import CpModel
sage: from claasp.components.shift_component import SHIFT
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: cp = CpModel(aes)
sage: shift_component = SHIFT(0, 18, ['sbox_0_2', 'sbox_0_6', 'sbox_0_10', 'sbox_0_14'], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], 32, -8)
sage: shift_component.cp_xor_differential_first_step_constraints(cp)
(['array[0..3] of var 0..1: shift_0_18;'],
 ['constraint shift_0_18[0] = sbox_0_6[0];',
  'constraint shift_0_18[1] = sbox_0_10[0];',
  'constraint shift_0_18[2] = sbox_0_14[0];',
  'constraint shift_0_18[3] = 0;'])
cp_xor_differential_propagation_constraints(model=None)
cp_xor_differential_propagation_first_step_constraints(model)
cp_xor_linear_mask_propagation_constraints(model=None)

Return a list of Cp declarations and a list of Cp constraints for SHIFT component for CP xor linear model.

INPUT:

  • modelmodel object (default: None); a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.cp_xor_linear_mask_propagation_constraints()
(['array[0..31] of var 0..1: shift_0_0_i;',
  'array[0..31] of var 0..1: shift_0_0_o;'],
 ['constraint shift_0_0_o[0]=shift_0_0_i[4];',
  'constraint shift_0_0_o[1]=shift_0_0_i[5];',
   ...
  'constraint shift_0_0_o[27]=shift_0_0_i[31];',
  'constraint shift_0_0_i[0]=0;',
   ...
  'constraint shift_0_0_i[3]=0;'])
property description
get_bit_based_vectorized_python_code(params, convert_output_to_bytes)
get_byte_based_vectorized_python_code(params)
get_graph_representation()
get_word_based_c_code(verbosity, word_size, wordstring_variables)
get_word_operation_sign(sign, solution)
property id
property input_bit_positions
property input_bit_size
is_forbidden(forbidden_types, forbidden_descriptions)
is_id_equal_to(component_id)
is_power_of_2_word_based(dto)
milp_bitwise_deterministic_truncated_xor_differential_constraints(model)

Returns a list of variables and a list of constrains modeling a component of type Shift.

EXAMPLE:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: cipher = TeaBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=2)
sage: from claasp.cipher_modules.models.milp.milp_models.milp_bitwise_deterministic_truncated_xor_differential_model import MilpBitwiseDeterministicTruncatedXorDifferentialModel
sage: milp = MilpBitwiseDeterministicTruncatedXorDifferentialModel(cipher)
sage: milp.init_model_in_sage_milp_class()
sage: shift_component = cipher.get_component_from_id("shift_0_0")
sage: variables, constraints = shift_component.milp_bitwise_deterministic_truncated_xor_differential_constraints(milp)
sage: variables
[('x_class[plaintext_8]', x_0),
('x_class[plaintext_9]', x_1),
...
('x_class[shift_0_0_6]', x_14),
('x_class[shift_0_0_7]', x_15)]
sage: constraints
[x_8 == x_4,
x_9 == x_5,
x_10 == x_6,
x_11 == x_7,
x_12 == 0,
x_13 == 0,
x_14 == 0,
x_15 == 0]
milp_constraints(model)

Return a list of variables and a list of constrains modeling a component of type SHIFT for MILP CIPHER model.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: from claasp.cipher_modules.models.milp.milp_model import MilpModel
sage: tea = TeaBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=2)
sage: milp = MilpModel(tea)
sage: milp.init_model_in_sage_milp_class()
sage: shift_component = tea.get_component_from_id("shift_0_0")
sage: variables, constraints = shift_component.milp_constraints(milp)
sage: variables
[('x[plaintext_8]', x_0),
('x[plaintext_9]', x_1),
...
('x[shift_0_0_6]', x_14),
('x[shift_0_0_7]', x_15)]
sage: constraints
[x_8 == x_4,
x_9 == x_5,
x_10 == x_6,
x_11 == x_7,
x_12 == 0,
x_13 == 0,
x_14 == 0,
x_15 == 0]
milp_wordwise_deterministic_truncated_xor_differential_constraints(model)

Returns a list of variables and a list of constrains modeling a component of type Shift.

EXAMPLE:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: cipher = AESBlockCipher(number_of_rounds=3)
sage: from claasp.cipher_modules.models.milp.milp_models.milp_wordwise_deterministic_truncated_xor_differential_model import MilpWordwiseDeterministicTruncatedXorDifferentialModel
sage: milp = MilpWordwiseDeterministicTruncatedXorDifferentialModel(cipher)
sage: milp.init_model_in_sage_milp_class()
sage: from claasp.components.shift_component import SHIFT
sage: shift_component = SHIFT(0, 18, ['sbox_0_2', 'sbox_0_6', 'sbox_0_10', 'sbox_0_14'], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], 32, -8)
sage: variables, constraints = shift_component.milp_wordwise_deterministic_truncated_xor_differential_constraints(milp)
sage: variables
[('x_class[sbox_0_2_word_0_class]', x_0),
 ('x_class[sbox_0_6_word_0_class]', x_1),
 ...
 ('x[shift_0_18_30]', x_70),
 ('x[shift_0_18_31]', x_71)]
sage: constraints
[x_4 == x_1,
 x_5 == x_2,
 ...
 x_70 == 0,
 x_71 == 0]
milp_xor_differential_propagation_constraints(model)
milp_xor_linear_mask_propagation_constraints(model)

Return a list of variables and a list of constraints for SHIFT component for MILP xor linear.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: from claasp.cipher_modules.models.milp.milp_model import MilpModel
sage: tea = TeaBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=2)
sage: milp = MilpModel(tea)
sage: milp.init_model_in_sage_milp_class()
sage: shift_component = tea.get_component_from_id("shift_0_0")
sage: variables, constraints = shift_component.milp_xor_linear_mask_propagation_constraints(milp)
sage: variables
[('x[shift_0_0_0_i]', x_0),
('x[shift_0_0_1_i]', x_1),
...
('x[shift_0_0_6_o]', x_14),
('x[shift_0_0_7_o]', x_15)]
sage: constraints
[x_0 == 0,
x_1 == 0,
x_2 == 0,
x_3 == 0,
x_8 == x_4,
x_9 == x_5,
x_10 == x_6,
x_11 == x_7]
minizinc_constraints(model)

Return variables and constraints for the component SHIFT for MINIZINC CIPHER model.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: from claasp.cipher_modules.models.minizinc.minizinc_model import MinizincModel
sage: tea = TeaBlockCipher(number_of_rounds=32)
sage: minizinc = MinizincModel(tea)
sage: shift_component = tea.get_component_from_id("shift_0_0")
sage: _, shift_mzn_constraints = shift_component.minizinc_constraints(minizinc)
sage: shift_mzn_constraints[0]
'constraint LSHIFT(array1d(0..32-1, [shift_0_0_x0,shift_0_0_x1,shift_0_0_x2,shift_0_0_x3,shift_0_0_x4,shift_0_0_x5,shift_0_0_x6,shift_0_0_x7,shift_0_0_x8,shift_0_0_x9,shift_0_0_x10,shift_0_0_x11,shift_0_0_x12,shift_0_0_x13,shift_0_0_x14,shift_0_0_x15,shift_0_0_x16,shift_0_0_x17,shift_0_0_x18,shift_0_0_x19,shift_0_0_x20,shift_0_0_x21,shift_0_0_x22,shift_0_0_x23,shift_0_0_x24,shift_0_0_x25,shift_0_0_x26,shift_0_0_x27,shift_0_0_x28,shift_0_0_x29,shift_0_0_x30,shift_0_0_x31]), 4)=array1d(0..32-1, [shift_0_0_y0,shift_0_0_y1,shift_0_0_y2,shift_0_0_y3,shift_0_0_y4,shift_0_0_y5,shift_0_0_y6,shift_0_0_y7,shift_0_0_y8,shift_0_0_y9,shift_0_0_y10,shift_0_0_y11,shift_0_0_y12,shift_0_0_y13,shift_0_0_y14,shift_0_0_y15,shift_0_0_y16,shift_0_0_y17,shift_0_0_y18,shift_0_0_y19,shift_0_0_y20,shift_0_0_y21,shift_0_0_y22,shift_0_0_y23,shift_0_0_y24,shift_0_0_y25,shift_0_0_y26,shift_0_0_y27,shift_0_0_y28,shift_0_0_y29,shift_0_0_y30,shift_0_0_y31]);\n'
minizinc_deterministic_truncated_xor_differential_trail_constraints(model)
minizinc_xor_differential_propagation_constraints(model)
property output_bit_size
output_size_for_concatenate(available_word_sizes, fixed, word_size)
print()
print_as_python_dictionary()
print_values(code)
print_word_values(code)
sat_bitwise_deterministic_truncated_xor_differential_constraints()

Return a list of variables and a list of clauses for SHIFT in SAT DETERMINISTIC TRUNCATED XOR DIFFERENTIAL model.

See also

SAT standard of Cipher for the format.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.sat_bitwise_deterministic_truncated_xor_differential_constraints()
(['shift_0_0_0_0',
  'shift_0_0_1_0',
  'shift_0_0_2_0',
  ...
  '-shift_0_0_30_1',
  '-shift_0_0_31_0',
  '-shift_0_0_31_1'])
sat_constraints()

Return a list of variables and a list of clauses for SHIFT in SAT CIPHER model.

See also

SAT standard of Cipher for the format.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.sat_constraints()
(['shift_0_0_0',
  'shift_0_0_1',
  'shift_0_0_2',
  ...
  '-shift_0_0_29',
  '-shift_0_0_30',
  '-shift_0_0_31'])
sat_xor_differential_propagation_constraints(model=None)
sat_xor_linear_mask_propagation_constraints(model=None)

Return a list of variables and a list of clauses for SHIFT in SAT XOR LINEAR model.

See also

SAT standard of Cipher for the format.

INPUT:

  • modelmodel object (default: None); a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.sat_xor_linear_mask_propagation_constraints()
(['shift_0_0_0_i',
  'shift_0_0_1_i',
  'shift_0_0_2_i',
  ...
  'shift_0_0_30_i -shift_0_0_26_o',
  'shift_0_0_27_o -shift_0_0_31_i',
  'shift_0_0_31_i -shift_0_0_27_o'])
select_bits(code)
select_words(code, word_size, input=True)
set_description(description)
set_id(id_string)
set_input_bit_positions(bit_positions)
smt_constraints()

Return a variable list and SMT-LIB list asserts representing for SMT CIPHER model.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.smt_constraints()
(['shift_0_0_0',
  'shift_0_0_1',
  ...
  'shift_0_0_30',
  'shift_0_0_31'],
 ['(assert (= shift_0_0_0 plaintext_36))',
  '(assert (= shift_0_0_1 plaintext_37))',
  ...
  '(assert (= shift_0_0_27 plaintext_63))',
  '(assert (not shift_0_0_28))',
  '(assert (not shift_0_0_29))',
  '(assert (not shift_0_0_30))',
  '(assert (not shift_0_0_31))'])
smt_xor_differential_propagation_constraints(model=None)
smt_xor_linear_mask_propagation_constraints(model=None)

Return a variable list and SMT-LIB list asserts for SHIFT in SMT XOR LINEAR model.

INPUT:

  • modelmodel object (default: None); a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.tea_block_cipher import TeaBlockCipher
sage: tea = TeaBlockCipher(number_of_rounds=3)
sage: shift_component = tea.component_from(0, 0)
sage: shift_component.smt_xor_linear_mask_propagation_constraints()
(['shift_0_0_0_i',
  'shift_0_0_1_i',
  ...
  'shift_0_0_30_o',
  'shift_0_0_31_o'],
 ['(assert (not shift_0_0_0_i))',
  '(assert (not shift_0_0_1_i))',
  ...
  '(assert (= shift_0_0_26_o shift_0_0_30_i))',
  '(assert (= shift_0_0_27_o shift_0_0_31_i))'])
property suffixes
property type