Improve secret reconstruction -- compute coefficients as needed rather
authormdw <mdw>
Thu, 22 Jun 2000 18:04:13 +0000 (18:04 +0000)
committermdw <mdw>
Thu, 22 Jun 2000 18:04:13 +0000 (18:04 +0000)
than making a big array of them.

gfshare.c

index bbb0aee..a0b102d 100644 (file)
--- a/gfshare.c
+++ b/gfshare.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: gfshare.c,v 1.2 2000/06/18 23:12:15 mdw Exp $
+ * $Id: gfshare.c,v 1.3 2000/06/22 18:04:13 mdw Exp $
  *
  * Secret sharing over %$\gf(2^8)$%
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: gfshare.c,v $
+ * Revision 1.3  2000/06/22 18:04:13  mdw
+ * Improve secret reconstruction -- compute coefficients as needed rather
+ * than making a big array of them.
+ *
  * Revision 1.2  2000/06/18 23:12:15  mdw
  * Change typesetting of Galois Field names.
  *
@@ -43,6 +47,7 @@
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <mLib/alloc.h>
 #include <mLib/bits.h>
@@ -222,18 +227,20 @@ unsigned gfshare_add(gfshare *s, unsigned x, const octet *y)
 void gfshare_combine(gfshare *s, octet *buf)
 {
   unsigned i, j;
-  octet *v;
 
   /* --- Sanity checking --- */
 
   assert(((void)"Not enough shares yet", s->i == s->t));
 
-  /* --- Precomputation of coefficients --- */
+  /* --- Grind through the shares --- */
 
-  v = XS_ALLOC(s->t);
+  memset(buf, 0, s->sz);
 
   for (i = 0; i < s->t; i++) {
     unsigned c = 0, ci = 0;
+
+    /* --- Compute the magic coefficient --- */
+
     for (j = 0; j < s->t; j++) {
       if (i == j)
        continue;
@@ -247,21 +254,14 @@ void gfshare_combine(gfshare *s, octet *buf)
     if (ci > c)
       c += 0xff;
     c -= ci;
-    v[i] = c;
-  }
 
-  /* --- Grind through the shares --- */
+    /* --- Work out another layer of the secret --- */
 
-  for (i = 0; i < s->sz; i++) {
-    unsigned x = 0;
-    for (j = 0; j < s->t; j++) {
-      if (s->v[j].y[i])
-       x ^= gfexp[v[j] + gflog[s->v[j].y[i]]];
+    for (j = 0; j < s->sz; j++) {
+      if (s->v[i].y[j])
+       buf[j] ^= gfexp[c + gflog[s->v[i].y[j]]];
     }
-    buf[i] = x;
   }
-
-  XS_FREE(v);
 }
 
 /*----- Test rig ----------------------------------------------------------*/