Skip to content

Commit

Permalink
Adding test for distinguisher checkers
Browse files Browse the repository at this point in the history
- Adding test for differential_truncated_checker_permutation
- Adding test for differential_checker_permutation
  • Loading branch information
juaninf committed Dec 28, 2024
1 parent 1f64db0 commit 0f004e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion claasp/cipher_modules/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def differential_linear_checker_for_block_cipher_single_key(
return corr


def differential_checker_for_permutation(
def differential_checker_permutation(
cipher, input_difference, output_difference, number_of_samples, state_size, seed=None
):
"""
Expand Down
27 changes: 26 additions & 1 deletion tests/unit/cipher_modules/models/models_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
find_sign_for_xor_linear_trails, print_components_values,
write_solution_to_file,
get_single_key_scenario_format_for_fixed_values,
get_related_key_scenario_format_for_fixed_values)
get_related_key_scenario_format_for_fixed_values,
differential_truncated_checker_permutation,
differential_checker_permutation)
from claasp.ciphers.permutations.chacha_permutation import ChachaPermutation

NOT_EQUAL = 'not equal'

Expand Down Expand Up @@ -108,3 +111,25 @@ def test_get_single_key_scenario_format_for_fixed_values():
fixed_values = get_single_key_scenario_format_for_fixed_values(speck)
assert fixed_values[0]["constraint_type"] == 'equal'
assert fixed_values[1]["constraint_type"] == 'not_equal'


def test_differential_checker_permutation():
cipher = ChachaPermutation(number_of_rounds=1)
input_difference = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000
output_difference = 0x00000000000000000000000000000000800000000000000000000000000000000008000000000000000000000000000000080000000000000000000000000000

probability_weight = differential_checker_permutation(
cipher, input_difference, output_difference, 1 << 12, 512, seed=42
)
assert abs(probability_weight) < 2


def test_differential_truncated_checker_permutation():
cipher = ChachaPermutation(number_of_rounds=3)
input_difference = 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000
output_difference = '100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000????????????????????????????????????????????????????????????????????1000000000000000????????????????????100000000000????????????????????????10000000????????????????????????????????????10000000????????????????????????????????????????????????1000000000000000????????????????????1000000000000000000010000000000010000000000000000000000000000000000000000000????????????????????????????????00000000000000001000000000000000'

probability_weight = differential_truncated_checker_permutation(
cipher, input_difference, output_difference, 1 << 12, 512, seed=42
)
assert abs(probability_weight) < 2

0 comments on commit 0f004e2

Please sign in to comment.