Fast but nonstandard secret sharing system.
[u/mdw/catacomb] / gfshare.h
CommitLineData
6c1035f5 1/* -*-c-*-
2 *
3 * $Id: gfshare.h,v 1.1 2000/06/17 10:56:30 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.1 2000/06/17 10:56:30 mdw
34 * Fast but nonstandard secret sharing system.
35 *
36 */
37
38#ifndef CATACOMB_GFSHARE_H
39#define CATACOMB_GFSHARE_H
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
45/*----- Header files ------------------------------------------------------*/
46
47#include <mLib/bits.h>
48
49#ifndef CATACOMB_GRAND_H
50# include "grand.h"
51#endif
52
53/*----- Data structures ---------------------------------------------------*/
54
55/* --- A secret sharing context --- */
56
57typedef struct gfshare_pt {
58 octet x; /* %$x$%-coordinate of the share */
59 octet *y; /* Pointer to share payload */
60} gfshare_pt;
61
62typedef struct gfshare {
63 unsigned t; /* Threshold */
64 unsigned n; /* The number of shares to make */
65 unsigned i; /* Next free slot in vector */
66 size_t sz; /* Size of the secret and shares */
67 octet *s; /* The secret */
68 gfshare_pt *v; /* Vector of share information */
69} gfshare;
70
71#define GFSHARE_INIT(t, n, sz) { t, n, 0, sz, 0, 0 }
72
73/*----- Functions provided ------------------------------------------------*/
74
75/* --- @gfshare_create@ --- *
76 *
77 * Arguments: @gfshare *s@ = pointer to share context to initialize
78 * @unsigned t, n@ = threshold parameters for the system
79 * @size_t sz@ = size of the secret
80 *
81 * Returns: ---
82 *
83 * Use: Initializes a sharing context.
84 */
85
86extern void gfshare_create(gfshare */*s*/, unsigned /*t*/, unsigned /*n*/,
87 size_t /*sz*/);
88
89/* --- @gfshare_destroy@ --- *
90 *
91 * Arguments: @gfshare *s@ = pointer to share context to destroy
92 *
93 * Returns: ---
94 *
95 * Use: Disposes of a sharing context. The allocations for the
96 * individual shares and the vector @v@ are freed; the secret is
97 * left alone.
98 */
99
100extern void gfshare_destroy(gfshare */*s*/);
101
102/* --- @gfshare_mkshares@ --- *
103 *
104 * Arguments: @gfshare *s@ = pointer to share context to fill in
105 * @grand *r@ = pointer to random number source
106 *
107 * Returns: ---
108 *
109 * Use: Generates @c->n@ secret shares, such that any @c->t@ of them
110 * may be used to recover the secret.
111 *
112 * The context structure is expected to be mostly filled in. In
113 * particular, @t@, @n@, @ssz@ and @s@ must be initialized. If
114 * @v@ is zero, a vector of appropriate size is allocated. You
115 * should use the macro @GFSHARE_INIT@ or @gfshare_create@ to
116 * construct sharing contexts.
117 */
118
119extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/);
120
121/* --- @gfshare_add@ --- *
122 *
123 * Arguments: @gfshare *s@ = pointer to sharing context
124 * @unsigned x@ = which share number this is
125 * @const octet *y@ = the share value
126 *
127 * Returns: Number of shares required before recovery may be performed.
128 *
129 * Use: Adds a share to the context. The context must have been
130 * initialized with the correct threshold @t@.
131 */
132
133extern unsigned gfshare_add(gfshare */*s*/,
134 unsigned /*x*/, const octet */*y*/);
135
136/* --- @gfshare_combine@ --- *
137 *
138 * Arguments: @gfshare *s@ = pointer to share context
139 * @octet *buf@ = pointer to output buffer for the secret
140 *
141 * Returns: ---
142 *
143 * Use: Reconstructs a secret, given enough shares.
144 */
145
146extern void gfshare_combine(gfshare */*s*/, octet */*buf*/);
147
148/*----- That's all, folks -------------------------------------------------*/
149
150#ifdef __cplusplus
151 }
152#endif
153
154#endif