From cb06abce90401baa11a89747170668173ffb6010 Mon Sep 17 00:00:00 2001 From: mdw Date: Thu, 22 Jun 2000 18:04:13 +0000 Subject: [PATCH] Improve secret reconstruction -- compute coefficients as needed rather than making a big array of them. --- gfshare.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gfshare.c b/gfshare.c index bbb0aee..a0b102d 100644 --- 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)$% * @@ -30,6 +30,10 @@ /*----- 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 #include #include +#include #include #include @@ -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 ----------------------------------------------------------*/ -- 2.11.0