Uprating of the passphrase pixie.
[u/mdw/catacomb] / share.c
diff --git a/share.c b/share.c
index cc793db..23d730c 100644 (file)
--- a/share.c
+++ b/share.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: share.c,v 1.5 2000/12/06 20:30:10 mdw Exp $
+ * $Id: share.c,v 1.7 2004/04/08 01:36:15 mdw Exp $
  *
  * Shamir's secret sharing
  *
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: share.c,v $
- * Revision 1.5  2000/12/06 20:30:10  mdw
- * Change secret sharing interface: present the secret at share
- * construction time.
- *
- * Revision 1.4  2000/10/08 12:16:17  mdw
- * Use @MP_EQ@ instead of @MP_CMP@.
- *
- * Revision 1.3  2000/06/24 18:29:05  mdw
- * Interface change: allow shares to be extracted from a context on demand,
- * rather than building them all up-front.
- *
- * Revision 1.2  2000/06/18 23:05:19  mdw
- * Minor performance tweak: use Barrett reduction rather than Montgomery.
- * Fast secret sharing isn't done here, though: see `gfshare' instead.
- *
- * Revision 1.1  2000/06/17 12:09:38  mdw
- * Shamir's secret sharing system.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <stdio.h>
@@ -102,17 +79,14 @@ void share_destroy(share *s)
   /* --- Dispose of the share vector --- */
 
   if (s->v) {
-    for (i = 0; i < s->t; i++) {
-      if (s->v[i].y)
-       mp_drop(s->v[i].y);
-    }
+    for (i = 0; i < s->t; i++)
+      mp_drop(s->v[i].y);
     xfree(s->v);
   }
 
   /* --- Other stuff --- */
 
-  if (s->p)
-    mp_drop(s->p);
+  mp_drop(s->p);
 }
 
 /* --- @share_mkshares@ --- *
@@ -182,8 +156,7 @@ mp *share_get(share *s, mp *d, unsigned x)
   /* --- Various bits of initialization --- */
 
   mp_build(&u, &uw, &uw + 1);
-  if (d)
-    mp_drop(d);
+  mp_drop(d);
 
   /* --- Evaluate the polynomial at %$x = i + 1$% --- */
 
@@ -280,7 +253,7 @@ mp *share_combine(share *s)
        m = mp_sub(m, &ii, &jj);
        m = mp_sub(m, s->p, m);
       }
-      mp_gcd(0, 0, &m, s->p, m);
+      m = mp_modinv(m, m, s->p);
       c = mp_mul(c, c, &jj);
       c = mpbarrett_reduce(&mb, c, c);
       c = mp_mul(c, c, m);
@@ -293,8 +266,7 @@ mp *share_combine(share *s)
   }
 
   a = mpbarrett_reduce(&mb, a, a);
-  if (m)
-    mp_drop(m);
+  mp_drop(m);
   mpbarrett_destroy(&mb);
   return (a);
 }