ghash.h: Fix GH_HASHSTR64*.
[u/mdw/catacomb] / rho.c
diff --git a/rho.c b/rho.c
index d4530b8..a02eeba 100644 (file)
--- a/rho.c
+++ b/rho.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: rho.c,v 1.1 2000/07/09 21:32:30 mdw Exp $
+ * $Id: rho.c,v 1.5 2004/04/08 01:36:15 mdw Exp $
  *
  * Pollard's rho algorithm for discrete logs
  *
  * (c) 2000 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Catacomb.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * Catacomb is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with Catacomb; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: rho.c,v $
- * Revision 1.1  2000/07/09 21:32:30  mdw
- * Pollard's rho algorithm for computing discrete logs.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include "fibrand.h"
@@ -135,7 +127,7 @@ mp *rho(rho_ctx *cc, void *x, void *y, mp *a, mp *b)
   bb = mp_sub(bb, bb, b);
   g = MP_NEW;
   mp_gcd(&g, &bb, 0, bb, cc->n);
-  if (MP_CMP(g, !=, MP_ONE)) {
+  if (!MP_EQ(g, MP_ONE)) {
     mp_drop(aa);
     aa = 0;
   } else {
@@ -183,7 +175,7 @@ static void prime_mul(void *x, void *y, void *c)
 
 static int prime_eq(void *x, void *y)
 {
-  return (MP_CMP(*(mp **)x, ==, *(mp **)y));
+  return (MP_EQ(*(mp **)x, *(mp **)y));
 }
 
 static int prime_split(void *x)
@@ -209,7 +201,7 @@ static void prime_drop(void *x)
   MP_DROP(*(mp **)x);
 }
 
-static rho_ops prime_ops = {
+static const rho_ops prime_ops = {
   prime_sqr, prime_mul, prime_eq, prime_split, prime_drop
 };
 
@@ -237,14 +229,14 @@ mp *rho_prime(mp *g, mp *a, mp *n, mp *p)
   /* --- The main loop --- */
 
   while ((l = rho(&cc, &x, &y, aa, bb)) == 0) {
-    mpmont_factor f[2];
+    mp_expfactor f[2];
 
     if (!r)
       r = fibrand_create(0);
     aa = mprand_range(MP_NEW, n, r, 0);
     bb = mprand_range(MP_NEW, n, r, 0);
-    f[0].base = g; f[0].exp = aa;
-    f[1].base = a; f[1].exp = bb;
+    f[0].base = cc.g; f[0].exp = aa;
+    f[1].base = cc.a; f[1].exp = bb;
     x = mpmont_mexpr(&mm, MP_NEW, f, 2);
     y = MP_COPY(x);
   }
@@ -285,7 +277,7 @@ int main(void)
   y = mpmont_exp(&mm, MP_NEW, dp.g, x);
   mpmont_destroy(&mm);
   l = rho_prime(dp.g, y, dp.q, dp.p);
-  if (MP_CMP(x, ==, l)) {
+  if (MP_EQ(x, l)) {
     fputs(". ok\n", stdout);
     ok = 1;
   } else {