Change interface for suggested destinations.
[u/mdw/catacomb] / mpmont-mexp.c
index 1d1266f..b541f8c 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: mpmont-mexp.c,v 1.2 1999/11/21 11:35:10 mdw Exp $
+ * $Id: mpmont-mexp.c,v 1.3 1999/12/10 23:18:39 mdw Exp $
  *
  * Multiplle simultaneous exponentiations
  *
  *
  * Multiplle simultaneous exponentiations
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmont-mexp.c,v $
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmont-mexp.c,v $
+ * Revision 1.3  1999/12/10 23:18:39  mdw
+ * Change interface for suggested destinations.
+ *
  * Revision 1.2  1999/11/21 11:35:10  mdw
  * Performance improvement: use @mp_sqr@ and @mpmont_reduce@ instead of
  * @mpmont_mul@ for squaring in exponentiation.
  * Revision 1.2  1999/11/21 11:35:10  mdw
  * Performance improvement: use @mp_sqr@ and @mpmont_reduce@ instead of
  * @mpmont_mul@ for squaring in exponentiation.
@@ -49,6 +52,7 @@
 /* --- @mpmont_mexpr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
 /* --- @mpmont_mexpr@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ *             @mp *d@ = fake destination
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
@@ -64,7 +68,7 @@ typedef struct scan {
   mpw w;
 } scan;
 
   mpw w;
 } scan;
 
-mp *mpmont_mexpr(mpmont *mm, mpmont_factor *f, size_t n)
+mp *mpmont_mexpr(mpmont *mm, mp *d, mpmont_factor *f, size_t n)
 {
   size_t vn = 1 << n;
   mp **v = xmalloc(vn * sizeof(mp *));
 {
   size_t vn = 1 << n;
   mp **v = xmalloc(vn * sizeof(mp *));
@@ -186,12 +190,16 @@ mp *mpmont_mexpr(mpmont *mm, mpmont_factor *f, size_t n)
     free(s);
   }
 
     free(s);
   }
 
+  if (d != MP_NEW)
+    MP_DROP(d);
+
   return (a);
 }
 
 /* --- @mpmont_mexp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
   return (a);
 }
 
 /* --- @mpmont_mexp@ --- *
  *
  * Arguments:  @mpmont *mm@ = pointer to Montgomery reduction context
+ *             @mp *d@ = fake destination
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
  *             @mpmont_factor *f@ = pointer to array of factors
  *             @size_t n@ = number of factors supplied
  *
@@ -200,9 +208,9 @@ mp *mpmont_mexpr(mpmont *mm, mpmont_factor *f, size_t n)
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
  * Use:                Convenient interface over @mpmont_mexpr@.
  */
 
-mp *mpmont_mexp(mpmont *mm, mpmont_factor *f, size_t n)
+mp *mpmont_mexp(mpmont *mm, mp *d, mpmont_factor *f, size_t n)
 {
 {
-  mp *d = mpmont_mexpr(mm, f, n);
+  d = mpmont_mexpr(mm, d, f, n);
   d = mpmont_reduce(mm, d, d);
   return (d);
 }
   d = mpmont_reduce(mm, d, d);
   return (d);
 }
@@ -230,7 +238,7 @@ static int verify(size_t n, dstr *v)
 
   rr = *(mp **)v[j].buf;
   mpmont_create(&mm, m);
 
   rr = *(mp **)v[j].buf;
   mpmont_create(&mm, m);
-  r = mpmont_mexp(&mm, f, n);
+  r = mpmont_mexp(&mm, MP_NEW, f, n);
   if (MP_CMP(r, !=, rr)) {
     fputs("\n*** mexp failed\n", stderr);
     fputs("m = ", stderr); mp_writefile(m, stderr, 10);
   if (MP_CMP(r, !=, rr)) {
     fputs("\n*** mexp failed\n", stderr);
     fputs("m = ", stderr); mp_writefile(m, stderr, 10);
@@ -254,6 +262,7 @@ static int verify(size_t n, dstr *v)
   MP_DROP(r);
   MP_DROP(rr);
   mpmont_destroy(&mm);
   MP_DROP(r);
   MP_DROP(rr);
   mpmont_destroy(&mm);
+  assert(mparena_count(MPARENA_GLOBAL) == 0);
   return (ok);
 }
 
   return (ok);
 }