X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/6c1035f55a83af8083af17432f2b4eb5afdb39dd..31cb4e2ef91d4ab2a6cc2d5fea5ac790be8f3801:/gfshare.c diff --git a/gfshare.c b/gfshare.c index cdc00d2..a0b102d 100644 --- a/gfshare.c +++ b/gfshare.c @@ -1,8 +1,8 @@ /* -*-c-*- * - * $Id: gfshare.c,v 1.1 2000/06/17 10:56:30 mdw Exp $ + * $Id: gfshare.c,v 1.3 2000/06/22 18:04:13 mdw Exp $ * - * Secret sharing over %$gf(2^8)$% + * Secret sharing over %$\gf(2^8)$% * * (c) 2000 Straylight/Edgeware */ @@ -30,6 +30,13 @@ /*----- 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. + * * Revision 1.1 2000/06/17 10:56:30 mdw * Fast but nonstandard secret sharing system. * @@ -40,6 +47,7 @@ #include #include #include +#include #include #include @@ -219,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; @@ -244,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 ----------------------------------------------------------*/