Fast but nonstandard secret sharing system.
[u/mdw/catacomb] / gfshare.h
diff --git a/gfshare.h b/gfshare.h
new file mode 100644 (file)
index 0000000..b0aca05
--- /dev/null
+++ b/gfshare.h
@@ -0,0 +1,154 @@
+/* -*-c-*-
+ *
+ * $Id: gfshare.h,v 1.1 2000/06/17 10:56:30 mdw Exp $
+ *
+ * Secret sharing over %$\gf(2^8)$%
+ *
+ * (c) 2000 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: gfshare.h,v $
+ * Revision 1.1  2000/06/17 10:56:30  mdw
+ * Fast but nonstandard secret sharing system.
+ *
+ */
+
+#ifndef CATACOMB_GFSHARE_H
+#define CATACOMB_GFSHARE_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <mLib/bits.h>
+
+#ifndef CATACOMB_GRAND_H
+#  include "grand.h"
+#endif
+
+/*----- Data structures ---------------------------------------------------*/
+
+/* --- A secret sharing context --- */
+
+typedef struct gfshare_pt {
+  octet x;                             /* %$x$%-coordinate of the share */
+  octet *y;                            /* Pointer to share payload */
+} gfshare_pt;
+
+typedef struct gfshare {
+  unsigned t;                          /* Threshold */
+  unsigned n;                          /* The number of shares to make */
+  unsigned i;                          /* Next free slot in vector */
+  size_t sz;                           /* Size of the secret and shares */
+  octet *s;                            /* The secret */
+  gfshare_pt *v;                       /* Vector of share information */
+} gfshare;
+
+#define GFSHARE_INIT(t, n, sz) { t, n, 0, sz, 0, 0 }
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @gfshare_create@ --- *
+ *
+ * Arguments:  @gfshare *s@ = pointer to share context to initialize
+ *             @unsigned t, n@ = threshold parameters for the system
+ *             @size_t sz@ = size of the secret
+ *
+ * Returns:    ---
+ *
+ * Use:                Initializes a sharing context.
+ */
+
+extern void gfshare_create(gfshare */*s*/, unsigned /*t*/, unsigned /*n*/,
+                          size_t /*sz*/);
+
+/* --- @gfshare_destroy@ --- *
+ *
+ * Arguments:  @gfshare *s@ = pointer to share context to destroy
+ *
+ * Returns:    ---
+ *
+ * Use:                Disposes of a sharing context.  The allocations for the
+ *             individual shares and the vector @v@ are freed; the secret is
+ *             left alone.
+ */
+
+extern void gfshare_destroy(gfshare */*s*/);
+
+/* --- @gfshare_mkshares@ --- *
+ *
+ * Arguments:  @gfshare *s@ = pointer to share context to fill in
+ *             @grand *r@ = pointer to random number source
+ *
+ * Returns:    ---
+ *
+ * Use:                Generates @c->n@ secret shares, such that any @c->t@ of them
+ *             may be used to recover the secret.
+ *
+ *             The context structure is expected to be mostly filled in.  In
+ *             particular, @t@, @n@, @ssz@ and @s@ must be initialized.  If
+ *             @v@ is zero, a vector of appropriate size is allocated.  You
+ *             should use the macro @GFSHARE_INIT@ or @gfshare_create@ to
+ *             construct sharing contexts.
+ */
+
+extern void gfshare_mkshares(gfshare */*s*/, grand */*r*/);
+
+/* --- @gfshare_add@ --- *
+ *
+ * Arguments:  @gfshare *s@ = pointer to sharing context
+ *             @unsigned x@ = which share number this is
+ *             @const octet *y@ = the share value
+ *
+ * Returns:    Number of shares required before recovery may be performed.
+ *
+ * Use:                Adds a share to the context.  The context must have been
+ *             initialized with the correct threshold @t@.
+ */
+
+extern unsigned gfshare_add(gfshare */*s*/,
+                           unsigned /*x*/, const octet */*y*/);
+
+/* --- @gfshare_combine@ --- *
+ *
+ * Arguments:  @gfshare *s@ = pointer to share context
+ *             @octet *buf@ = pointer to output buffer for the secret
+ *
+ * Returns:    ---
+ *
+ * Use:                Reconstructs a secret, given enough shares.
+ */
+
+extern void gfshare_combine(gfshare */*s*/, octet */*buf*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif