FEATURE/Make permutation component independent from linear layer#454
Open
peacker wants to merge 14 commits into
Open
FEATURE/Make permutation component independent from linear layer#454peacker wants to merge 14 commits into
peacker wants to merge 14 commits into
Conversation
821eeb1 to
735e323
Compare
… to match naming convention, merge duplicate branches
There was a problem hiding this comment.
Pull request overview
This PR makes permutations first-class components (instead of being modeled as a special case of linear_layer) and extends them to support word-wise permutations via a word_size parameter, while still modeling at the bit level across the different constraint backends and code generators.
Changes:
- Introduces an independent
Permutationcomponent with SAT/SMT/CP/MILP/algebraic encodings and vectorized evaluation helpers. - Adds
word_sizesupport to permutation construction (editor +PermutationCipher) and evaluation (bit/byte generic functions). - Updates models, inverse-cipher logic, code generation, and unit tests to recognize
permutationcomponents and updated component IDs.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/components/permutation_component_test.py | Updates expectations for new permutation component identity/encoding; adds algebraic polynomial test. |
| tests/unit/ciphers/toys/toy_cipherFOUR_test.py | Updates verbose-evaluation transcript to reflect permutation_* component IDs. |
| tests/unit/ciphers/single_component_ciphers/permutation_cipher_test.py | Adds tests for custom permutations and word-wise permutations. |
| tests/unit/ciphers/permutations/spongent_pi_permutation_test.py | Updates expected component ID from linear_layer_* to permutation_*. |
| tests/unit/ciphers/block_ciphers/twofish_block_cipher_test.py | Updates expected component ID from linear_layer_* to permutation_*. |
| tests/unit/ciphers/block_ciphers/qarmav2_with_mixcolumn_block_cipher_test.py | Updates expected component ID from linear_layer_* to permutation_*. |
| tests/unit/ciphers/block_ciphers/des_exact_key_length_block_cipher_test.py | Updates expected component ID from linear_layer_* to permutation_*. |
| tests/unit/ciphers/block_ciphers/des_block_cipher_test.py | Updates expected component ID from linear_layer_* to permutation_*. |
| claasp/name_mappings.py | Adds PERMUTATION_COMPONENT = "permutation" component-type constant. |
| claasp/editor.py | Extends add_permutation_component API/docs to accept word_size; updates example output. |
| claasp/components/permutation_component.py | Reimplements permutation as an independent Component with constraints + codegen helpers. |
| claasp/ciphers/single_component_ciphers/permutation_cipher.py | Adds word_size support and default description behavior for word permutations. |
| claasp/cipher.py | Threads word_size through the Cipher.add_permutation_component wrapper. |
| claasp/cipher_modules/report.py | Adds backward-compat handling for historical show_permuation argument typo; avoids KeyErrors via .get(). |
| claasp/cipher_modules/models/sat/sat_models/sat_xor_differential_model.py | Includes permutation components when building SAT XOR-differential models. |
| claasp/cipher_modules/models/milp/milp_models/milp_xor_differential_model.py | Includes permutation components when building MILP XOR-differential models. |
| claasp/cipher_modules/inverse_cipher.py | Treats permutations as invertible and implements inversion by inverting the permutation list. |
| claasp/cipher_modules/generic_functions.py | Adds scalar permutation(...) evaluation helper (bit/word-wise). |
| claasp/cipher_modules/generic_functions_vectorized_byte.py | Adds byte_vector_permutation(...) for byte-vectorized evaluation. |
| claasp/cipher_modules/generic_functions_vectorized_bit.py | Adds bit_vector_permutation(...) and refactors verbosity labels (but introduces a NameError bug). |
| claasp/cipher_modules/code_generator.py | Allows permutation components in generated code and emits permutation(...) calls for non-vectorized evaluation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+34
to
+38
| For ``word_size=1`` this means ``output[permutation_description[i]] = input[i]``. | ||
|
|
||
| When ``word_size=1`` (default), this is a plain bitwise permutation where each entry in | ||
| ``permutation_description`` is a source *bit* index. When ``word_size > 1``, each entry is | ||
| a source *word* index and the description has ``output_bit_size // word_size`` elements. |
Comment on lines
+99
to
+103
| perm = self.description[0] | ||
| w = self.description[1] | ||
| src_to_dst = [perm[j // w] * w + (j % w) for j in range(self.output_bit_size)] | ||
| dst_to_src = [0] * self.output_bit_size | ||
| for src, dst in enumerate(src_to_dst): |
Comment on lines
+761
to
+762
| each entry is a source bit index. When ``word_size > 1``, each entry is a source word index and | ||
| the list has ``output_bit_size // word_size`` entries. |
Comment on lines
+18
to
+20
| # Permutation [3, 2, 1, 0]: output bit i = input bit perm[i] | ||
| # Output bit 0 = input bit 3, output bit 1 = input bit 2, etc. | ||
| # Input 0b1000 (bit 0=1, rest=0 in MSB-first indexing): |
Comment on lines
34
to
+38
| if permutation_description is None: | ||
| permutation_description = list(reversed(range(bit_size))) | ||
| if word_size == 1: | ||
| permutation_description = list(reversed(range(bit_size))) | ||
| else: | ||
| n_words = bit_size // word_size |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The permutation component is now an independent component (not falling back to binary linear layer behavior).
Furthermore, the component accepts a word bit size parameter to apply word-wise permutations.
The underlying modeling is still bit-wise.