]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor: Pollard-rho a is now mp_limb_t
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Jul 2025 16:34:00 +0000 (09:34 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 Jul 2025 00:12:40 +0000 (17:12 -0700)
* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2): Use mp_limb_t, not unsigned long int,
for a parameter.  This avoids some casts, and avoids a theoretical
bug where converting to mp_limb_t loses info.

src/factor.c

index 850e32a59db7c9322c56b647c98ceda76d5d8be6..f7ddce0b8d5d53707ed766ca51ff754b321c2cdf 100644 (file)
@@ -1227,8 +1227,7 @@ mp_prime_p (mpz_t n)
 /* Insert into FACTORS the result of factoring N,
    using Pollard-rho with starting value A.  N must be odd.  */
 static void
-factor_using_pollard_rho (struct factors *factors,
-                          mp_limb_t n, unsigned long int a)
+factor_using_pollard_rho (struct factors *factors, mp_limb_t n, mp_limb_t a)
 {
   mp_limb_t x, z, y, P, t, ni, g;
 
@@ -1314,7 +1313,7 @@ factor_using_pollard_rho (struct factors *factors,
 
 static void
 factor_using_pollard_rho2 (struct factors *factors,
-                           mp_limb_t n1, mp_limb_t n0, unsigned long int a)
+                           mp_limb_t n1, mp_limb_t n0, mp_limb_t a)
 {
   mp_limb_t x1, x0, z1, z0, y1, y0, P1, P0, t1, t0, g1, g0, r1m;
 
@@ -1336,7 +1335,7 @@ factor_using_pollard_rho2 (struct factors *factors,
             {
               x0 = mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
               x1 = r1m;
-              addmod2 (x1, x0, x1, x0, 0, (mp_limb_t) a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
 
               submod2 (t1, t0, z1, z0, x1, x0, n1, n0);
               P0 = mulredc2 (&r1m, P1, P0, t1, t0, n1, n0, ni);
@@ -1359,7 +1358,7 @@ factor_using_pollard_rho2 (struct factors *factors,
             {
               x0 = mulredc2 (&r1m, x1, x0, x1, x0, n1, n0, ni);
               x1 = r1m;
-              addmod2 (x1, x0, x1, x0, 0, (mp_limb_t) a, n1, n0);
+              addmod2 (x1, x0, x1, x0, 0, a, n1, n0);
             }
           y1 = x1; y0 = x0;
         }
@@ -1369,7 +1368,7 @@ factor_using_pollard_rho2 (struct factors *factors,
         {
           y0 = mulredc2 (&r1m, y1, y0, y1, y0, n1, n0, ni);
           y1 = r1m;
-          addmod2 (y1, y0, y1, y0, 0, (mp_limb_t) a, n1, n0);
+          addmod2 (y1, y0, y1, y0, 0, a, n1, n0);
 
           submod2 (t1, t0, z1, z0, y1, y0, n1, n0);
           uuset (&g1, &g0, gcd2_odd (t1, t0, n1, n0));