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

Correct NTL calls when computing modular powers of GF(2) polynomials #35325

Merged
merged 1 commit into from
Apr 13, 2023
Merged
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
30 changes: 22 additions & 8 deletions src/sage/libs/ntl/ntl_GF2X_linkage.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,23 @@ cdef inline int celement_pow(GF2X_c* res, GF2X_c* x, long e, GF2X_c *modulus, lo
x^9 + x^8 + x^7 + x^5 + x^3
sage: pow(f, 2, h)
x^9 + x^8 + x^7 + x^5 + x^3
sage: pow(x, 1000, h)
x^8 + x^7 + x^4
Check that deg x >= deg modulus works (:issue:`35324`)::
sage: pow(x+1, 2, x^2+x+1)
x
sage: pow(x^2+1, 2, x^2+x+1)
x + 1
"""
cdef GF2XModulus_c mod
cdef GF2X_c xmod

if modulus == NULL:
if GF2X_IsX(x[0]):
GF2X_LeftShift(res[0], x[0], e - 1)
GF2X_LeftShift(res[0], x[0], e - 1)
else:
do_sig = GF2X_deg(x[0]) > 1e5
if do_sig:
Expand All @@ -353,14 +364,17 @@ cdef inline int celement_pow(GF2X_c* res, GF2X_c* x, long e, GF2X_c *modulus, lo
if do_sig:
sig_off()
else:
GF2X_rem(xmod, x[0], modulus[0])
GF2XModulus_build(mod, modulus[0])

do_sig = GF2X_deg(x[0]) > 1e5
if do_sig:
sig_on()
GF2X_PowerMod_long_pre(res[0], x[0], e, mod)
if do_sig:
sig_off()
if GF2X_IsX(xmod):
GF2X_PowerXMod_long_pre(res[0], e, mod)
else:
do_sig = GF2X_deg(x[0]) > 1e5
if do_sig:
sig_on()
GF2X_PowerMod_long_pre(res[0], xmod, e, mod)
if do_sig:
sig_off()


cdef inline int celement_gcd(GF2X_c* res, GF2X_c* a, GF2X_c *b, long parent) except -2:
Expand Down