X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b817bfc642225b8c3c0b6a7e42d1fb949b61a606..80be023065ced106a4078a36371c135a60d2bd6c:/share.c diff --git a/share.c b/share.c index 23d730c..55f3b98 100644 --- a/share.c +++ b/share.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: share.c,v 1.7 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Shamir's secret sharing * @@ -172,6 +172,26 @@ mp *share_get(share *s, mp *d, unsigned x) return (d); } +/* --- @share_addedp@ --- * + * + * Arguments: @share *s@ = pointer to sharing context + * @unsigned x@ = which share number to check + * + * Returns: Nonzero if share @x@ has been added already, zero if it + * hasn't. + */ + +int share_addedp(share *s, unsigned x) +{ + unsigned i; + + for (i = 0; i < s->i; i++) { + if (s->v[i].x == x + 1) + return (1); + } + return (0); +} + /* --- @share_add@ --- * * * Arguments: @share *s@ = pointer to sharing context @@ -186,6 +206,9 @@ mp *share_get(share *s, mp *d, unsigned x) unsigned share_add(share *s, unsigned x, mp *y) { + assert(((void)"Share context is full", s->i < s->t)); + assert(((void)"Share already present", !share_addedp(s, x))); + /* --- If no vector has been allocated, create one --- */ if (!s->v) { @@ -196,8 +219,6 @@ unsigned share_add(share *s, unsigned x, mp *y) s->v[i].y = 0; } - assert(((void)"Share context is full", s->i < s->t)); - /* --- Store the share in the vector --- */ s->v[s->i].x = x + 1;