3 * $Id: share.h,v 1.1 2000/06/17 12:09:38 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.1 2000/06/17 12:09:38 mdw
34 * Shamir's secret sharing system.
38 /*----- Notes on the sharing system ---------------------------------------*
40 * Shamir's secret-sharing system is based on polynomial interpolation modulo
41 * a prime number. It is `perfect' in that fewer participants than the
42 * threshold can derive no information about the secret by pooling their
43 * shares, and `ideal' in that the shares are the same size as the secret.
45 * This implementation stays close to the definition, in order to support
46 * other schemes for (e.g.) threshold cryptography. It is, however, rather
50 #ifndef CATACOMB_SHARE_H
51 #define CATACOMB_SHARE_H
57 /*----- Header files ------------------------------------------------------*/
59 #ifndef CATACOMB_GRAND_H
67 /*----- Data structures ---------------------------------------------------*/
69 /* --- A secret sharing context --- */
71 typedef struct share_pt
{
72 unsigned x
; /* Index of this share */
73 mp
*y
; /* Payload of this share */
76 typedef struct share
{
77 unsigned t
; /* Threshold */
78 unsigned n
; /* The number of shares to make */
79 unsigned i
; /* Next free slot in the vector */
80 mp
*s
; /* The secret */
81 mp
*p
; /* Modulus for arithmetic */
82 share_pt
*v
; /* Vector of share information */
85 #define SHARE_INIT(t, n) { t, n, 0, 0, 0, 0 }
87 /*----- Functions provided ------------------------------------------------*/
89 /* --- @share_create@ --- *
91 * Arguments: @share *s@ = pointer to share context to initialize
92 * @unsigned t, n@ = threshold parameters for the system
96 * Use: Initializes a sharing context.
99 extern void share_create(share */
*s*/
, unsigned /*t*/, unsigned /*n*/);
101 /* --- @share_destroy@ --- *
103 * Arguments: @share *s@ = pointer to share context to destroy
107 * Use: Disposes of a sharing context. All memory is freed, all
108 * integers are dropped.
111 extern void share_destroy(share */
*s*/
);
113 /* --- @share_mkshares@ --- *
115 * Arguments: @share *s@ = pointer to share context to fill in
116 * @grand *r@ = pointer to random number source
120 * Use: Generates @c->n@ secret shares, such that any @c->t@ of them
121 * may be used to recover the secret.
123 * The context structure is expected to be mostly filled in. In
124 * particular, @t@, @n@ and @s@ must be initialized. If @p@ is
125 * zero, a prime number of appropriate size is generated
126 * automatically. If @v@ is zero, a vector of appropriate size
127 * is allocated. You should use the macro @SHARE_INIT@ or
128 * @share_create@ to construct sharing contexts.
131 extern void share_mkshares(share */
*s*/
, grand */
*r*/
);
133 /* --- @share_add@ --- *
135 * Arguments: @share *s@ = pointer to sharing context
136 * @unsigned x@ = which share number this is
137 * @mp *y@ = the share value
139 * Returns: Number of shares required before recovery may be performed.
141 * Use: Adds a share to the context. The context must have been
142 * initialized with the correct prime @p@ and threshold @t@.
145 extern unsigned share_add(share */
*s*/
, unsigned /*x*/, mp */
*y*/
);
147 /* --- @share_combine@ --- *
149 * Arguments: @share *s@ = pointer to share context
151 * Returns: The secret, as a multiprecision integer.
153 * Use: Reconstructs a secret, given enough shares.
156 extern mp
*share_combine(share */
*s*/
);
158 /*----- That's all, folks -------------------------------------------------*/