Renamed from `rsa-decrypt', since the name was no longer appropriate.
[u/mdw/catacomb] / gfshare.h
1 /* -*-c-*-
2 *
3 * $Id: gfshare.h,v 1.5 2000/06/24 19:11:47 mdw Exp $
4 *
5 * Secret sharing over %$\gf{2^8}$%
6 *
7 * (c) 2000 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: gfshare.h,v $
33 * Revision 1.5 2000/06/24 19:11:47 mdw
34 * Fix daft error in the comment for @gfshare_get@.
35 *
36 * Revision 1.4 2000/06/24 18:29:05 mdw
37 * Interface change: allow shares to be extracted from a context on demand,
38 * rather than building them all up-front.
39 *
40 * Revision 1.3 2000/06/18 23:12:15 mdw
41 * Change typesetting of Galois Field names.
42 *
43 * Revision 1.2 2000/06/17 11:05:27 mdw
44 * Add a commentary on the system.
45 *
46 * Revision 1.1 2000/06/17 10:56:30 mdw
47 * Fast but nonstandard secret sharing system.
48 *
49 */
50
51 /*----- Notes on the system -----------------------------------------------*
52 *
53 * This uses a variant of Shamir's secret sharing system. Shamir's original
54 * system used polynomials modulo a large prime. This implementation instead
55 * uses the field %$\gf{2^8}$%, represented by
56 *
57 * %$\gf{2}[x]/(x^8 + x^4 + x^3 + x^2 + 1)$%
58 *
59 * and shares each byte of the secret independently. It is therefore limited
60 * to 255 players, although this probably isn't a serious limitation in
61 * practice.
62 *
63 * Share creation and reconstruction is extremely efficient. Contrast the
64 * performance of the straightforward implementation based on multiprecision
65 * arithmetic.
66 */
67
68 #ifndef CATACOMB_GFSHARE_H
69 #define CATACOMB_GFSHARE_H
70
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74
75 /*----- Header files ------------------------------------------------------*/
76
77 #include <mLib/bits.h>
78
79 #ifndef CATACOMB_GRAND_H
80 # include "grand.h"
81 #endif
82
83 /*----- Data structures ---------------------------------------------------*/
84
85 /* --- A secret sharing context --- */
86
87 typedef struct gfshare {
88 unsigned t; /* Threshold */
89 unsigned i; /* Next free slot in vector */
90 size_t sz; /* Size of the secret and shares */
91 void *s; /* The secret */
92 octet *v; /* Vector of share information */
93 } gfshare;
94
95 #define GFSHARE_INIT(t, sz) { t, 0, sz, 0, 0 }
96
97 /*----- Functions provided ------------------------------------------------*/
98
99 /* --- @gfshare_create@ --- *
100 *
101 * Arguments: @gfshare *s@ = pointer to share context to initialize
102 * @unsigned t@ = threshold for the system
103 * @size_t sz@ = size of the secret
104 *
105 * Returns: ---
106 *
107 * Use: Initializes a sharing context.
108 */
109
110 extern void gfshare_create(gfshare */*s*/, unsigned /*t*/, size_t /*sz*/);
111
112 /* --- @gfshare_destroy@ --- *
113 *
114 * Arguments: @gfshare *s@ = pointer to share context to destroy
115 *
116 * Returns: ---
117 *
118 * Use: Disposes of a sharing context. The allocations for the
119 * individual shares and the vector @v@ are freed; the secret is
120 * left alone.
121 */
122
123 extern void gfshare_destroy(gfshare */*s*/);
124
125 /* --- @gfshare_mkshares@ --- *
126 *
127 * Arguments: @gfshare *s@ = pointer to share context to fill in
128 * @grand *r@ = pointer to random number source
129 *
130 * Returns: ---
131 *
132 * Use: Initializes a sharing context to be able to create shares.
133 * The context structure is expected to be mostly filled in. In
134 * particular, @t@ and @s@ must be initialized. If @v@ is zero,
135 * a vector of appropriate size is allocated. You should use
136 * the macro @GFSHARE_INIT@ or @gfshare_create@ to construct
137 * sharing contexts.
138 */
139
140 extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/);
141
142 /* --- @gfshare_get@ --- *
143 *
144 * Arguments: @gfshare *s@ = pointer to share conext
145 * @unsigned x@ = share index to fetch
146 * @void *buf@ = pointer to output buffer
147 *
148 * Returns: ---
149 *
150 * Use: Extracts a share from the system. You may extract up to 255
151 * shares from the system. Shares are indexed from 0.
152 */
153
154 extern void gfshare_get(gfshare */*s*/, unsigned /*x*/, void */*buf*/);
155
156 /* --- @gfshare_add@ --- *
157 *
158 * Arguments: @gfshare *s@ = pointer to sharing context
159 * @unsigned x@ = which share number this is
160 * @const void *y@ = the share value
161 *
162 * Returns: Number of shares required before recovery may be performed.
163 *
164 * Use: Adds a share to the context. The context must have been
165 * initialized with the correct threshold @t@.
166 */
167
168 extern unsigned gfshare_add(gfshare */*s*/,
169 unsigned /*x*/, const void */*y*/);
170
171 /* --- @gfshare_combine@ --- *
172 *
173 * Arguments: @gfshare *s@ = pointer to share context
174 * @void *buf@ = pointer to output buffer for the secret
175 *
176 * Returns: ---
177 *
178 * Use: Reconstructs a secret, given enough shares.
179 */
180
181 extern void gfshare_combine(gfshare */*s*/, void */*buf*/);
182
183 /*----- That's all, folks -------------------------------------------------*/
184
185 #ifdef __cplusplus
186 }
187 #endif
188
189 #endif