Skip to content

Commit 300fd19

Browse files
author
Release Manager
committed
gh-36106: `sage.crypto`: Update `# needs`, modularization fixes <!-- ^^^^^ 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
2 parents ce7457f + 37a6b46 commit 300fd19

21 files changed

+435
-375
lines changed

src/sage/crypto/block_cipher/des.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.modules sage.rings.finite_rings
12
r"""
23
DES
34
@@ -77,7 +78,7 @@
7778
from sage.rings.integer_ring import ZZ
7879
from sage.modules.free_module_element import vector
7980
from sage.rings.finite_rings.finite_field_constructor import GF
80-
from sage.modules.vector_mod2_dense import Vector_mod2_dense
81+
from sage.structure.element import Vector
8182
from sage.rings.integer import Integer
8283
from sage.crypto.sboxes import DES_S1_1, DES_S1_2, DES_S1_3, DES_S1_4
8384
from sage.crypto.sboxes import DES_S2_1, DES_S2_2, DES_S2_3, DES_S2_4
@@ -511,7 +512,7 @@ def encrypt(self, plaintext, key):
511512
sage: des.encrypt(P, K56) == C
512513
True
513514
"""
514-
if isinstance(plaintext, (list, tuple, Vector_mod2_dense)):
515+
if isinstance(plaintext, (list, tuple, Vector)):
515516
inputType = 'vector'
516517
elif isinstance(plaintext, (Integer, int)):
517518
inputType = 'integer'
@@ -568,7 +569,7 @@ def decrypt(self, ciphertext, key):
568569
sage: des.decrypt(C, K56).hex() == P
569570
True
570571
"""
571-
if isinstance(ciphertext, (list, tuple, Vector_mod2_dense)):
572+
if isinstance(ciphertext, (list, tuple, Vector)):
572573
inputType = 'vector'
573574
elif isinstance(ciphertext, (Integer, int)):
574575
inputType = 'integer'
@@ -868,7 +869,7 @@ def __call__(self, key):
868869
pass a ``masterKey`` value on initialisation. Otherwise you can
869870
omit ``masterKey`` and pass a key when you call the object.
870871
"""
871-
if isinstance(key, (list, tuple, Vector_mod2_dense)):
872+
if isinstance(key, (list, tuple, Vector)):
872873
inputType = 'vector'
873874
elif isinstance(key, (Integer, int)):
874875
inputType = 'integer'

src/sage/crypto/block_cipher/miniaes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.combinat sage.modules sage.rings.finite_rings
12
r"""
23
Mini-AES
34

src/sage/crypto/block_cipher/present.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.modules sage.rings.finite_rings
12
r"""
23
PRESENT
34
@@ -63,8 +64,8 @@
6364
from sage.rings.integer import Integer
6465
from sage.modules.free_module_element import vector
6566
from sage.rings.finite_rings.finite_field_constructor import GF
67+
from sage.structure.element import Vector
6668
from sage.crypto.sboxes import PRESENT as PRESENTSBOX
67-
from sage.modules.vector_mod2_dense import Vector_mod2_dense
6869

6970

7071
def _smallscale_present_linearlayer(nsboxes=16):
@@ -417,7 +418,7 @@ def encrypt(self, plaintext, key):
417418
\leq 32` and current STATE `b_{63} \dots b_0`, addRoundkey consists of
418419
the operation for `0 \leq j \leq 63`, `b_j = b_j \oplus \kappa^i_j`.
419420
"""
420-
if isinstance(plaintext, (list, tuple, Vector_mod2_dense)):
421+
if isinstance(plaintext, (list, tuple, Vector)):
421422
inputType = 'vector'
422423
elif isinstance(plaintext, (Integer, int)):
423424
inputType = 'integer'
@@ -473,7 +474,7 @@ def decrypt(self, ciphertext, key):
473474
sage: present.decrypt(c4, k4) == p4
474475
True
475476
"""
476-
if isinstance(ciphertext, (list, tuple, Vector_mod2_dense)):
477+
if isinstance(ciphertext, (list, tuple, Vector)):
477478
inputType = 'vector'
478479
elif isinstance(ciphertext, (Integer, int)):
479480
inputType = 'integer'
@@ -773,7 +774,7 @@ def __call__(self, K):
773774
pass a ``master_key`` value on initialisation. Otherwise you can
774775
omit ``master_key`` and pass a key when you call the object.
775776
"""
776-
if isinstance(K, (list, tuple, Vector_mod2_dense)):
777+
if isinstance(K, (list, tuple, Vector)):
777778
inputType = 'vector'
778779
elif isinstance(K, (Integer, int)):
779780
inputType = 'integer'

src/sage/crypto/block_cipher/sdes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.combinat sage.rings.finite_rings
12
r"""
23
Simplified DES
34

0 commit comments

Comments
 (0)