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

sage.crypto: Update # needs, modularization fixes #36106

Merged
merged 15 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure that this change is safe for users ? I'm not sure it's currently tested...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this just distinguishes scalar input from list/vector input. In fact, when neither of the two conditions holds, inputType remains uninitialized, leading to an error in the last line of the function

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
Loading