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/cipher inversion for lblock #101

Closed
wants to merge 376 commits into from
Closed
Changes from 5 commits
Commits
Show all changes
376 commits
Select commit Hold shift + click to select a range
82bfd3d
Update run-benchmark-tests action.
mariags803 Jun 26, 2023
e5ed3c4
Update run-benchmark-tests action.
mariags803 Jun 26, 2023
0e885d6
Add benchmark test results
github-actions[bot] Jun 26, 2023
6715201
Add benchmark test results
github-actions[bot] Jun 26, 2023
0241c39
Add benchmark test results
github-actions[bot] Jun 26, 2023
069acaf
Add benchmark test results
github-actions[bot] Jun 26, 2023
47f0796
Update run-benchmark-tests action. Add .benchmarks folder in .gitignore.
mariags803 Jun 26, 2023
96c17e8
Update groups in run-benchmark-tests and run-pytest-and-sonarcloud-sc…
mariags803 Jun 26, 2023
5dccfd6
Change run-benchmark-tests to not save the results files in the repos…
mariags803 Jun 26, 2023
a4200ab
Update sitecustomize.py
yessica-rd Jun 26, 2023
b1fbc04
Uncomment tests in cipher_test.py
yessica-rd Jun 28, 2023
71f95d9
Add parameters to test_neural_network_blackbox_distinguisher_tests me…
yessica-rd Jun 28, 2023
d6291b3
Modify test_neural_network_blackbox_distinguisher_tests with speck an…
yessica-rd Jun 28, 2023
2bdd53e
Merge pull request #45 from Crypto-TII/performance-tests
peacker Jul 6, 2023
7a36b2e
Add parametrization to network blackbox distinguisher tests for speck…
AnaCaceres Jul 6, 2023
515d0c5
Modify workflow to run pytest on push to this branch.
AnaCaceres Jul 6, 2023
d4aa9d9
temporarily commited
Jul 6, 2023
b4bc512
Revert "Modify workflow to run pytest on push to this branch."
AnaCaceres Jul 7, 2023
ee02fb5
Run benchmark tests only in PR to main.
AnaCaceres Jul 7, 2023
d8c9145
Fix: MILP external file paths are now absolute
p-huynh Jul 10, 2023
c634e21
Fix: MILP external file paths are now absolute
p-huynh Jul 10, 2023
d3c6dd4
Fix: MILP external file paths are now absolute
p-huynh Jul 10, 2023
735c399
Fix: MILP external file paths are now absolute
p-huynh Jul 10, 2023
c8fcc4b
FIX/fix: fix the bug of the nist_statistical_tests_test.py when the e…
Jul 13, 2023
9e49a58
FIX/fix: fix the bug of the nist_statistical_tests_test.py when the e…
Jul 13, 2023
ee3f402
Update CONTRIBUTING.md.
AnaCaceres Jul 13, 2023
f1ebfc2
Refactor: window_size heuristic
juaninf Jul 19, 2023
08e42b1
Undo change signature of init method for SatCipherModel
juaninf Jul 19, 2023
681ad04
Removing window_size heuristic from where it is not necessary
juaninf Jul 19, 2023
d3feebd
Adding window_size heuristic by round to modular component
juaninf Jul 19, 2023
447c2af
Revise FSR with word size, debug, redefine the description: in progress
Jul 20, 2023
7b49f5f
Revise FSR with word size, debug, redefine the description: in progress
Jul 25, 2023
a6ccd27
.
Jul 31, 2023
df89ce9
Refactored + added dbitnet
Jul 31, 2023
e805b8c
Fix: compactification of cipher in SAT
ale-depi Jul 31, 2023
8f667ef
Merge branch develop
ale-depi Jul 31, 2023
a3e53b8
temporarily updated
Jul 31, 2023
d34d96d
Merge pull request #46 from Crypto-TII/performance-neural-network-tests
peacker Aug 1, 2023
bb09452
Merge pull request #47 from Crypto-TII/feat/change_milp_file_paths_to…
peacker Aug 1, 2023
9ab8392
Merge pull request #49 from Crypto-TII/fix/CLAASP-24-bug-files-create…
peacker Aug 1, 2023
7094d42
Merge pull request #50 from Crypto-TII/update-contributing-guide
peacker Aug 1, 2023
f5243a2
Merge pull request #54 from Crypto-TII/fix/sat-model-cipher-compactif…
peacker Aug 1, 2023
e4e1b4d
Feature: vectorized implementation of neural_network distinguishers a…
RisingZero Aug 1, 2023
b9a1928
.
Aug 1, 2023
073282b
Fix unit test
Aug 1, 2023
6fd5b4c
.
Aug 2, 2023
f44c441
temporarily updated for fsr_binary
Aug 2, 2023
29d9cf9
Merge pull request #55 from Crypto-TII/feat/nn-distinguisher-vectorized
peacker Aug 2, 2023
0a6bc35
Add dbitnet test
Aug 3, 2023
58db4c9
Feat: Adding max number of carries
juaninf Aug 3, 2023
bc63569
temporarily updated for fsr_word
Aug 4, 2023
c3fe0ef
temporarily updated for fsr_word
Aug 4, 2023
849886c
.
Aug 4, 2023
b795b4b
FEATURE/Add: create new BEA-1 cipher
RisingZero Aug 6, 2023
182121f
Change: update cipher documentation with BEA-1
RisingZero Aug 6, 2023
d987621
temporarily updated for a51
Aug 10, 2023
cdf8e8c
removed unused parameters
Aug 14, 2023
37030f4
Merge branch 'develop' of github.com:Crypto-TII/claasp into neural-di…
Aug 14, 2023
70cac36
.
Aug 14, 2023
2242d0c
a51
Aug 15, 2023
cdb984d
Merge pull request #51 from Crypto-TII/feat/update-sitecustomize-file
peacker Aug 16, 2023
679863e
Merge pull request #53 from Crypto-TII/feat/LIBCA-1219-allowing-windo…
peacker Aug 16, 2023
5004dd7
Merge pull request #56 from Crypto-TII/feat/LIBCA-1220-heuristic-tota…
peacker Aug 16, 2023
6e92068
Merge pull request #57 from Crypto-TII/feat/BEA1-cipher-implementation
peacker Aug 16, 2023
8d7c84a
Merge pull request #58 from Crypto-TII/neural-distinguishers-improvem…
peacker Aug 16, 2023
a7bda8a
Adding maximum number of non-linear portions constraint
juaninf Aug 26, 2023
6975961
Adding test for modadd heuristics
juaninf Aug 26, 2023
313e34d
Adding test for MiniZinc model of modadd
juaninf Aug 26, 2023
77471fd
- added MILP deterministic bitwise and wordwise models, with various …
p-huynh Aug 29, 2023
767c1bc
Merge branch 'develop' into feat/LIBCA-1106-XOR_deterministic_truncat…
p-huynh Aug 29, 2023
6d0e821
Fixing pytests
p-huynh Aug 29, 2023
9329ad0
Fixing pytests part 2
p-huynh Aug 29, 2023
f7a2a6a
Fixing pytests part 3
p-huynh Aug 29, 2023
0f75aa1
Fixing linear layer component
p-huynh Aug 29, 2023
aeb3741
Fixing long pytest
p-huynh Aug 29, 2023
f3156b1
Remove timing out test
p-huynh Aug 29, 2023
3876aeb
Adding absolute file paths
p-huynh Aug 30, 2023
36dc2cd
Adding dictionary files to avoid long regeneration times
p-huynh Aug 30, 2023
372e6f2
Add new pytest MILP xor truncated module
p-huynh Aug 30, 2023
5520de5
Reduce code smells
p-huynh Aug 30, 2023
1e97912
Reduce code smells and improve coverage
p-huynh Aug 30, 2023
1fddede
Reduce code smells and improve coverage (part 2)
p-huynh Aug 30, 2023
10f1088
Fixing pytests
p-huynh Aug 30, 2023
fa00a0f
More pytests fixing
p-huynh Aug 30, 2023
9a2dbd9
Improving code coverage and reducing duplication
p-huynh Aug 31, 2023
dcda3ad
Refactor to decrease duplication and code smells
p-huynh Aug 31, 2023
e9b36e0
Refactor to decrease duplication and code smells (2)
p-huynh Aug 31, 2023
2a7914c
Decrease cognitive complexity
p-huynh Sep 1, 2023
09b8d26
Qarmav2 creator done, to be fixed for unmatching test vectors
SimoPez Sep 3, 2023
638401e
Change: replaced BEA1 concatenate component for CP compatibility
RisingZero Sep 5, 2023
e34b15e
Merge pull request #62 from Crypto-TII/fix/bea1-remove-concatenate
peacker Sep 5, 2023
1ed7271
portage of cipher_inverse module from cryptalib to claasp
SiMohamedRachidi Sep 5, 2023
5aff976
add import
SiMohamedRachidi Sep 5, 2023
e41cd8d
Split deterministic truncated model into two distinct files (bitwise/…
p-huynh Sep 5, 2023
a094a32
Merge branch 'develop' into feat/LIBCA-1106-XOR_deterministic_truncat…
p-huynh Sep 5, 2023
5d932f1
cipher_inverse works for speck
SiMohamedRachidi Sep 5, 2023
45dda2e
polish code
SiMohamedRachidi Sep 5, 2023
e88e005
Fixing pytest after method name change
p-huynh Sep 5, 2023
f237399
Reduce code smells
p-huynh Sep 5, 2023
86ec53f
Correct pytest and increase coverage
p-huynh Sep 5, 2023
223f936
Fix incorrect method name called in pytest
p-huynh Sep 5, 2023
954d4c9
Remove duplicated code
p-huynh Sep 6, 2023
35fe7e3
Feat: Adding graph generator based on cipher component IDs
juaninf Sep 6, 2023
7b44f8f
change doctests
SiMohamedRachidi Sep 6, 2023
a7f1d9d
Adding space
juaninf Sep 6, 2023
7e90524
cipher_inverse() works for at least 16 ciphers
SiMohamedRachidi Sep 6, 2023
0c82597
Merge pull request #63 from Crypto-TII/feat/LIBCA-1222-graph-from-com…
peacker Sep 6, 2023
e22bb7a
Merge pull request #59 from Crypto-TII/feat/LIBCA-1221-heuristic-tota…
peacker Sep 6, 2023
5c1fb88
Add pytest for undisturbed bits inequalities generator
p-huynh Sep 6, 2023
c2ca4d5
polish code
SiMohamedRachidi Sep 6, 2023
628084b
polish code
SiMohamedRachidi Sep 6, 2023
b00cf5e
change doctests
SiMohamedRachidi Sep 6, 2023
fbed0f3
Add extra pytests for code coverage
p-huynh Sep 6, 2023
3d626a5
take into account update of BitArray in generic_function.py
SiMohamedRachidi Sep 7, 2023
dbf20fc
Adding initial MILP impossible differential model
p-huynh Sep 8, 2023
cc88f93
Merge pull request #60 from Crypto-TII/feat/LIBCA-1106-XOR_determinis…
peacker Sep 12, 2023
6c1f020
updated of a5_1
Sep 13, 2023
19f73bb
updated of a5_2
Sep 13, 2023
6d74b60
Merge remote-tracking branch 'origin/develop' into develop
Sep 13, 2023
817a528
Merge branch 'develop' into LIBCA-1117-add-fsr-component
Sep 13, 2023
db93924
bug with intermediate_output still to be fixed
SiMohamedRachidi Sep 14, 2023
8fed3ad
modified mod_add component and added zuc stram cipher
Sep 15, 2023
1a9b113
modified mod_add component and added zuc stram cipher
Sep 15, 2023
88d6947
adding a parameter in modsub component similar to modadd
Sep 15, 2023
493c590
Merge branch 'develop' into feat/cipher_inversion_improved
p-huynh Sep 18, 2023
c6c55ae
manage to fix intermediate_output bug
SiMohamedRachidi Sep 18, 2023
95f0681
cipher_inverse() now works on 18 ciphers
SiMohamedRachidi Sep 18, 2023
3bc123c
Merge branch 'feat/cipher_inversion' into feat/cipher_inversion_improved
p-huynh Sep 18, 2023
493b879
updated of lfsr component
Sep 18, 2023
e7af5d7
cipher_inverse() now works for 20 ciphers
SiMohamedRachidi Sep 19, 2023
32fe5b2
modify doctests
SiMohamedRachidi Sep 19, 2023
97b7af2
added test file for zuc cipher and polished zuc code
Sep 19, 2023
1c0985b
add partial cipher inversion methods
p-huynh Sep 19, 2023
818052d
Merge branch 'feat/cipher_inversion_improved' into feat/MILP_impossib…
p-huynh Sep 19, 2023
87f745f
fix bug on chacha. The words of plaintext are not in the correct order
SiMohamedRachidi Sep 19, 2023
3f62fd7
Refactor SAT MODADD constraints
ale-depi Sep 20, 2023
7196b08
Refactor the solution parsing framework
ale-depi Sep 20, 2023
c46a573
FIX/Fix: upgrade Tensorflow to work with m1 architecture
AnaCaceres Sep 20, 2023
7ca7345
Merge branch 'develop' into fix/tensorflow
yessica-rd Sep 20, 2023
4e4b9dc
Rename variables and fix doctests
ale-depi Sep 20, 2023
9160013
Merge pull request #64 from Crypto-TII/fix/tensorflow
peacker Sep 20, 2023
f8f308b
polished zuc code
Sep 21, 2023
a2e4b62
Merge branch 'feat/add-new-parameter-modadd-component' into develop
Sep 21, 2023
5a6f924
modified fsr component
Sep 25, 2023
2de86bf
Merge branch 'develop' into feat-fsr_component_and_stream_ciphers
Sep 25, 2023
e985f2d
added trivium stream cipher
Sep 25, 2023
aa77c3c
Merge pull request #66 from Crypto-TII/feat/add-new-parameter-modadd-…
peacker Sep 26, 2023
3573cd0
added bivium stream cipher and test for trivium stream cipher
Sep 26, 2023
d57061c
added a test vector for bivium stream cipher
Sep 26, 2023
2510cbb
Merge branch 'develop' into feat-fsr_component_and_stream_ciphers
Sep 26, 2023
63f684d
Permutations fixed
SimoPez Sep 26, 2023
a76d8e1
minor polishing on fsr component and trivium stream cipher
Sep 27, 2023
3d114fc
initialization clocks is done in one fsr component
Sep 27, 2023
55854a3
LFSR updated
SimoPez Sep 28, 2023
e03b695
Fix pytests in new framework
ale-depi Oct 3, 2023
9a5a09e
Add bitwise and wordwise impossible xor differential models
p-huynh Oct 3, 2023
531d8fc
Merge branch 'develop' into feat/MILP_impossible_differential_trail_s…
p-huynh Oct 3, 2023
cb30e2a
Merge branch 'develop' into feat/MILP_impossible_differential_trail_s…
p-huynh Oct 3, 2023
952f4e9
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 3, 2023
225798f
Merge branch develop
ale-depi Oct 3, 2023
495f2a5
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 3, 2023
79ddd6d
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 3, 2023
435810f
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 3, 2023
5fd8ca8
➕ Add networkx to Dockerfile to fix numpy tests errors
yessica-rd Oct 5, 2023
73b526f
- Add bitwise method to automatically search for impossible trails wi…
p-huynh Oct 5, 2023
c96f26a
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 5, 2023
fa2b278
🧪 Update remote-pytest Makefile command
yessica-rd Oct 5, 2023
a2fe057
Add SMT constraints for MODADD
ale-depi Oct 5, 2023
c26e732
Created test and fixed implementation errors
SimoPez Oct 6, 2023
68a6324
Start refactoring of SMT models
ale-depi Oct 6, 2023
99269ca
Refactor set component fields name
ale-depi Oct 6, 2023
39c4549
Merge SAT branch to update
ale-depi Oct 6, 2023
0ba57c9
Refactor names
ale-depi Oct 6, 2023
cb675d1
Implement parse solver output
ale-depi Oct 6, 2023
a87d26d
Implement parse solver output
ale-depi Oct 6, 2023
a7661b9
- Add wordwise method to automatically search for impossible trails w…
p-huynh Oct 7, 2023
68d52be
Merge remote-tracking branch 'origin/fix/update-dockerfile' into feat…
p-huynh Oct 9, 2023
d419762
- split all MILP output parsing methods
p-huynh Oct 9, 2023
33adaa0
Merge remote-tracking branch 'origin/fix/update-dockerfile' into feat…
p-huynh Oct 9, 2023
d7fb14a
- split all MILP output parsing methods
p-huynh Oct 9, 2023
6bf683d
Merge remote-tracking branch 'origin/feat/separate_output_parsers_for…
p-huynh Oct 9, 2023
5d90537
Merge remote-tracking branch 'origin/feat/separate_output_parsers_for…
p-huynh Oct 9, 2023
80d030a
Merge remote-tracking branch 'origin/feat/separate_output_parsers_for…
p-huynh Oct 10, 2023
5fb3959
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 9, 2023
2862610
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 9, 2023
ef4f193
Merge remote-tracking branch 'origin/feat/MILP_impossible_differentia…
p-huynh Oct 10, 2023
e1833ae
Merge branch 'feat/MILP_impossible_differential_trail_search' into fe…
p-huynh Oct 10, 2023
e8f8252
Merge pull request #69 from Crypto-TII/feat/MILP_impossible_different…
peacker Oct 10, 2023
f9ead52
Merge branch 'develop' into feat/qarma_v2_creator
SimoPez Oct 10, 2023
0a3f788
Fixing numpy and networkx versions
juaninf Oct 10, 2023
556dca9
Fixing _get_descendants_subgraph method
Oct 10, 2023
619f893
Merge pull request #73 from Crypto-TII/fix/LIBCA-1224-fixing-numpy-an…
peacker Oct 11, 2023
6932cee
Merge pull request #74 from Crypto-TII/fix/LIBCA-1225-fixing-graph-mo…
peacker Oct 11, 2023
cecf080
added test for bivium stream cipher and polished code of bivium & tri…
Oct 11, 2023
19a7d2d
Merge branch 'develop' into feat-fsr_component_and_stream_ciphers
Oct 11, 2023
31e860a
Fix MixColumn component inversion
p-huynh Oct 11, 2023
3671a80
Fix MixColumn component inversion
p-huynh Oct 11, 2023
2c7bf1a
Merge remote-tracking branch 'origin/fix/mix_column_component_inversi…
p-huynh Oct 11, 2023
550c4be
Fixed Theta component of Keccak to accomodate variable wordsize
p-huynh Oct 12, 2023
0bfc5b3
Merge branch develop
ale-depi Oct 12, 2023
0b74032
Merge branch develop
ale-depi Oct 12, 2023
a7223a5
Fix SMT pytests
ale-depi Oct 13, 2023
8392a76
Added component_values
juaninf Oct 13, 2023
2da22a7
Added: component_values to Minizinc output model
juaninf Oct 14, 2023
00b3874
cleaned branch to add bivium stream cipher
Oct 14, 2023
0d9f306
Added component_values key to dictionary of solutions
juaninf Oct 14, 2023
002a5db
Added component_values key to dictionary of solutions
juaninf Oct 14, 2023
127d14b
modified fsr_word generic function
Oct 15, 2023
4596038
added tests for fsr_binary and fsr_word generic functions and finaliz…
Oct 15, 2023
ded061f
cleaned to merge bivium stream cipher into develop
Oct 15, 2023
c0b2183
added a test for add_FSR_component and completed bivium stream cipher
Oct 15, 2023
d26c5ac
modified slightly to reduce duplications
Oct 16, 2023
b92c13d
fixed a verbosity typo
Oct 16, 2023
af887f8
added trivium stream cipher
Oct 16, 2023
9040390
polished trivium stream cipher code
Oct 17, 2023
c295d16
Fix: xor-diff-mzn-model
juaninf Oct 18, 2023
19a019c
Merge branch 'develop' into fix/mix_column_component_inversion_as_wor…
p-huynh Oct 24, 2023
1d68d90
Merge branch 'develop' into feat/separate_output_parsers_for_MILP_models
p-huynh Oct 24, 2023
c3888a6
LBlock cipher
Oct 24, 2023
53e2b73
Improve bitwise truncated linear layer component
p-huynh Oct 24, 2023
703902f
Merge branch 'develop' into fix/keccak_theta_for_smaller_wordsize
p-huynh Oct 24, 2023
cd4a590
Remove unused variables
p-huynh Oct 24, 2023
955c821
Remove unused variables
p-huynh Oct 24, 2023
ca58a15
Merge remote-tracking branch 'origin/feat/separate_output_parsers_for…
p-huynh Oct 24, 2023
06f2084
Merge branch 'develop' into feat/qarma_v2_creator
SimoPez Oct 24, 2023
93598b6
Add pytest for linear layer component improvement
p-huynh Oct 24, 2023
b4ff57c
Add pytest for linear layer component improvement
p-huynh Oct 24, 2023
c55ffb8
Merge pull request #76 from Crypto-TII/feature/sat-modadd-having-more…
peacker Oct 24, 2023
4cdc6eb
Merge pull request #91 from Crypto-TII/feature/LBLOCK_cipher
peacker Oct 24, 2023
b93be47
Merge pull request #89 from Crypto-TII/fix/mix_column_component_inver…
peacker Oct 24, 2023
fd8efb3
- Decrease code duplicatio
p-huynh Oct 25, 2023
3cd24a7
Merge branch 'develop' into feat/separate_output_parsers_for_MILP_models
p-huynh Oct 25, 2023
0c0c6ed
Merge branch 'develop' into fix/keccak_theta_for_smaller_wordsize
p-huynh Oct 25, 2023
97724f3
Merge branch develop
ale-depi Oct 26, 2023
2d18391
- Extend cipher inversion to Chacha permutation
p-huynh Oct 27, 2023
8cb5dc3
Merge pull request #79 from Crypto-TII/feat/add-details-to-minizinc-s…
peacker Oct 27, 2023
2c1885c
Merge pull request #81 from Crypto-TII/feat-fsr_component_and_bivium_…
peacker Oct 27, 2023
c959022
Merge pull request #83 from Crypto-TII/feat-trivium_stream_cipher
peacker Oct 27, 2023
c786733
Merge pull request #93 from Crypto-TII/feat/qarma_v2_creator
peacker Oct 27, 2023
bb33f14
Merge pull request #90 from Crypto-TII/feat/separate_output_parsers_f…
peacker Oct 27, 2023
9b845f8
Merge pull request #92 from Crypto-TII/fix/keccak_theta_for_smaller_w…
peacker Oct 27, 2023
e1a79ec
Merge branch 'develop' into fix/chacha_inversion
p-huynh Oct 27, 2023
d1f3ebb
Merge branch develop
ale-depi Oct 30, 2023
1a79cb7
- Decrease cognitive complexity
p-huynh Oct 30, 2023
2ef20e3
- Decrease cognitive complexity
p-huynh Oct 30, 2023
44741f8
Merge remote-tracking branch 'origin/fix/chacha_inversion' into fix/c…
p-huynh Oct 30, 2023
f754a3e
Clean deterministic truncated for CMS and SMT
ale-depi Oct 30, 2023
3286d3c
Merge pull request #77 from Crypto-TII/feature/smt-modadd-having-more…
peacker Oct 31, 2023
33ed5c6
Merge pull request #97 from Crypto-TII/fix/chacha_inversion
peacker Oct 31, 2023
9948c69
- Improve cipher inversion to cover additional cases
p-huynh Nov 1, 2023
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
110 changes: 106 additions & 4 deletions claasp/cipher_modules/component_analysis_tests.py
Original file line number Diff line number Diff line change
@@ -281,10 +281,32 @@ def branch_number(component, type, format):
return min(calculate_weights_for_mix_column(component, format, type))

def instantiate_matrix_over_correct_field(matrix, polynomial_as_int, word_size, input_bit_size, output_bit_size):
G = PolynomialRing(GF(2 ** word_size), 'x')
"""
sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field, field_element_matrix_to_integer_matrix
sage: midori = MidoriBlockCipher(number_of_rounds=2)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_20')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
mix_column_component.input_bit_size, mix_column_component.output_bit_size)

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field, field_element_matrix_to_integer_matrix
sage: midori = MidoriBlockCipher(number_of_rounds=2)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_21')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
mix_column_component.input_bit_size, mix_column_component.output_bit_size)

"""

G = PolynomialRing(GF(2), 'x')
x = G.gen()
irr_poly = int_to_poly(polynomial_as_int, word_size, x)
F = QuotientRing(G, G.ideal(irr_poly), 'a')
if irr_poly:
F = GF(2 ** word_size, name='a', modulus=irr_poly)
else:
F = GF(2 ** word_size)
a = F.gen()
input_word_size = input_bit_size // word_size
output_word_size = output_bit_size // word_size
@@ -296,6 +318,7 @@ def instantiate_matrix_over_correct_field(matrix, polynomial_as_int, word_size,
final_mtr = Matrix(F, mtr)

return final_mtr, F

def is_mds(component):
"""
A matrix is MDS if and only if all the minors (determinants of square submatrices) are non-zero
@@ -337,10 +360,82 @@ def is_mds(component):
for i in range(num_rows - size + 1):
for j in range(num_cols - size + 1):
submatrix = final_mtr[i:i + size, j:j + size]
if submatrix.det() == 0:
if submatrix.is_singular():
return False
return True

def field_element_matrix_to_integer_matrix(matrix):
"""
Converts a matrix of field elements to the corresponding integer matrix representation

INPUT:

- ``matrix`` -- **Matrix object**; a matrix whose entries are field elements

EXAMPLES::

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import instantiate_matrix_over_correct_field, field_element_matrix_to_integer_matrix
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: description = mix_column_component.description
sage: mc_matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
mix_column_component.input_bit_size, mix_column_component.output_bit_size)
sage: mc_matrix
[ a a + 1 1 1]
[ 1 a a + 1 1]
[ 1 1 a a + 1]
[a + 1 1 1 a]
sage: field_element_matrix_to_integer_matrix(mc_matrix)
[2 3 1 1]
[1 2 3 1]
[1 1 2 3]
[3 1 1 2]
"""

int_matrix = []
for i in range(matrix.nrows()):
for j in range(matrix.ncols()):
int_matrix.append(matrix[i][j].integer_representation())

return Matrix(matrix.nrows(), matrix.ncols(), int_matrix)

def get_inverse_matrix_in_integer_representation(component):
"""
Returns the inverse matrix in its integer representation

INPUT:

- ``component`` -- **Component object**; a component from the cipher

EXAMPLES::

sage: from claasp.ciphers.block_ciphers.aes_block_cipher import AESBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import get_inverse_matrix_in_integer_representation
sage: aes = AESBlockCipher(number_of_rounds=3)
sage: mix_column_component = aes.get_component_from_id('mix_column_1_20')
sage: get_inverse_matrix_in_integer_representation(mix_column_component)
[14 11 13 9]
[ 9 14 11 13]
[13 9 14 11]
[11 13 9 14]

sage: from claasp.ciphers.block_ciphers.midori_block_cipher import MidoriBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import get_inverse_matrix_in_integer_representation
sage: midori = MidoriBlockCipher(number_of_rounds=3)
sage: mix_column_component = midori.get_component_from_id('mix_column_0_20')
sage: get_inverse_matrix_in_integer_representation(mix_column_component)


"""
if component.type != MIX_COLUMN:
raise Exception(f"Component is not of type {MIX_COLUMN}")

description = component.description
matrix, _ = instantiate_matrix_over_correct_field(description[0], int(description[1]), int(description[2]),
component.input_bit_size, component.output_bit_size)
return field_element_matrix_to_integer_matrix(matrix.inverse())

def has_maximal_branch_number(component):
"""
INPUT:
@@ -349,6 +444,13 @@ def has_maximal_branch_number(component):

EXAMPLES::

sage: from claasp.ciphers.block_ciphers.twofish_block_cipher import TwofishBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: twofish = TwofishBlockCipher(number_of_rounds=2)
sage: mix_column_component = twofish.get_component_from_id('mix_column_0_1')
sage: has_maximal_branch_number(mix_column_component)
True

sage: from claasp.ciphers.block_ciphers.twofish_block_cipher import TwofishBlockCipher
sage: from claasp.cipher_modules.component_analysis_tests import has_maximal_branch_number
sage: twofish = TwofishBlockCipher(number_of_rounds=2)
@@ -374,7 +476,7 @@ def has_maximal_branch_number(component):
word_size = int(description[2])
output_word_size = component.output_bit_size // word_size

if component.type == "mix_column":
if component.type == MIX_COLUMN:
return branch_number(component, 'linear', 'word') == (output_word_size + 1)

def calculate_weights_for_mix_column(component, format, type):
15 changes: 8 additions & 7 deletions claasp/cipher_modules/inverse_cipher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from copy import *

from sage.crypto.sbox import SBox
from claasp.cipher_modules.component_analysis_tests import binary_matrix_of_linear_component
from claasp.cipher_modules.component_analysis_tests import binary_matrix_of_linear_component, \
get_inverse_matrix_in_integer_representation
from claasp.component import Component
from claasp.components import modsub_component, cipher_output_component, linear_layer_component
from claasp.input import Input
@@ -725,13 +726,13 @@ def component_inverse(component, available_bits, all_equivalent_bits, key_schedu
setattr(inverse_component, "round", component.round)
update_output_bits(inverse_component, self, all_equivalent_bits, available_bits)
elif component.type == MIX_COLUMN:
input_id_links, input_bit_positions = compute_input_id_links_and_input_bit_positions_for_inverse_component_from_available_output_components(component, available_output_components, all_equivalent_bits, self)
binary_matrix = binary_matrix_of_linear_component(component)
inv_binary_matrix = binary_matrix.inverse()
inverse_component = Component(component.id, LINEAR_LAYER,
input_id_links, input_bit_positions = compute_input_id_links_and_input_bit_positions_for_inverse_component_from_available_output_components(
component, available_output_components, all_equivalent_bits, self)
inv_matrix = get_inverse_matrix_in_integer_representation(component)
inverse_component = Component(component.id, component.type,
Input(component.input_bit_size, input_id_links, input_bit_positions),
component.output_bit_size, list(inv_binary_matrix.transpose()))
inverse_component.__class__ = linear_layer_component.LinearLayer
component.output_bit_size, [[list(row) for row in inv_matrix]] + component.description[1:])
inverse_component.__class__ = component.__class__
setattr(inverse_component, "round", component.round)
update_output_bits(inverse_component, self, all_equivalent_bits, available_bits)
elif component.type == WORD_OPERATION and component.description[0] == "SIGMA":
4 changes: 2 additions & 2 deletions tests/unit/components/linear_layer_component_test.py
Original file line number Diff line number Diff line change
@@ -309,8 +309,8 @@ def test_milp_wordwise_deterministic_truncated_xor_differential_constraints():
variables, constraints = linear_layer_component.milp_wordwise_deterministic_truncated_xor_differential_constraints(milp)
assert str(variables[0]) == "('x[rot_0_17_word_0_class_bit_0]', x_0)"
assert str(variables[1]) == "('x[rot_0_17_word_0_class_bit_1]', x_1)"
assert str(variables[-2]) == "('x[mix_column_0_21_word_31_class_bit_0]', x_126)"
assert str(variables[-1]) == "('x[mix_column_0_21_word_31_class_bit_1]', x_127)"
assert str(variables[-2]) == "('x[mix_column_0_21_word_3_class_bit_0]', x_14)"
assert str(variables[-1]) == "('x[mix_column_0_21_word_3_class_bit_1]', x_15)"

assert str(constraints[0]) == '1 <= 1 + x_0 + x_1 + x_2 + x_3 + x_4 + x_5 + x_6 - x_15'
assert str(constraints[1]) == '1 <= 1 + x_0 + x_1 + x_2 + x_3 + x_4 + x_5 + x_7 - x_15'