Skip to content

Commit

Permalink
gh-36106: sage.crypto: Update # needs, modularization fixes
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
- Part of: #29705
- Cherry-picked from: #35095
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes #12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- #12345: short description why this is a dependency
- #34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: #36106
Reported by: Matthias Köppe
Reviewer(s): David Coudert, Matthias Köppe
  • Loading branch information
Release Manager committed Aug 26, 2023
2 parents ce7457f + 37a6b46 commit 300fd19
Show file tree
Hide file tree
Showing 21 changed files with 435 additions and 375 deletions.
9 changes: 5 additions & 4 deletions src/sage/crypto/block_cipher/des.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
DES
Expand Down Expand Up @@ -77,7 +78,7 @@
from sage.rings.integer_ring import ZZ
from sage.modules.free_module_element import vector
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.modules.vector_mod2_dense import Vector_mod2_dense
from sage.structure.element import Vector
from sage.rings.integer import Integer
from sage.crypto.sboxes import DES_S1_1, DES_S1_2, DES_S1_3, DES_S1_4
from sage.crypto.sboxes import DES_S2_1, DES_S2_2, DES_S2_3, DES_S2_4
Expand Down Expand Up @@ -511,7 +512,7 @@ def encrypt(self, plaintext, key):
sage: des.encrypt(P, K56) == C
True
"""
if isinstance(plaintext, (list, tuple, Vector_mod2_dense)):
if isinstance(plaintext, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(plaintext, (Integer, int)):
inputType = 'integer'
Expand Down Expand Up @@ -568,7 +569,7 @@ def decrypt(self, ciphertext, key):
sage: des.decrypt(C, K56).hex() == P
True
"""
if isinstance(ciphertext, (list, tuple, Vector_mod2_dense)):
if isinstance(ciphertext, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(ciphertext, (Integer, int)):
inputType = 'integer'
Expand Down Expand Up @@ -868,7 +869,7 @@ def __call__(self, key):
pass a ``masterKey`` value on initialisation. Otherwise you can
omit ``masterKey`` and pass a key when you call the object.
"""
if isinstance(key, (list, tuple, Vector_mod2_dense)):
if isinstance(key, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(key, (Integer, int)):
inputType = 'integer'
Expand Down
1 change: 1 addition & 0 deletions src/sage/crypto/block_cipher/miniaes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.combinat sage.modules sage.rings.finite_rings
r"""
Mini-AES
Expand Down
9 changes: 5 additions & 4 deletions src/sage/crypto/block_cipher/present.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.modules sage.rings.finite_rings
r"""
PRESENT
Expand Down Expand Up @@ -63,8 +64,8 @@
from sage.rings.integer import Integer
from sage.modules.free_module_element import vector
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.structure.element import Vector
from sage.crypto.sboxes import PRESENT as PRESENTSBOX
from sage.modules.vector_mod2_dense import Vector_mod2_dense


def _smallscale_present_linearlayer(nsboxes=16):
Expand Down Expand Up @@ -417,7 +418,7 @@ def encrypt(self, plaintext, key):
\leq 32` and current STATE `b_{63} \dots b_0`, addRoundkey consists of
the operation for `0 \leq j \leq 63`, `b_j = b_j \oplus \kappa^i_j`.
"""
if isinstance(plaintext, (list, tuple, Vector_mod2_dense)):
if isinstance(plaintext, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(plaintext, (Integer, int)):
inputType = 'integer'
Expand Down Expand Up @@ -473,7 +474,7 @@ def decrypt(self, ciphertext, key):
sage: present.decrypt(c4, k4) == p4
True
"""
if isinstance(ciphertext, (list, tuple, Vector_mod2_dense)):
if isinstance(ciphertext, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(ciphertext, (Integer, int)):
inputType = 'integer'
Expand Down Expand Up @@ -773,7 +774,7 @@ def __call__(self, K):
pass a ``master_key`` value on initialisation. Otherwise you can
omit ``master_key`` and pass a key when you call the object.
"""
if isinstance(K, (list, tuple, Vector_mod2_dense)):
if isinstance(K, (list, tuple, Vector)):
inputType = 'vector'
elif isinstance(K, (Integer, int)):
inputType = 'integer'
Expand Down
1 change: 1 addition & 0 deletions src/sage/crypto/block_cipher/sdes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.combinat sage.rings.finite_rings
r"""
Simplified DES
Expand Down
Loading

0 comments on commit 300fd19

Please sign in to comment.