Skip to content

Commit 0c01403

Browse files
author
Matthias Koeppe
committed
Fixup: Elements of finite fields are not instances of FieldElement
1 parent 97a363e commit 0c01403

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/sage/crypto/mq/rijndael_gf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424

425425
from sage.matrix.constructor import matrix
426426
from sage.matrix.constructor import column_matrix
427-
from sage.structure.element import FieldElement, Matrix
427+
from sage.structure.element import Element, Matrix
428428
from sage.rings.finite_rings.finite_field_constructor import FiniteField
429429
from sage.structure.sage_object import SageObject
430430
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
@@ -757,7 +757,9 @@ def _GF_to_hex(self, GF):
757757
sage: rgf._GF_to_hex(output)
758758
'e142cd5fcd9d6d94a3340793034391b5'
759759
"""
760-
if not isinstance(GF, (Matrix, list, FieldElement)):
760+
if not isinstance(GF, Matrix) and \
761+
not isinstance(GF, list) and \
762+
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)):
761763
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
762764
"elements from {0}, or a single element from {0}")
763765
raise TypeError(msg.format(self._F))
@@ -880,7 +882,9 @@ def _GF_to_bin(self, GF):
880882
sage: rgf._GF_to_bin(output)
881883
'11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011'
882884
"""
883-
if not isinstance(GF, (Matrix, list, FieldElement)):
885+
if not isinstance(GF, Matrix) and \
886+
not isinstance(GF, list) and \
887+
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)):
884888
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
885889
"elements from {0}, or a single element from {0}")
886890
raise TypeError(msg.format(self))

src/sage/crypto/sbox.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cimport cython
55
from cysignals.memory cimport check_allocarray, sig_free
66

77
from sage.structure.sage_object cimport SageObject
8-
from sage.structure.element cimport Element, FieldElement
8+
from sage.structure.element cimport Element
99

1010
from sage.combinat.integer_vector import IntegerVectors
1111
from sage.crypto.boolean_function import BooleanFunction
@@ -17,6 +17,7 @@ from sage.misc.functional import is_even
1717
from sage.misc.misc_c import prod as mul
1818
from sage.misc.superseded import deprecated_function_alias
1919
from sage.modules.free_module_element import vector
20+
from sage.rings.finite_rings.finite_field_base import FiniteField
2021
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
2122
from sage.rings.ideal import FieldIdeal, Ideal
2223
from sage.rings.integer_ring import ZZ
@@ -194,7 +195,7 @@ cdef class SBox(SageObject):
194195

195196
_S_list = []
196197
for e in S:
197-
if isinstance(e, FieldElement) and e.parent().is_finite():
198+
if isinstance(e, Element) and isinstance(e.parent(), FiniteField):
198199
e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic())
199200
_S_list.append(e)
200201
S = _S_list

src/sage/rings/algebraic_closure_finite_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
from sage.rings.finite_rings.finite_field_base import FiniteField
6161
from sage.rings.ring import Field
62-
from sage.structure.element import FieldElement
62+
from sage.structure.element import Element, FieldElement
6363
from sage.structure.richcmp import richcmp
6464

6565

@@ -90,7 +90,7 @@ def __init__(self, parent, value):
9090
and ``loads(dumps(x))``.
9191
9292
"""
93-
if isinstance(value, FieldElement) and value.parent().is_finite():
93+
if isinstance(value, Element) and isinstance(value.parent(), FiniteField):
9494
n = value.parent().degree()
9595
else:
9696
from sage.rings.integer import Integer

src/sage/rings/padics/padic_template_element.pxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ from sage.rings.infinity import infinity
3737
from sage.rings.rational import Rational
3838
from sage.rings.padics.precision_error import PrecisionError
3939
from sage.rings.padics.misc import trim_zeros
40-
from sage.structure.element import canonical_coercion, FieldElement
40+
from sage.structure.element import canonical_coercion, Element
4141
import itertools
4242

4343
cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1
@@ -146,7 +146,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
146146
elif sage.rings.finite_rings.integer_mod.is_IntegerMod(x):
147147
if not Integer(self.prime_pow.prime).divides(x.parent().order()):
148148
raise TypeError("p does not divide modulus %s"%x.parent().order())
149-
elif isinstance(x, FieldElement) and isinstance(x.parent(), FiniteField):
149+
elif isinstance(x, Element) and isinstance(x.parent(), FiniteField):
150150
k = self.parent().residue_field()
151151
if not k.has_coerce_map_from(x.parent()):
152152
raise NotImplementedError("conversion from finite fields which do not embed into the residue field not implemented")

src/sage/schemes/elliptic_curves/ell_finite_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field
3131
from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen
3232
from sage.rings.finite_rings.finite_field_base import FiniteField
33-
from sage.structure.element import FieldElement
33+
from sage.structure.element import Element
3434
import sage.groups.generic as generic
3535
from . import ell_point
3636
from sage.arith.all import gcd, lcm, binomial
@@ -1530,7 +1530,7 @@ def is_j_supersingular(j, proof=True):
15301530
sage: [p for p in prime_range(100) if is_j_supersingular(GF(p)(123456))]
15311531
[2, 3, 59, 89]
15321532
"""
1533-
if not (isinstance(j, FieldElement) and isinstance(j.parent(), FiniteField)):
1533+
if not (isinstance(j, Element) and isinstance(j.parent(), FiniteField)):
15341534
raise ValueError("%s must be an element of a finite field" % j)
15351535

15361536
F = j.parent()

0 commit comments

Comments
 (0)