From cbcab8ea4c74d5a1b36b8583571340ff728c2ad5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 9 Aug 2018 17:51:20 +0200 Subject: [PATCH] kernel: fix LogFFE on 32 bit systems Fixes #2687 --- src/finfield.c | 6 ++---- tst/testbugfix/2011-01-16-t00231.tst | 3 --- tst/testinstall/ffe.tst | 23 +++++++++++++++++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 tst/testbugfix/2011-01-16-t00231.tst diff --git a/src/finfield.c b/src/finfield.c index b74bda4c74..22ab809092 100644 --- a/src/finfield.c +++ b/src/finfield.c @@ -1471,11 +1471,9 @@ Obj FuncLOG_FFE_DEFAULT ( while (a < 0) a+= (qX -1)/c; - /* return the logarithm */ - - - return INTOBJ_INT( (((Int) (vZ-1) / c) * a) % ((Int) (qX-1)) ); + // return the logarithm + return INTOBJ_INT( (((UInt) (vZ-1) / c) * a) % ((UInt) (qX-1)) ); } diff --git a/tst/testbugfix/2011-01-16-t00231.tst b/tst/testbugfix/2011-01-16-t00231.tst deleted file mode 100644 index fc94139b92..0000000000 --- a/tst/testbugfix/2011-01-16-t00231.tst +++ /dev/null @@ -1,3 +0,0 @@ -# Reported by MN on 2009/10/06, added by AK on 2011/01/16 -gap> (Z(65536)^2)^LogFFE(Z(65536)^16386,Z(65536)^2) = Z(65536)^16386; -true diff --git a/tst/testinstall/ffe.tst b/tst/testinstall/ffe.tst index 2cebcea9ba..55dfa40cec 100644 --- a/tst/testinstall/ffe.tst +++ b/tst/testinstall/ffe.tst @@ -183,10 +183,29 @@ gap> DegreeFFE( [[Z(2),Z(8)],[Z(2), Z(4)]]); 6 # -gap> n:=LogFFE(Z(25)^3, Z(25)^7);; (Z(25)^7)^n; -Z(5^2)^3 +# LogFFE +# +gap> q:=25;; r:=Z(q)^7;; ForAll([0..q-2], i -> LogFFE(r^i,r)=i); +true +# test an issue reported by MN on 2009/10/06, added by AK on 2011/01/16 +gap> q:=2^16;; r:=Z(q)^2;; ForAll([0..q-2], i -> LogFFE(r^i,r)=i); +true + +# test an edge case on 32 bit systems, where a kernel value could overflow +# (see https://github.com/gap-system/gap/issues/2687) +gap> q:=37^3;; r:=Z(q)^1055;; ForAll([0..q-2], i -> LogFFE(r^i,r)=i); +true + +# error handling +gap> LogFFE(0*Z(2), Z(2)); +Error, LogFFE: must be a nonzero finite field element +gap> LogFFE(Z(2), 0*Z(2)); +Error, LogFFE: must be a nonzero finite field element + +# # RootFFE +# gap> Rochambeau:=function(F) > local e,i,p,a,r; > e:=Elements(F);