3 * $Id: share.h,v 1.2 2000/06/24 18:29:05 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.2 2000/06/24 18:29:05 mdw
34 * Interface change: allow shares to be extracted from a context on demand,
35 * rather than building them all up-front.
37 * Revision 1.1 2000/06/17 12:09:38 mdw
38 * Shamir's secret sharing system.
42 /*----- Notes on the sharing system ---------------------------------------*
44 * Shamir's secret-sharing system is based on polynomial interpolation modulo
45 * a prime number. It is `perfect' in that fewer participants than the
46 * threshold can derive no information about the secret by pooling their
47 * shares, and `ideal' in that the shares are the same size as the secret.
49 * This implementation stays close to the definition, in order to support
50 * other schemes for (e.g.) threshold cryptography. It is, however, rather
54 #ifndef CATACOMB_SHARE_H
55 #define CATACOMB_SHARE_H
61 /*----- Header files ------------------------------------------------------*/
63 #ifndef CATACOMB_GRAND_H
71 /*----- Data structures ---------------------------------------------------*/
73 /* --- A secret sharing context --- */
75 typedef struct share_pt
{
76 unsigned x
; /* Index of this share */
77 mp
*y
; /* Payload of this share */
80 typedef struct share
{
81 unsigned t
; /* Threshold */
82 unsigned i
; /* Next free slot in the vector */
83 mp
*s
; /* The secret */
84 mp
*p
; /* Modulus for arithmetic */
85 share_pt
*v
; /* Vector of share information */
88 #define SHARE_INIT(t) { t, 0, 0, 0, 0 }
90 /*----- Functions provided ------------------------------------------------*/
92 /* --- @share_create@ --- *
94 * Arguments: @share *s@ = pointer to share context to initialize
95 * @unsigned t@ = threshold for the system
99 * Use: Initializes a sharing context.
102 extern void share_create(share */
*s*/
, unsigned /*t*/);
104 /* --- @share_destroy@ --- *
106 * Arguments: @share *s@ = pointer to share context to destroy
110 * Use: Disposes of a sharing context. All memory is freed, all
111 * integers are dropped.
114 extern void share_destroy(share */
*s*/
);
116 /* --- @share_mkshares@ --- *
118 * Arguments: @share *s@ = pointer to share context to fill in
119 * @grand *r@ = pointer to random number source
123 * Use: Initializes a sharing context to be able to create shares.
124 * The context structure is expected to be mostly filled in. In
125 * particular, @t@ and @s@ must be initialized. If @p@ is zero,
126 * a prime number of appropriate size is generated
127 * automatically. If @v@ is zero, a vector of appropriate size
128 * is allocated. You should use the macro @SHARE_INIT@ or
129 * @share_create@ to construct sharing contexts.
132 extern void share_mkshares(share */
*s*/
, grand */
*r*/
);
134 /* --- @share_get@ --- *
136 * Arguments: @share *s@ = pointer to share conext
137 * @mp *d@ = destination for the share
138 * @unsigned x@ = share index to fetch
140 * Returns: The share, as requested.
142 * Use: Extracts a share from the system. You may extract @MPW_MAX@
143 * shares, or @s->p@ shares from the system, whichever is
144 * smaller. Shares are indexed from 0.
147 extern mp
*share_get(share */
*s*/
, mp */
*d*/
, unsigned /*x*/);
149 /* --- @share_add@ --- *
151 * Arguments: @share *s@ = pointer to sharing context
152 * @unsigned x@ = which share number this is
153 * @mp *y@ = the share value
155 * Returns: Number of shares required before recovery may be performed.
157 * Use: Adds a share to the context. The context must have been
158 * initialized with the correct prime @p@ and threshold @t@.
161 extern unsigned share_add(share */
*s*/
, unsigned /*x*/, mp */
*y*/
);
163 /* --- @share_combine@ --- *
165 * Arguments: @share *s@ = pointer to share context
167 * Returns: The secret, as a multiprecision integer.
169 * Use: Reconstructs a secret, given enough shares.
172 extern mp
*share_combine(share */
*s*/
);
174 /*----- That's all, folks -------------------------------------------------*/