Skip to content

Commit

Permalink
Adding missing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cs authored and cs committed Nov 19, 2024
1 parent 8abf78e commit 66ff487
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 66ff487

Please sign in to comment.