3 * $Id: share.h,v 1.3 2000/12/06 20:30:10 mdw Exp $
5 * Shamir's secret sharing
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.3 2000/12/06 20:30:10 mdw
34 * Change secret sharing interface: present the secret at share
37 * Revision 1.2 2000/06/24 18:29:05 mdw
38 * Interface change: allow shares to be extracted from a context on demand,
39 * rather than building them all up-front.
41 * Revision 1.1 2000/06/17 12:09:38 mdw
42 * Shamir's secret sharing system.
46 /*----- Notes on the sharing system ---------------------------------------*
48 * Shamir's secret-sharing system is based on polynomial interpolation modulo
49 * a prime number. It is `perfect' in that fewer participants than the
50 * threshold can derive no information about the secret by pooling their
51 * shares, and `ideal' in that the shares are the same size as the secret.
53 * This implementation stays close to the definition, in order to support
54 * other schemes for (e.g.) threshold cryptography. It is, however, rather
58 #ifndef CATACOMB_SHARE_H
59 #define CATACOMB_SHARE_H
65 /*----- Header files ------------------------------------------------------*/
67 #ifndef CATACOMB_GRAND_H
75 /*----- Data structures ---------------------------------------------------*/
77 /* --- A secret sharing context --- */
79 typedef struct share_pt
{
80 unsigned x
; /* Index of this share */
81 mp
*y
; /* Payload of this share */
84 typedef struct share
{
85 unsigned t
; /* Threshold */
86 unsigned i
; /* Next free slot in the vector */
87 mp
*p
; /* Modulus for arithmetic */
88 share_pt
*v
; /* Vector of share information */
91 #define SHARE_INIT(t) { t, 0, 0, 0 }
93 /*----- Functions provided ------------------------------------------------*/
95 /* --- @share_create@ --- *
97 * Arguments: @share *s@ = pointer to share context to initialize
98 * @unsigned t@ = threshold for the system
102 * Use: Initializes a sharing context.
105 extern void share_create(share */
*s*/
, unsigned /*t*/);
107 /* --- @share_destroy@ --- *
109 * Arguments: @share *s@ = pointer to share context to destroy
113 * Use: Disposes of a sharing context. All memory is freed, all
114 * integers are dropped.
117 extern void share_destroy(share */
*s*/
);
119 /* --- @share_mkshares@ --- *
121 * Arguments: @share *s@ = pointer to share context to fill in
122 * @grand *r@ = pointer to random number source
123 * @mp *n@ = the secret to share
127 * Use: Initializes a sharing context to be able to create shares.
128 * The context structure is expected to be mostly filled in. In
129 * particular, @t@ must be initialized. If @p@ is zero, a prime
130 * number of appropriate size is generated automatically. If
131 * @v@ is zero, a vector of appropriate size is allocated. You
132 * should use the macro @SHARE_INIT@ or @share_create@ to
133 * construct sharing contexts.
136 extern void share_mkshares(share */
*s*/
, grand */
*r*/
, mp */
*n*/
);
138 /* --- @share_get@ --- *
140 * Arguments: @share *s@ = pointer to share conext
141 * @mp *d@ = destination for the share
142 * @unsigned x@ = share index to fetch
144 * Returns: The share, as requested.
146 * Use: Extracts a share from the system. You may extract @MPW_MAX@
147 * shares, or @s->p@ shares from the system, whichever is
148 * smaller. Shares are indexed from 0.
151 extern mp
*share_get(share */
*s*/
, mp */
*d*/
, unsigned /*x*/);
153 /* --- @share_add@ --- *
155 * Arguments: @share *s@ = pointer to sharing context
156 * @unsigned x@ = which share number this is
157 * @mp *y@ = the share value
159 * Returns: Number of shares required before recovery may be performed.
161 * Use: Adds a share to the context. The context must have been
162 * initialized with the correct prime @p@ and threshold @t@.
165 extern unsigned share_add(share */
*s*/
, unsigned /*x*/, mp */
*y*/
);
167 /* --- @share_combine@ --- *
169 * Arguments: @share *s@ = pointer to share context
171 * Returns: The secret, as a multiprecision integer.
173 * Use: Reconstructs a secret, given enough shares.
176 extern mp
*share_combine(share */
*s*/
);
178 /*----- That's all, folks -------------------------------------------------*/