Constant component

class Constant(current_round_number, current_round_number_of_components, output_bit_size, value)

Bases: Component

algebraic_polynomials(model)

Return a list of polynomials for CONSTANT addition.

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=1)
sage: constant_component = fancy.get_component_from_id("constant_0_10")
sage: algebraic = AlgebraicModel(fancy)
sage: constant_component.algebraic_polynomials(algebraic)
[constant_0_10_y0,
 constant_0_10_y1 + 1,
 constant_0_10_y2,
 constant_0_10_y3 + 1,
 constant_0_10_y4 + 1,
 constant_0_10_y5 + 1,
 constant_0_10_y6,
 constant_0_10_y7 + 1,
 constant_0_10_y8,
 constant_0_10_y9,
 constant_0_10_y10 + 1,
 constant_0_10_y11 + 1,
 constant_0_10_y12 + 1,
 constant_0_10_y13,
 constant_0_10_y14 + 1,
 constant_0_10_y15 + 1,
 constant_0_10_y16,
 constant_0_10_y17 + 1,
 constant_0_10_y18 + 1,
 constant_0_10_y19 + 1,
 constant_0_10_y20 + 1,
 constant_0_10_y21 + 1,
 constant_0_10_y22 + 1,
 constant_0_10_y23 + 1]
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 a CONSTANT in CMS CIPHER model.

See also

SAT standard of Cipher for the format.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.cms_constraints()
(['constant_2_0_0',
  'constant_2_0_1',
  'constant_2_0_2',
  ...
  '-constant_2_0_13',
  '-constant_2_0_14',
  'constant_2_0_15'])
cms_xor_differential_propagation_constraints(model)
cms_xor_linear_mask_propagation_constraints(model=None)
cp_constraints()

Return lists of declarations and constraints for CONSTANT component for CP CIPHER model.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.cp_constraints()
(['array[0..15] of var 0..1: constant_2_0 = array1d(0..15, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]);'],
 [])
cp_deterministic_truncated_xor_differential_trail_constraints()
cp_wordwise_deterministic_truncated_xor_differential_constraints(model)

Return lists of declarations and constraints for CONSTANT component for CP wordwise deterministic truncated xor differential.

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.constant_component import Constant
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: cp = CpModel(aes)
sage: constant_component = Constant(0, 18, 16, 0xAB01)
sage: constant_component.cp_wordwise_deterministic_truncated_xor_differential_constraints(cp)
(['array[0..1] of var 0..1: constant_0_18_active = array1d(0..1, [0,0]);',
  'array[0..1] of var 0..1: constant_0_18_value = array1d(0..1, [0,0]);'],
 [])
cp_xor_differential_propagation_constraints(model=None)

Return lists of declarations and constraints for CONSTANT component for CP xor differential model.

INPUT:

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

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=22)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.cp_xor_differential_propagation_constraints()
(['array[0..15] of var 0..1: constant_2_0 = array1d(0..15, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);'],
 [])
cp_xor_differential_propagation_first_step_constraints(model)

Return lists of declarations and constraints for CONSTANT component for CP xor differential first step.

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: aes = AESBlockCipher(number_of_rounds=3)
sage: cp = CpModel(aes)
sage: constant_component = aes.component_from(0, 30)
sage: constant_component.cp_xor_differential_propagation_first_step_constraints(cp)
(['array[0..3] of var 0..1: constant_0_30 = array1d(0..3, [0,0,0,0]);'], [])
cp_xor_linear_mask_propagation_constraints(model=None)

Return lists of declarations and constraints for CONSTANT component for CP xor linear model.

INPUT:

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

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=22)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.cp_xor_linear_mask_propagation_constraints()
(['array[0..15] of var 0..1: constant_2_0_o;'],
 [])
property description
get_bit_based_c_code(verbosity)
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)
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 constraints modeling a component of type Constant.

EXAMPLE:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, 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(speck)
sage: milp.init_model_in_sage_milp_class()
sage: constant_component = speck.get_component_from_id("constant_1_0")
sage: variables, constraints = constant_component.milp_bitwise_deterministic_truncated_xor_differential_constraints(milp)
sage: variables
[('x_class[constant_1_0_0]', x_0),
('x_class[constant_1_0_1]', x_1),
...
('x_class[constant_1_0_14]', x_14),
('x_class[constant_1_0_15]', x_15)]
sage: constraints
[x_0 == 0,
x_1 == 0,
...
x_14 == 0,
x_15 == 0]
milp_wordwise_deterministic_truncated_xor_differential_constraints(model)

Returns a list of variables and a list of constraints modeling a component of type Constant for wordwise models.

EXAMPLE:

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.components.constant_component import Constant
sage: aes = 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(aes)
sage: milp.init_model_in_sage_milp_class()
sage: constant_component = aes.get_component_from_id("constant_0_30")
sage: variables, constraints = constant_component.milp_wordwise_deterministic_truncated_xor_differential_constraints(milp)
sage: variables
[('x_class[constant_0_30_word_0_class]', x_0),
 ('x_class[constant_0_30_word_1_class]', x_1),
 ('x_class[constant_0_30_word_2_class]', x_2),
 ('x_class[constant_0_30_word_3_class]', x_3)]
sage: constraints
[x_0 == 0, x_1 == 0, x_2 == 0, x_3 == 0]
milp_xor_differential_propagation_constraints(model)

