From 66ff48799a0ad1f8aea90f3c36c9a27220eb0ca9 Mon Sep 17 00:00:00 2001 From: cs Date: Tue, 19 Nov 2024 16:20:40 +0400 Subject: [PATCH] Adding missing parameters --- .../sat_models/sat_xor_differential_model.py | 70 +------------------ .../sat/sat_models/sat_xor_linear_model.py | 7 +- 2 files changed, 6 insertions(+), 71 deletions(-) diff --git a/claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py b/claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py index 1095517d..ca371158 100644 --- a/claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py +++ b/claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py @@ -289,75 +289,9 @@ def find_all_xor_differential_trails_with_weight_at_most(self, min_weight, max_w return solutions_list - def find_lowest_weight_xor_differential_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT): - """ - Return the solution representing a trail with the lowest weight. - By default, the search is set in the single-key setting. - - .. NOTE:: - - There could be more than one trail with the lowest weight. In order to find all the lowest weight trail, - run :py:meth:`~SatXorDifferentialModel.find_all_xor_differential_trails_with_fixed_weight`. - - INPUT: - - - ``fixed_values`` -- **list** (default: `[]`); can be created using ``set_fixed_variables`` method - - ``solver_name`` -- **string** (default: `CRYPTOMINISAT_EXT`); the name of the solver - - .. SEEALSO:: - - :ref:`sat-solvers` - - EXAMPLES:: - - # single-key setting - sage: from claasp.cipher_modules.models.sat.sat_models.sat_xor_differential_model import SatXorDifferentialModel - sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher - sage: speck = SpeckBlockCipher(number_of_rounds=5) - sage: sat = SatXorDifferentialModel(speck) - sage: trail = sat.find_lowest_weight_xor_differential_trail() - sage: trail['total_weight'] - 9.0 - - # related-key setting - sage: from claasp.cipher_modules.models.sat.sat_models.sat_xor_differential_model import SatXorDifferentialModel - sage: from claasp.cipher_modules.models.utils import set_fixed_variables - sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher - sage: speck = SpeckBlockCipher(number_of_rounds=5) - sage: sat = SatXorDifferentialModel(speck) - sage: key = set_fixed_variables( - ....: component_id='key', - ....: constraint_type='not_equal', - ....: bit_positions=range(64), - ....: bit_values=(0,)*64) - sage: trail = sat.find_lowest_weight_xor_differential_trail(fixed_values=[key]) - sage: trail['total_weight'] - 1.0 - """ - current_weight = 0 - start_building_time = time.time() - self.build_xor_differential_trail_model(weight=current_weight, fixed_variables=fixed_values) - end_building_time = time.time() - solution = self.solve(XOR_DIFFERENTIAL, solver_name=solver_name) - solution['building_time_seconds'] = end_building_time - start_building_time - total_time = solution['solving_time_seconds'] - max_memory = solution['memory_megabytes'] - while solution['total_weight'] is None: - current_weight += 1 - start_building_time = time.time() - self.build_xor_differential_trail_model(weight=current_weight, fixed_variables=fixed_values) - end_building_time = time.time() - solution = self.solve(XOR_DIFFERENTIAL, solver_name=solver_name) - solution['building_time_seconds'] = end_building_time - start_building_time - total_time += solution['solving_time_seconds'] - max_memory = max((max_memory, solution['memory_megabytes'])) - solution['solving_time_seconds'] = total_time - solution['memory_megabytes'] = max_memory - solution['test_name'] = "find_lowest_weight_xor_differential_trail" - - return solution - def find_lowest_weight_xor_differential_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT, start_weight=0, options=None): + def find_lowest_weight_xor_differential_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT, + options=None, start_weight=0, ): """ Return the solution representing a trail with the lowest weight. By default, the search is set in the single-key setting. diff --git a/claasp/cipher_modules/models/sat/sat_models/sat_xor_linear_model.py b/claasp/cipher_modules/models/sat/sat_models/sat_xor_linear_model.py index e19b75a4..4a7425e6 100644 --- a/claasp/cipher_modules/models/sat/sat_models/sat_xor_linear_model.py +++ b/claasp/cipher_modules/models/sat/sat_models/sat_xor_linear_model.py @@ -236,7 +236,8 @@ def find_all_xor_linear_trails_with_weight_at_most(self, min_weight, max_weight, return solutions_list - def find_lowest_weight_xor_linear_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT, options=None, start_weight=0): + def find_lowest_weight_xor_linear_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT, options=None, + start_weight=0): """ Return the solution representing a XOR LINEAR trail with the lowest possible weight. By default, the search removes the key schedule, if any. @@ -300,7 +301,7 @@ def find_lowest_weight_xor_linear_trail(self, fixed_values=[], solver_name=solve return solution - def find_one_xor_linear_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT): + def find_one_xor_linear_trail(self, fixed_values=[], solver_name=solvers.SOLVER_DEFAULT, options=None): """ Return the solution representing a XOR linear trail. By default, the search removes the key schedule, if any. @@ -345,7 +346,7 @@ def find_one_xor_linear_trail(self, fixed_values=[], solver_name=solvers.SOLVER_ start_building_time = time.time() self.build_xor_linear_trail_model(fixed_variables=fixed_values) end_building_time = time.time() - solution = self.solve(XOR_LINEAR, solver_name=solver_name) + solution = self.solve(XOR_LINEAR, solver_name=solver_name, options=options) solution['building_time_seconds'] = end_building_time - start_building_time solution['test_name'] = "find_one_xor_linear_trail"