/* -*-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.
*
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include <mLib/alloc.h>
#include <mLib/bits.h>
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;
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 ----------------------------------------------------------*/