6c1035f5 |
1 | /* -*-c-*- |
2 | * |
73fb671f |
3 | * $Id: gfshare.h,v 1.2 2000/06/17 11:05:27 mdw Exp $ |
6c1035f5 |
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 $ |
73fb671f |
33 | * Revision 1.2 2000/06/17 11:05:27 mdw |
34 | * Add a commentary on the system. |
35 | * |
6c1035f5 |
36 | * Revision 1.1 2000/06/17 10:56:30 mdw |
37 | * Fast but nonstandard secret sharing system. |
38 | * |
39 | */ |
40 | |
73fb671f |
41 | /*----- Notes on the system -----------------------------------------------* |
42 | * |
43 | * This uses a variant of Shamir's secret sharing system. Shamir's original |
44 | * system used polynomials modulo a large prime. This implementation instead |
45 | * uses the field %$\gf(2^8)$%, represented by |
46 | * |
47 | * %$\gf(2)[x]/(x^8 + x^4 + x^3 + x^2 + 1)$% |
48 | * |
49 | * and shares each byte of the secret independently. It is therefore limited |
50 | * to 255 players, although this probably isn't a serious limitation in |
51 | * practice. |
52 | * |
53 | * Share creation and reconstruction is extremely efficient. Contrast the |
54 | * performance of the straightforward implementation based on multiprecision |
55 | * arithmetic. |
56 | */ |
57 | |
6c1035f5 |
58 | #ifndef CATACOMB_GFSHARE_H |
59 | #define CATACOMB_GFSHARE_H |
60 | |
61 | #ifdef __cplusplus |
62 | extern "C" { |
63 | #endif |
64 | |
65 | /*----- Header files ------------------------------------------------------*/ |
66 | |
67 | #include <mLib/bits.h> |
68 | |
69 | #ifndef CATACOMB_GRAND_H |
70 | # include "grand.h" |
71 | #endif |
72 | |
73 | /*----- Data structures ---------------------------------------------------*/ |
74 | |
75 | /* --- A secret sharing context --- */ |
76 | |
77 | typedef struct gfshare_pt { |
78 | octet x; /* %$x$%-coordinate of the share */ |
79 | octet *y; /* Pointer to share payload */ |
80 | } gfshare_pt; |
81 | |
82 | typedef struct gfshare { |
83 | unsigned t; /* Threshold */ |
84 | unsigned n; /* The number of shares to make */ |
85 | unsigned i; /* Next free slot in vector */ |
86 | size_t sz; /* Size of the secret and shares */ |
87 | octet *s; /* The secret */ |
88 | gfshare_pt *v; /* Vector of share information */ |
89 | } gfshare; |
90 | |
91 | #define GFSHARE_INIT(t, n, sz) { t, n, 0, sz, 0, 0 } |
92 | |
93 | /*----- Functions provided ------------------------------------------------*/ |
94 | |
95 | /* --- @gfshare_create@ --- * |
96 | * |
97 | * Arguments: @gfshare *s@ = pointer to share context to initialize |
98 | * @unsigned t, n@ = threshold parameters for the system |
99 | * @size_t sz@ = size of the secret |
100 | * |
101 | * Returns: --- |
102 | * |
103 | * Use: Initializes a sharing context. |
104 | */ |
105 | |
106 | extern void gfshare_create(gfshare */*s*/, unsigned /*t*/, unsigned /*n*/, |
107 | size_t /*sz*/); |
108 | |
109 | /* --- @gfshare_destroy@ --- * |
110 | * |
111 | * Arguments: @gfshare *s@ = pointer to share context to destroy |
112 | * |
113 | * Returns: --- |
114 | * |
115 | * Use: Disposes of a sharing context. The allocations for the |
116 | * individual shares and the vector @v@ are freed; the secret is |
117 | * left alone. |
118 | */ |
119 | |
120 | extern void gfshare_destroy(gfshare */*s*/); |
121 | |
122 | /* --- @gfshare_mkshares@ --- * |
123 | * |
124 | * Arguments: @gfshare *s@ = pointer to share context to fill in |
125 | * @grand *r@ = pointer to random number source |
126 | * |
127 | * Returns: --- |
128 | * |
129 | * Use: Generates @c->n@ secret shares, such that any @c->t@ of them |
130 | * may be used to recover the secret. |
131 | * |
132 | * The context structure is expected to be mostly filled in. In |
133 | * particular, @t@, @n@, @ssz@ and @s@ must be initialized. If |
134 | * @v@ is zero, a vector of appropriate size is allocated. You |
135 | * should use the macro @GFSHARE_INIT@ or @gfshare_create@ to |
136 | * construct sharing contexts. |
137 | */ |
138 | |
139 | extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/); |
140 | |
141 | /* --- @gfshare_add@ --- * |
142 | * |
143 | * Arguments: @gfshare *s@ = pointer to sharing context |
144 | * @unsigned x@ = which share number this is |
145 | * @const octet *y@ = the share value |
146 | * |
147 | * Returns: Number of shares required before recovery may be performed. |
148 | * |
149 | * Use: Adds a share to the context. The context must have been |
150 | * initialized with the correct threshold @t@. |
151 | */ |
152 | |
153 | extern unsigned gfshare_add(gfshare */*s*/, |
154 | unsigned /*x*/, const octet */*y*/); |
155 | |
156 | /* --- @gfshare_combine@ --- * |
157 | * |
158 | * Arguments: @gfshare *s@ = pointer to share context |
159 | * @octet *buf@ = pointer to output buffer for the secret |
160 | * |
161 | * Returns: --- |
162 | * |
163 | * Use: Reconstructs a secret, given enough shares. |
164 | */ |
165 | |
166 | extern void gfshare_combine(gfshare */*s*/, octet */*buf*/); |
167 | |
168 | /*----- That's all, folks -------------------------------------------------*/ |
169 | |
170 | #ifdef __cplusplus |
171 | } |
172 | #endif |
173 | |
174 | #endif |