Skip to content

Commit

Permalink
Fix doctests for Linear_layer component in MILP and additional typos …
Browse files Browse the repository at this point in the history
…in documentation for various methods.

Inequalities for wordwise truncated XOR have been regenerated as well.
  • Loading branch information
p-huynh committed Jun 10, 2024
1 parent 47d6a17 commit 13e74a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ def get_valid_points_for_wordwise_xor(delta_in_1, zeta_in_1, delta_in_2, zeta_in
zeta_out = 0
if delta_in_1 + delta_in_2 > 2:
delta_out = 3
zeta_out = -2
elif delta_in_1 + delta_in_2 == 1:
delta_out = 1
zeta_out = zeta_in_1 + zeta_in_2
elif delta_in_1 == 0 and delta_in_2 == 0:
delta_out = 0
elif zeta_in_1 + zeta_in_2 < 0:
delta_out = 2
zeta_out = -1
elif zeta_in_1 == zeta_in_2:
delta_out = 0
else:
Expand Down Expand Up @@ -169,6 +171,7 @@ def generate_valid_points_for_xor_between_n_input_words(wordsize=4, number_of_wo
zeta[summand + 1])

delta_output, zeta_output = get_valid_points_for_wordwise_xor(tmp_delta[-1], tmp_zeta[-1], delta[-1], zeta[-1])
zeta_output = max(0, zeta_output)
if delta.count(3) == 0 and delta.count(2) == 1 and delta.count(1) > 1:
only_fixed_patterns = [i[1] for i in enumerate(zeta) if delta[i[0]] == 1]
if len(only_fixed_patterns) > 1:
Expand Down
7 changes: 4 additions & 3 deletions claasp/components/linear_layer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,11 @@ def milp_wordwise_deterministic_truncated_xor_differential_constraints(self, mod
('x[mix_column_0_21_14]', x_46),
('x[mix_column_0_21_15]', x_47)]
sage: constraints
[1 <= 1 + x_6 + x_8 + x_9 + x_10 + x_11 + x_13 + x_18 + x_19 - x_25,
1 <= 1 + x_6 + x_8 + x_9 + x_10 + x_11 + x_12 + x_13 + x_19 - x_25,
[1 <= 2 - x_6 - x_12 + x_25,
1 <= 3 - x_8 + x_9 + x_10 + x_11 - x_14 + x_15 + x_16 + x_17 + x_19 - x_25,
1 <= 3 + x_8 - x_9 + x_10 + x_11 + x_14 - x_15 + x_16 + x_17 + x_19 - x_25,
...
1 <= 2 - x_6 - x_8,
1 <= 1 + x_1 - x_2,
1 <= 1 + x_7 - x_8]
"""
Expand Down
21 changes: 12 additions & 9 deletions claasp/components/xor_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ def milp_wordwise_deterministic_truncated_xor_differential_constraints(self, mod
1 <= 2 - x_30 - x_39]
"""
if model.word_size == 8:
return self.milp_wordwise_deterministic_truncated_xor_differential_sequential_constraints(model)

x = model.binary_variable

num_of_inputs = int(self.description[1])
Expand Down Expand Up @@ -845,20 +848,20 @@ def milp_wordwise_deterministic_truncated_xor_differential_sequential_constraint
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: xor_component = cipher.get_component_from_id("xor_0_32")
sage: xor_component = cipher.get_component_from_id("xor_0_31")
sage: variables, constraints = xor_component.milp_wordwise_deterministic_truncated_xor_differential_sequential_constraints(milp)
sage: variables
[('x[xor_0_31_word_0_class_bit_0]', x_0),
('x[xor_0_31_word_0_class_bit_1]', x_1),
[('x[sbox_0_26_word_0_class_bit_0]', x_0),
('x[sbox_0_26_word_0_class_bit_1]', x_1),
...
('x[xor_0_32_30]', x_118),
('x[xor_0_32_31]', x_119)]
('x[xor_0_31_30]', x_158),
('x[xor_0_31_31]', x_159)]
sage: constraints
[1 <= 1 + x_0 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8 + x_9 + x_41 - x_81,
1 <= 1 + x_1 + x_40 + x_42 + x_43 + x_44 + x_45 + x_46 + x_47 + x_48 + x_49 - x_81,
[1 <= 1 + x_0 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8 + x_9 + x_41 - x_161,
1 <= 1 + x_1 + x_40 + x_42 + x_43 + x_44 + x_45 + x_46 + x_47 + x_48 + x_49 - x_161,
...
1 <= 1 + x_31 - x_39,
1 <= 2 - x_30 - x_39]
1 <= 1 + x_111 - x_119,
1 <= 2 - x_110 - x_119]
"""
Expand Down

0 comments on commit 13e74a9

Please sign in to comment.