Avalanche tests

class AvalancheTests(cipher)

Bases: object

avalanche_probability_vectors(nb_samples)

Return the avalanche probability vectors of each input bit difference for each round.

The inputs considered are plaintext, key, etc.

The i-th component of the vector is the probability that i-th bit of the output flips due to the input bit difference.

Note

apvs[“key”][“round_output”][i][j] The vector returned corresponds to the probablity of flipping of each output bits after j+1 rounds when the difference is injected in position i in the key.

INPUT:

  • nb_samplesinteger; used to compute the estimated probability of flipping

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher as speck
sage: speck = speck(block_bit_size=16, key_bit_size=32, number_of_rounds=5)
sage: from claasp.cipher_modules.avalanche_tests import AvalancheTests
sage: test = AvalancheTests(speck)
sage: apvs = test.avalanche_probability_vectors(100)
sage: apvs["plaintext"]["round_output"][0][3] # random
avalanche_tests(number_of_samples=5, avalanche_dependence_uniform_bias=0.05, avalanche_dependence_criterion_threshold=0, avalanche_dependence_uniform_criterion_threshold=0, avalanche_weight_criterion_threshold=0.01, avalanche_entropy_criterion_threshold=0.01, run_avalanche_dependence=True, run_avalanche_dependence_uniform=True, run_avalanche_weight=True, run_avalanche_entropy=True)

Return a python dictionary that contains the dictionaries corresponding to each criterion and their analysis.

INPUT:

  • number_of_samplesinteger (default: 5); used to compute the estimated probability of flipping

  • avalanche_dependence_uniform_biasfloat (default: 0.05); define the range where the probability of flipping should be

  • avalanche_dependence_criterion_thresholdfloat (default: 0); It is a bias. The criterion is satisfied for a given input bit difference if for all output bits of the round under analysis, the corresponding avalanche dependence criterion d is such that block_bit_size - bias <= d <= block_bit_size + bias

  • avalanche_dependence_uniform_criterion_thresholdfloat (default: 0); It is a bias. The criterion is satisfied for a given input bit difference if for all output bits of the round under analysis, the corresponding avalanche dependence uniform criterion d is such that block_bit_size - bias <= d <= block_bit_size + bias

  • avalanche_weight_criterion_thresholdfloat (default: 0.01); It is a bias. The criterion is satisfied for a given input bit difference if for all output bits of the round under analysis, the corresponding avalanche weight criterion is such that block_bit_size/2 - bias <= d <= block_bit_size/2 + bias

  • avalanche_entropy_criterion_thresholdfloat (default: 0.01); It is a bias. The criterion is satisfied for a given input bit difference if for all output bits of the round under analysis, the corresponding avalanche entropy criterion d is such that block_bit_size - bias <= d <= block_bit_size + bias

  • run_avalanche_dependenceboolean (default: True); if True, add the avalanche dependence results to the output dictionary

  • run_avalanche_dependence_uniformboolean (default: True); if True, add the avalanche dependence uniform results to the output dictionary

  • run_avalanche_weightboolean (default: True); if True, add the avalanche weight results to the output dictionary

  • run_avalanche_entropyboolean (default: True); if True, add the avalanche entropy results to the output dictionary

Note

d[“test_results”][“plaintext”][“round_output”][“avalanche_entropy”][i][“vectors”][j] The vector returned by this command correspond to the avalanche entropy after j+1 rounds, when an input difference has been injected in position i in the plaintext.

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=5)
sage: from claasp.cipher_modules.avalanche_tests import AvalancheTests
sage: test = AvalancheTests(speck)
sage: d = test.avalanche_tests(number_of_samples=100)
sage: d["test_results"]["key"]["round_output"]["avalanche_dependence_vectors"][0]["vectors"][1] # random
compute_criterion_from_avalanche_probability_vectors(all_avalanche_probability_vectors, avalanche_dependence_uniform_bias)

Return a python dictionary that contains the dictionaries corresponding to each criterion.

ALGORITHM:

The avalanche dependence is the number of output bit that flip with respect to an input bit difference, for a given round. If the worst avalanche dependence for a certain round is close to the output bit size with respect to a certain threshold, we say that the cipher satisfies the avalanche dependence criterion for this round.

The avalanche dependence uniform is the number of output bit that flip with a probability \in \left[\frac{1}{2} - \text{bias}; \frac{1}{2} + \text{bias}\right], with respect to an input bit difference, for a given round. If the worst avalanche dependence uniform for a certain round is close to the output bit size with respect to a certain threshold, we say that the cipher satisfies the avalanche dependence uniform criterion for this round.

The avalanche weight is the expected Hamming weight of the output difference with respect to an input bit difference, for a given round. If the avalanche weights of all the input bit differences for a certain round is close to half of the output bit size with respect to a certain threshold, we say that the cipher satisfies the avalanche criterion for this round.

The avalanche entropy is defined as uncertainty about whether output bits flip with respect to an input bit difference, for a given round. If the strict avalanche entropy of all the input bit differences for a certain round is close to the output bit size with respect to a certain threshold, we say that the cipher satisfies the strict avalanche criterion for this round.

Note

d[“key”][“round_output”][position][index_occurrence][“avalanche_dependence”] = vector of round_output size with input diff injected in key

INPUT:

  • all_apvsdictionary; all avalanche probability vectors returned by avalanche_probability_vectors()

  • avalanche_dependence_uniform_biasfloat; define the range where the probability of flipping should be

See also

avalanche_probability_vectors() for the returning vectors.

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: speck = SpeckBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=5)
sage: from claasp.cipher_modules.avalanche_tests import AvalancheTests
sage: test = AvalancheTests(speck)
sage: apvs = test.avalanche_probability_vectors(100)
sage: d = test.compute_criterion_from_avalanche_probability_vectors(apvs, 0.2) # random
generate_3D_plot(number_of_samples=100, criterion='avalanche_weight_vectors')

Return an object that can be plot to visualize the results of the avalanche properties in a 3D graph.

EXAMPLES:

sage: from claasp.ciphers.block_ciphers.speck_block_cipher import SpeckBlockCipher
sage: cipher = SpeckBlockCipher(block_bit_size=16, key_bit_size=32, number_of_rounds=5)
sage: from claasp.cipher_modules.avalanche_tests import AvalancheTests
sage: plot = AvalancheTests(cipher).generate_3D_plot(number_of_samples=100)
graph can be plot with the build-in method plot.show()
sage: type(plot)
<class 'module'>

sage: from claasp.ciphers.permutations.chacha_permutation import ChachaPermutation
sage: cipher = ChachaPermutation(number_of_rounds=5)
sage: from claasp.cipher_modules.avalanche_tests import AvalancheTests
sage: plot = AvalancheTests(cipher).generate_3D_plot(number_of_samples=100)
graph can be plot with the build-in method plot.show()
sage: type(plot)
<class 'module'>