Return lists of variables and constrains modeling a component of type CONSTANT for MILP xor differential.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.models.milp.milp_model import MilpModel
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=2)
sage: milp = MilpModel(speck)
sage: milp.init_model_in_sage_milp_class()
sage: constant_component = speck.get_component_from_id("constant_1_0")
sage: variables, constraints = constant_component.milp_xor_differential_propagation_constraints(milp)
sage: variables
[('x[constant_1_0_0]', x_0),
('x[constant_1_0_1]', x_1),
...
('x[constant_1_0_14]', x_14),
('x[constant_1_0_15]', x_15)]
sage: constraints
[x_0 == 0,
x_1 == 0,
...
x_14 == 0,
x_15 == 0]
milp_xor_linear_mask_propagation_constraints(model)

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

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: from claasp.cipher_modules.models.milp.milp_model import MilpModel
sage: speck = SpeckBlockCipher(block_bit_size=32, key_bit_size=64, number_of_rounds=3)
sage: milp = MilpModel(speck)
sage: milp.init_model_in_sage_milp_class()
sage: constant_component = speck.get_component_from_id("constant_2_0")
sage: variables, constraints = constant_component.milp_xor_linear_mask_propagation_constraints(milp)
sage: variables
[('x[constant_2_0_0_o]', x_0),
('x[constant_2_0_1_o]', x_1),
...
('x[constant_2_0_14_o]', x_14),
('x[constant_2_0_15_o]', x_15)]
sage: constraints
[]
minizinc_deterministic_truncated_xor_differential_trail_constraints(model)
minizinc_xor_differential_propagation_constraints(model)

Return variables and constraints for the CONSTANT component for MINIZINC xor differential.

INPUT:

  • modelmodel object; a model instance

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.fancy_block_cipher import FancyBlockCipher
sage: from claasp.cipher_modules.models.minizinc.minizinc_models.minizinc_xor_differential_model import MinizincXorDifferentialModel
sage: fancy = FancyBlockCipher(number_of_rounds=1)
sage: minizinc = MinizincXorDifferentialModel(fancy)
sage: constant_component = fancy.get_component_from_id("constant_0_10")
sage: _, constant_xor_differential_constraints = constant_component.minizinc_xor_differential_propagation_constraints(minizinc)
sage: constant_xor_differential_constraints[6]
'constraint constant_0_10_y6=0;'
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 CONSTANT 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.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.sat_bitwise_deterministic_truncated_xor_differential_constraints()
(['constant_2_0_0_0',
  'constant_2_0_1_0',
  'constant_2_0_2_0',
  ...
  '-constant_2_0_13_1',
  '-constant_2_0_14_1',
  '-constant_2_0_15_1'])
sat_constraints()

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

See also

SAT standard of Cipher for the format.

INPUT:

  • None

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.sat_constraints()
(['constant_2_0_0',
  'constant_2_0_1',
  'constant_2_0_2',
  ...
  '-constant_2_0_13',
  '-constant_2_0_14',
  'constant_2_0_15'])
sat_xor_differential_propagation_constraints(model=None)

Return lists of variables and strings representing clauses for CONSTANT for SAT xor differential.

INPUT:

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

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.sat_xor_differential_propagation_constraints()
(['constant_2_0_0',
  'constant_2_0_1',
  'constant_2_0_2',
  ...
  '-constant_2_0_13',
  '-constant_2_0_14',
  '-constant_2_0_15'])
sat_xor_linear_mask_propagation_constraints(model=None)

Return a list of variables and a list of clauses for a CONSTANT 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.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(number_of_rounds=3)
sage: constant_component = speck.component_from(2, 0)
sage: constant_component.sat_xor_linear_mask_propagation_constraints()
(['constant_2_0_0_o',
  'constant_2_0_1_o',
  'constant_2_0_2_o',
  ...
  'constant_2_0_14_o',
  'constant_2_0_15_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 a CONSTANT 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: constant_component = tea.component_from(0, 2)
sage: constant_component.smt_constraints()
(['constant_0_2_0',
  'constant_0_2_1',
  ...
  'constant_0_2_30',
  'constant_0_2_31'],
 ['(assert constant_0_2_0)',
  '(assert (not constant_0_2_1))',
  ...
  '(assert (not constant_0_2_30))',
  '(assert constant_0_2_31)'])
smt_xor_differential_propagation_constraints(model=None)

Return a variable list and SMT-LIB list asserts representing a CONSTANT for SMT xor differential.

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: constant_component = tea.component_from(0, 2)
sage: constant_component.smt_xor_differential_propagation_constraints()
(['constant_0_2_0',
  'constant_0_2_1',
  ...
  'constant_0_2_30',
  'constant_0_2_31'],
 ['(assert (not constant_0_2_0))',
  '(assert (not constant_0_2_1))',
  ...
  '(assert (not constant_0_2_30))',
  '(assert (not constant_0_2_31))'])
smt_xor_linear_mask_propagation_constraints(model=None)

Return a variable list and SMT-LIB list asserts for a CONSTANT 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: constant_component = tea.component_from(0, 2)
sage: constant_component.smt_xor_linear_mask_propagation_constraints()
(['constant_0_2_0_o',
  'constant_0_2_1_o',
  ...
  'constant_0_2_30_o',
  'constant_0_2_31_o'],
 [])
property suffixes
property type
constant_to_repr(val, output_size)