Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fixup: Elements of finite fields are not instances of FieldElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 18, 2022
1 parent 97a363e commit 0c01403
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/sage/crypto/mq/rijndael_gf.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@

from sage.matrix.constructor import matrix
from sage.matrix.constructor import column_matrix
from sage.structure.element import FieldElement, Matrix
from sage.structure.element import Element, Matrix
from sage.rings.finite_rings.finite_field_constructor import FiniteField
from sage.structure.sage_object import SageObject
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
Expand Down Expand Up @@ -757,7 +757,9 @@ def _GF_to_hex(self, GF):
sage: rgf._GF_to_hex(output)
'e142cd5fcd9d6d94a3340793034391b5'
"""
if not isinstance(GF, (Matrix, list, FieldElement)):
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self._F))
Expand Down Expand Up @@ -880,7 +882,9 @@ def _GF_to_bin(self, GF):
sage: rgf._GF_to_bin(output)
'11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011'
"""
if not isinstance(GF, (Matrix, list, FieldElement)):
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self))
Expand Down
5 changes: 3 additions & 2 deletions src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cimport cython
from cysignals.memory cimport check_allocarray, sig_free

from sage.structure.sage_object cimport SageObject
from sage.structure.element cimport Element, FieldElement
from sage.structure.element cimport Element

from sage.combinat.integer_vector import IntegerVectors
from sage.crypto.boolean_function import BooleanFunction
Expand All @@ -17,6 +17,7 @@ from sage.misc.functional import is_even
from sage.misc.misc_c import prod as mul
from sage.misc.superseded import deprecated_function_alias
from sage.modules.free_module_element import vector
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.ideal import FieldIdeal, Ideal
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -194,7 +195,7 @@ cdef class SBox(SageObject):

_S_list = []
for e in S:
if isinstance(e, FieldElement) and e.parent().is_finite():
if isinstance(e, Element) and isinstance(e.parent(), FiniteField):
e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic())
_S_list.append(e)
S = _S_list
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/algebraic_closure_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.ring import Field
from sage.structure.element import FieldElement
from sage.structure.element import Element, FieldElement
from sage.structure.richcmp import richcmp


Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self, parent, value):
and ``loads(dumps(x))``.
"""
if isinstance(value, FieldElement) and value.parent().is_finite():
if isinstance(value, Element) and isinstance(value.parent(), FiniteField):
n = value.parent().degree()
else:
from sage.rings.integer import Integer
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/padics/padic_template_element.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ from sage.rings.infinity import infinity
from sage.rings.rational import Rational
from sage.rings.padics.precision_error import PrecisionError
from sage.rings.padics.misc import trim_zeros
from sage.structure.element import canonical_coercion, FieldElement
from sage.structure.element import canonical_coercion, Element
import itertools

cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1
Expand Down Expand Up @@ -146,7 +146,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
elif sage.rings.finite_rings.integer_mod.is_IntegerMod(x):
if not Integer(self.prime_pow.prime).divides(x.parent().order()):
raise TypeError("p does not divide modulus %s"%x.parent().order())
elif isinstance(x, FieldElement) and isinstance(x.parent(), FiniteField):
elif isinstance(x, Element) and isinstance(x.parent(), FiniteField):
k = self.parent().residue_field()
if not k.has_coerce_map_from(x.parent()):
raise NotImplementedError("conversion from finite fields which do not embed into the residue field not implemented")
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field
from sage.rings.all import Integer, ZZ, PolynomialRing, GF, polygen
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.structure.element import FieldElement
from sage.structure.element import Element
import sage.groups.generic as generic
from . import ell_point
from sage.arith.all import gcd, lcm, binomial
Expand Down Expand Up @@ -1530,7 +1530,7 @@ def is_j_supersingular(j, proof=True):
sage: [p for p in prime_range(100) if is_j_supersingular(GF(p)(123456))]
[2, 3, 59, 89]
"""
if not (isinstance(j, FieldElement) and isinstance(j.parent(), FiniteField)):
if not (isinstance(j, Element) and isinstance(j.parent(), FiniteField)):
raise ValueError("%s must be an element of a finite field" % j)

F = j.parent()
Expand Down

0 comments on commit 0c01403

Please sign in to comment.