Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remove cipher from report class #195

Merged
merged 29 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d0d5707
FIX:reworked test outputs to include cipher object. changed str repre…
MFormenti Mar 12, 2024
c07db7f
removed cipher from report class creator
MFormenti Mar 12, 2024
fcfbdff
removed cipher from report class creator
MFormenti Mar 12, 2024
2d77047
refactored pytests
MFormenti Mar 12, 2024
755b4bd
refactored pytests
MFormenti Mar 12, 2024
83c02c2
refactored pytests
MFormenti Mar 12, 2024
c5f6d48
refactored pytests
MFormenti Mar 13, 2024
81dbe7b
updated benchmark tests
MFormenti Mar 13, 2024
d372d64
updated benchmark tests
MFormenti Mar 13, 2024
d4e8736
updated benchmark tests
MFormenti Mar 13, 2024
fb081ae
updated pytests
MFormenti Mar 13, 2024
fa184c7
updated pytests
MFormenti Mar 13, 2024
b078dd8
updated pytests
MFormenti Mar 13, 2024
67d6ecc
updated dieharder tests
MFormenti Mar 13, 2024
24efff3
updated statistical tests
MFormenti Mar 14, 2024
c41ec9a
fixed code duplication
MFormenti Mar 14, 2024
8e5a50a
fixed code duplication
MFormenti Mar 14, 2024
282689a
fixed code duplication
MFormenti Mar 14, 2024
d85c57e
fixed code duplication
MFormenti Mar 14, 2024
f491351
fixed code duplication
MFormenti Mar 14, 2024
b8ce88a
Merge branch 'develop' into fix/remove-cipher-from-report-class
MFormenti Mar 15, 2024
3d952ca
fixed algebraic tests
MFormenti Mar 15, 2024
9073d41
fixed report pytests
MFormenti Mar 15, 2024
f125ff5
fixed pytests and statistical tests graphs
MFormenti Mar 15, 2024
2b58f29
Merge branch 'develop' into fix/remove-cipher-from-report-class
MFormenti Mar 15, 2024
b39944e
fixed pytests
MFormenti Mar 15, 2024
477354e
fixed pytests
MFormenti Mar 15, 2024
2116ff0
Merge remote-tracking branch 'origin/fix/remove-cipher-from-report-cl…
MFormenti Mar 15, 2024
633a257
fixed pytests
MFormenti Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions claasp/cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@


class Cipher:


def __init__(self, family_name, cipher_type, cipher_inputs,
cipher_inputs_bit_size, cipher_output_bit_size,
cipher_reference_code=None):
Expand Down Expand Up @@ -146,6 +148,8 @@ def __init__(self, family_name, cipher_type, cipher_inputs,
self._id = self.make_cipher_id()
self._file_name = self.make_file_name()

def __repr__(self):
return self.id
def _are_there_not_forbidden_components(self, forbidden_types, forbidden_descriptions):
return self._rounds.are_there_not_forbidden_components(forbidden_types, forbidden_descriptions)

Expand Down
2 changes: 1 addition & 1 deletion claasp/cipher_modules/algebraic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def algebraic_tests(self, timeout_in_seconds=60):
tests_up_to_round.append(result)

input_parameters = {
"cipher.id": self._cipher.id,
"cipher": self._cipher,
"timeout_in_seconds": timeout_in_seconds,
"test_name": "algebraic_tests"
}
Expand Down
1 change: 1 addition & 0 deletions claasp/cipher_modules/avalanche_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def avalanche_tests(self, number_of_samples=5, avalanche_dependence_uniform_bias
avalanche_dependence_uniform_bias)
intermediate_output_names = self._add_intermediate_output_components_id_to_dictionary(self._cipher.get_all_components())
diffusion_tests = {"input_parameters": {
"cipher": self._cipher,
"test_name": "avalanche_tests",
"number_of_samples": number_of_samples,
"avalanche_dependence_uniform_bias": avalanche_dependence_uniform_bias,
Expand Down
3 changes: 2 additions & 1 deletion claasp/cipher_modules/component_analysis_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def component_analysis_tests(self):

output_dictionary = {
'input_parameters': {
'test_name': 'component_analysis'
'test_name': 'component_analysis',
'cipher': self._cipher
},
'test_results': components_analysis
}
Expand Down
1 change: 1 addition & 0 deletions claasp/cipher_modules/continuous_diffusion_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ def continuous_diffusion_tests(self,
"""
continuous_diffusion_tests = {"input_parameters": {
'test_name': 'continuous_diffusion_tests',
'cipher': self.cipher,
'continuous_avalanche_factor_number_of_samples': continuous_avalanche_factor_number_of_samples,
'threshold_for_avalanche_factor': threshold_for_avalanche_factor,
'continuous_neutral_measure_beta_number_of_samples': continuous_neutral_measure_beta_number_of_samples,
Expand Down
4 changes: 2 additions & 2 deletions claasp/cipher_modules/models/cp/cp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def add_solutions_from_components_values(self, components_values, memory, model_
solver_name, solver_output, total_weight):
for i in range(len(total_weight)):
solution = convert_solver_solution_to_dictionary(
self.cipher_id,
self._cipher,
model_type,
solver_name,
solve_time,
Expand Down Expand Up @@ -463,7 +463,7 @@ def solve(self, model_type, solver_name=None, num_of_processors=1, timelimit=600
solver_output = solver_process.stdout.splitlines()
solve_time, memory, components_values, total_weight = self._parse_solver_output(solver_output)
if components_values == {}:
solution = convert_solver_solution_to_dictionary(self.cipher_id, model_type, solver_name,
solution = convert_solver_solution_to_dictionary(self._cipher, model_type, solver_name,
solve_time, memory,
components_values, total_weight)
if 'UNSATISFIABLE' in solver_output[0]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ def find_lowest_weight_xor_differential_trail(self, fixed_values=[], solver_name
solution = self.solve('xor_differential_one_solution', solver_name)
solution['building_time_seconds'] = build_time
solution['test_name'] = "find_lowest_weight_xor_differential_trail"

return solution

def find_one_xor_differential_trail(self, fixed_values=[], solver_name='Chuffed'):
Expand Down
2 changes: 1 addition & 1 deletion claasp/cipher_modules/models/milp/milp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def solve(self, model_type, solver_name=SOLVER_DEFAULT, external_solver_name=Non
status, milp_time, milp_memory = self._solve_with_internal_solver()
objective_value, components_values = self._parse_solver_output()

solution = convert_solver_solution_to_dictionary(self.cipher_id, model_type, solver_name_in_solution, milp_time,
solution = convert_solver_solution_to_dictionary(self._cipher, model_type, solver_name_in_solution, milp_time,
milp_memory, components_values, objective_value)
solution['status'] = status
return solution
Expand Down
4 changes: 2 additions & 2 deletions claasp/cipher_modules/models/sat/sat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _solve_with_external_sat_solver(self, model_type, solver_name, options, host
component2fields, total_weight = {}, None
if total_weight is not None:
total_weight = float(total_weight)
solution = convert_solver_solution_to_dictionary(self.cipher_id, model_type, solver_name, sat_time,
solution = convert_solver_solution_to_dictionary(self._cipher, model_type, solver_name, sat_time,
sat_memory, component2fields, total_weight)
solution['status'] = status

Expand All @@ -361,7 +361,7 @@ def _solve_with_sage_sat_solver(self, model_type, solver_name):
status = 'UNSATISFIABLE'
if total_weight is not None:
total_weight = float(total_weight)
solution = convert_solver_solution_to_dictionary(self.cipher_id, model_type, solver_name, sat_time,
solution = convert_solver_solution_to_dictionary(self._cipher, model_type, solver_name, sat_time,
sat_memory, component2fields, total_weight)
solution['status'] = status

Expand Down
2 changes: 1 addition & 1 deletion claasp/cipher_modules/models/smt/smt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _get_data(data_string, lines):
if total_weight is not None:
total_weight = float(total_weight)

solution = convert_solver_solution_to_dictionary(self.cipher_id, model_type, solver_name, solve_time,
solution = convert_solver_solution_to_dictionary(self._cipher, model_type, solver_name, solve_time,
memory, component2attributes, total_weight)
solution['status'] = status

Expand Down
4 changes: 2 additions & 2 deletions claasp/cipher_modules/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def add_arcs(arcs, component, curr_input_bit_ids, input_bit_size, intermediate_o
arcs[previous_output_bit_ids[i]].append(curr_input_bit_ids[i])


def convert_solver_solution_to_dictionary(cipher_id, model_type, solver_name, solve_time, memory,
def convert_solver_solution_to_dictionary(cipher, model_type, solver_name, solve_time, memory,
components_values, total_weight):
"""
Return a dictionary that represents the solution obtained from the solver.
Expand Down Expand Up @@ -72,7 +72,7 @@ def convert_solver_solution_to_dictionary(cipher_id, model_type, solver_name, so
'total_weight': 0}
"""
return {
'cipher_id': cipher_id,
'cipher': cipher,
'model_type': model_type,
'solver_name': solver_name,
'solving_time_seconds': solve_time,
Expand Down
6 changes: 6 additions & 0 deletions claasp/cipher_modules/neural_network_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def neural_network_blackbox_distinguisher_tests(self, nb_samples=10000,
"""
results = {"input_parameters": {
"test_name": "neural_network_blackbox_distinguisher_tests",
"cipher": self.cipher,
"number_of_samples": nb_samples,
"hidden_layers": hidden_layers,
"number_of_epochs": number_of_epochs}, "test_results": {}}
Expand Down Expand Up @@ -255,6 +256,7 @@ def neural_network_differential_distinguisher_tests(self, nb_samples=10000, hidd
"""
results = {"input_parameters": {
"test_name": "neural_network_differential_distinguisher_tests",
"cipher":self.cipher,
"number_of_samples": nb_samples,
"input_differences": diff,
"hidden_layers": hidden_layers,
Expand Down Expand Up @@ -598,6 +600,7 @@ def run_autond_pipeline(self, difference_positions=None, optimizer_samples=10 **
neural_distinguisher_test_results = {
'input_parameters': {
'test_name': 'neural_distinguisher_test',
'cipher': self.cipher,
'optimizer_samples': optimizer_samples,
'optimizer_generations': optimizer_generations,
'training_samples': training_samples,
Expand Down Expand Up @@ -636,6 +639,9 @@ def data_generator(nr, samples):
input_size = self.cipher.output_bit_size * 2
neural_network = self.get_neural_network(neural_net, input_size = input_size)
nr = max(1, highest_round-3)

neural_distinguisher_test_results['test_results']['round_start']=nr

print(f'Training {neural_net} on input difference {[hex(x) for x in input_difference]} ({self.cipher.inputs}), from round {nr}...')
neural_results = self.train_neural_distinguisher(data_generator, nr, neural_network, training_samples,
testing_samples, number_of_epochs)
Expand Down
Loading
Loading