From 5d4fee2a9d2ecf4d2566c0deca27e1878bf2380f Mon Sep 17 00:00:00 2001 From: mdw Date: Wed, 6 Dec 2000 20:30:10 +0000 Subject: [PATCH] Change secret sharing interface: present the secret at share construction time. --- gfshare.c | 23 +++++++++++++---------- gfshare.h | 21 +++++++++++++-------- share.c | 30 +++++++++++++++--------------- share.h | 22 +++++++++++++--------- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/gfshare.c b/gfshare.c index 7854f7d..09d3e89 100644 --- a/gfshare.c +++ b/gfshare.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: gfshare.c,v 1.5 2000/06/24 19:11:47 mdw Exp $ + * $Id: gfshare.c,v 1.6 2000/12/06 20:30:10 mdw Exp $ * * Secret sharing over %$\gf(2^8)$% * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: gfshare.c,v $ + * Revision 1.6 2000/12/06 20:30:10 mdw + * Change secret sharing interface: present the secret at share + * construction time. + * * Revision 1.5 2000/06/24 19:11:47 mdw * Fix daft error in the comment for @gfshare_get@. * @@ -86,7 +90,6 @@ void gfshare_create(gfshare *s, unsigned t, size_t sz) s->t = t; s->i = 0; s->sz = sz; - s->s = 0; s->v = 0; } @@ -111,22 +114,23 @@ void gfshare_destroy(gfshare *s) * * Arguments: @gfshare *s@ = pointer to share context to fill in * @grand *r@ = pointer to random number source + * @const void *buf@ = pointer to the secret to share * * Returns: --- * * Use: Initializes a sharing context to be able to create shares. * The context structure is expected to be mostly filled in. In - * particular, @t@ and @s@ must be initialized. If @v@ is zero, - * a vector of appropriate size is allocated. You should use - * the macro @GFSHARE_INIT@ or @gfshare_create@ to construct - * sharing contexts. + * particular, @t@ must be initialized. If @v@ is zero, a + * vector of appropriate size is allocated. You should use the + * macro @GFSHARE_INIT@ or @gfshare_create@ to construct sharing + * contexts. */ -void gfshare_mkshares(gfshare *s, grand *r) +void gfshare_mkshares(gfshare *s, grand *r, const void *buf) { s->v = XS_ALLOC(s->sz * s->t); r->ops->fill(r, s->v, s->sz * (s->t - 1)); - memcpy(s->v + s->sz * (s->t - 1), s->s, s->sz); + memcpy(s->v + s->sz * (s->t - 1), buf, s->sz); } /* --- @gfshare_get@ --- * @@ -290,9 +294,8 @@ static int verify(grand *r) r->ops->fill(r, sec, len); gfshare_create(&s, t, len); - s.s = sec; - gfshare_mkshares(&s, r); + gfshare_mkshares(&s, r, sec); for (i = 0; i < t; i++) gfshare_get(&s, p[i], v + (i * len)); gfshare_destroy(&s); diff --git a/gfshare.h b/gfshare.h index 2d0f73e..fe09d8a 100644 --- a/gfshare.h +++ b/gfshare.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: gfshare.h,v 1.5 2000/06/24 19:11:47 mdw Exp $ + * $Id: gfshare.h,v 1.6 2000/12/06 20:30:10 mdw Exp $ * * Secret sharing over %$\gf{2^8}$% * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: gfshare.h,v $ + * Revision 1.6 2000/12/06 20:30:10 mdw + * Change secret sharing interface: present the secret at share + * construction time. + * * Revision 1.5 2000/06/24 19:11:47 mdw * Fix daft error in the comment for @gfshare_get@. * @@ -88,11 +92,10 @@ typedef struct gfshare { unsigned t; /* Threshold */ unsigned i; /* Next free slot in vector */ size_t sz; /* Size of the secret and shares */ - void *s; /* The secret */ octet *v; /* Vector of share information */ } gfshare; -#define GFSHARE_INIT(t, sz) { t, 0, sz, 0, 0 } +#define GFSHARE_INIT(t, sz) { t, 0, sz, 0 } /*----- Functions provided ------------------------------------------------*/ @@ -126,18 +129,20 @@ extern void gfshare_destroy(gfshare */*s*/); * * Arguments: @gfshare *s@ = pointer to share context to fill in * @grand *r@ = pointer to random number source + * @const void *buf@ = pointer to the secret to share * * Returns: --- * * Use: Initializes a sharing context to be able to create shares. * The context structure is expected to be mostly filled in. In - * particular, @t@ and @s@ must be initialized. If @v@ is zero, - * a vector of appropriate size is allocated. You should use - * the macro @GFSHARE_INIT@ or @gfshare_create@ to construct - * sharing contexts. + * particular, @t@ must be initialized. If @v@ is zero, a + * vector of appropriate size is allocated. You should use the + * macro @GFSHARE_INIT@ or @gfshare_create@ to construct sharing + * contexts. */ -extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/); +extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/, + const void */*buf*/); /* --- @gfshare_get@ --- * * diff --git a/share.c b/share.c index 4f5942e..cc793db 100644 --- a/share.c +++ b/share.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: share.c,v 1.4 2000/10/08 12:16:17 mdw Exp $ + * $Id: share.c,v 1.5 2000/12/06 20:30:10 mdw Exp $ * * Shamir's secret sharing * @@ -30,6 +30,10 @@ /*----- 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@. * @@ -77,7 +81,6 @@ void share_create(share *s, unsigned t) { s->t = t; s->i = 0; - s->s = 0; s->p = 0; s->v = 0; } @@ -110,27 +113,26 @@ void share_destroy(share *s) if (s->p) mp_drop(s->p); - if (s->s) - mp_drop(s->s); } /* --- @share_mkshares@ --- * * * Arguments: @share *s@ = pointer to share context to fill in * @grand *r@ = pointer to random number source + * @mp *n@ = the secret to share * * Returns: --- * * Use: Initializes a sharing context to be able to create shares. * The context structure is expected to be mostly filled in. In - * particular, @t@ and @s@ must be initialized. If @p@ is zero, - * a prime number of appropriate size is generated - * automatically. If @v@ is zero, a vector of appropriate size - * is allocated. You should use the macro @SHARE_INIT@ or - * @share_create@ to construct sharing contexts. + * particular, @t@ must be initialized. If @p@ is zero, a prime + * number of appropriate size is generated automatically. If + * @v@ is zero, a vector of appropriate size is allocated. You + * should use the macro @SHARE_INIT@ or @share_create@ to + * construct sharing contexts. */ -void share_mkshares(share *s, grand *r) +void share_mkshares(share *s, grand *r, mp *n) { unsigned i; @@ -140,7 +142,7 @@ void share_mkshares(share *s, grand *r) pgen_filterctx pf; rabin pr; mp *p; - unsigned bits = (mp_octets(s->s) + 1) * 8; + unsigned bits = (mp_octets(n) + 1) * 8; pf.step = 2; p = mprand(MP_NEW, bits, r, 1); @@ -154,7 +156,7 @@ void share_mkshares(share *s, grand *r) s->v = xmalloc(s->t * sizeof(share_pt)); for (i = 0; i < s->t - 1; i++) s->v[i].y = mprand_range(MP_NEWSEC, s->p, r, 0); - s->v[s->t - 1].y = mp_copy(s->s); + s->v[s->t - 1].y = mp_copy(n); } /* --- @share_get@ --- * @@ -291,7 +293,6 @@ mp *share_combine(share *s) } a = mpbarrett_reduce(&mb, a, a); - s->s = mp_copy(a); if (m) mp_drop(m); mpbarrett_destroy(&mb); @@ -330,8 +331,7 @@ static int verify(grand *r) } share_create(&s, t); - s.s = mp_copy(sec); - share_mkshares(&s, r); + share_mkshares(&s, r, sec); for (i = 0; i < t; i++) v[i] = share_get(&s, MP_NEW, p[i]); pp = mp_copy(s.p); diff --git a/share.h b/share.h index 813c524..a875e06 100644 --- a/share.h +++ b/share.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: share.h,v 1.2 2000/06/24 18:29:05 mdw Exp $ + * $Id: share.h,v 1.3 2000/12/06 20:30:10 mdw Exp $ * * Shamir's secret sharing * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: share.h,v $ + * Revision 1.3 2000/12/06 20:30:10 mdw + * Change secret sharing interface: present the secret at share + * construction time. + * * Revision 1.2 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. @@ -80,12 +84,11 @@ typedef struct share_pt { typedef struct share { unsigned t; /* Threshold */ unsigned i; /* Next free slot in the vector */ - mp *s; /* The secret */ mp *p; /* Modulus for arithmetic */ share_pt *v; /* Vector of share information */ } share; -#define SHARE_INIT(t) { t, 0, 0, 0, 0 } +#define SHARE_INIT(t) { t, 0, 0, 0 } /*----- Functions provided ------------------------------------------------*/ @@ -117,19 +120,20 @@ extern void share_destroy(share */*s*/); * * Arguments: @share *s@ = pointer to share context to fill in * @grand *r@ = pointer to random number source + * @mp *n@ = the secret to share * * Returns: --- * * Use: Initializes a sharing context to be able to create shares. * The context structure is expected to be mostly filled in. In - * particular, @t@ and @s@ must be initialized. If @p@ is zero, - * a prime number of appropriate size is generated - * automatically. If @v@ is zero, a vector of appropriate size - * is allocated. You should use the macro @SHARE_INIT@ or - * @share_create@ to construct sharing contexts. + * particular, @t@ must be initialized. If @p@ is zero, a prime + * number of appropriate size is generated automatically. If + * @v@ is zero, a vector of appropriate size is allocated. You + * should use the macro @SHARE_INIT@ or @share_create@ to + * construct sharing contexts. */ -extern void share_mkshares(share */*s*/, grand */*r*/); +extern void share_mkshares(share */*s*/, grand */*r*/, mp */*n*/); /* --- @share_get@ --- * * -- 2.11.0