Pollard's rho algorithm for computing discrete logs.
[u/mdw/catacomb] / bbs.h
diff --git a/bbs.h b/bbs.h
index 851dcb8..7217f65 100644 (file)
--- a/bbs.h
+++ b/bbs.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: bbs.h,v 1.1 1999/12/10 23:14:59 mdw Exp $
+ * $Id: bbs.h,v 1.5 2000/07/01 11:20:24 mdw Exp $
  *
  * The Blum-Blum-Shub random bit generator
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: bbs.h,v $
+ * Revision 1.5  2000/07/01 11:20:24  mdw
+ * New functions for freeing public and private keys.  Remove bad type name
+ * `bbs_param'.
+ *
+ * Revision 1.4  2000/06/17 10:45:48  mdw
+ * Minor changes for key fetching.  Typesetting fixes.
+ *
+ * Revision 1.3  2000/02/12 18:21:02  mdw
+ * Overhaul of key management (again).
+ *
+ * Revision 1.2  1999/12/22 15:52:08  mdw
+ * Rename `bbs_params' to `bbs_param' for consistency.
+ *
  * Revision 1.1  1999/12/10 23:14:59  mdw
  * Blum-Blum-Shub generator, and Blum-Goldwasser encryption.
  *
  * sequence %$x_i = x_{i - 1}^2 \bmod n$%, where %$n = pq$% is the product of
  * two primes %$p$% and %$q$%, each of which are congruent to %$3 \bmod 4$%.
  * For maximum period of the generator, %$(p - 1)/2$% and %$(q - 1)/1$%
- * should be coprime.  It is safe to use the least significant %$\log \log
- * n$% bits of each step in the sequence -- an adversary must factor the
- * modulus before being able to work forwards or backwards.  The output of
- * the generator cannot be distinguished from a (uniform, independent) random
- * sequence of bits using any polynomial-time test.  This is by far the
- * strongest pseudorandom number generator provided in Catacomb, and by far
- * the slowest too.  For normal use, the standard Catacomb @rand@ generator
- * should be more than adequate.
+ * should be coprime.  It is safe to use the least significant
+ * %$\log \log n$% bits of each step in the sequence -- an adversary must
+ * factor the modulus before being able to work forwards or backwards.  The
+ * output of the generator cannot be distinguished from a (uniform,
+ * independent) random sequence of bits using any polynomial-time test.  This
+ * is by far the strongest pseudorandom number generator provided in
+ * Catacomb, and by far the slowest too.  For normal use, the standard
+ * Catacomb @rand@ generator should be more than adequate.
  */
 
 #ifndef CATACOMB_BBS_H
 #  include "grand.h"
 #endif
 
+#ifndef CATACOMB_KEY_H
+#  include "key.h"
+#endif
+
 #ifndef CATACOMB_MP_H
 #  include "mp.h"
 #endif
 #  include "mpbarrett.h"
 #endif
 
+#ifndef CATACOMB_PGEN_H
+#  include "pgen.h"
+#endif
+
 /*----- Data structures ---------------------------------------------------*/
 
 /* --- Basic generator state --- */
@@ -88,28 +109,34 @@ typedef struct bbs {
 
 /* --- Parameters --- */
 
-typedef struct bbs_params {
+typedef struct bbs_pub {
+  mp *n;
+} bbs_pub;
+
+typedef struct bbs_priv {
   mp *p, *q;                           /* Prime factors (3 mod 4) */
   mp *n;                               /* Product @pq@ -- a Blum integer */
-} bbs_params;
+} bbs_priv;
 
-/*----- Event codes from @bbs_gen@ ----------------------------------------*/
+/*----- Key fetching ------------------------------------------------------*/
 
-enum {
-  BBSEV_OK,
+extern const key_fetchdef bbs_pubfetch[];
+#define BBS_PUBFETCHSZ 3
 
-  BBSEV_FINDP,
-  BBSEV_TRYP,
-  BBSEV_PASSP,
-  BBSEV_FAILP,
-  BBSEV_GOODP,
+extern const key_fetchdef bbs_privfetch[];
+#define BBS_PRIVFETCHSZ 7
+
+/* --- @bbs_pubfree@, @bbs_privfree@ --- *
+ *
+ * Arguments:  @bbs_pub *bp@, @bbs_priv *bp@ = pointer to key block
+ *
+ * Returns:    ---
+ *
+ * Use:                Frees a BBS key block.
+ */
 
-  BBSEV_FINDQ,
-  BBSEV_TRYQ,
-  BBSEV_PASSQ,
-  BBSEV_FAILQ,
-  BBSEV_GOODQ
-};  
+extern void bbs_pubfree(bbs_pub */*bp*/);
+extern void bbs_privfree(bbs_priv */*bp*/);
 
 /*----- The basic generator -----------------------------------------------*/
 
@@ -200,7 +227,7 @@ extern uint32 bbs_bits(bbs */*b*/, unsigned /*bits*/);
  *
  *             If a generator is seeded, %$b$% bits are extracted, and then
  *             @bbs_wrap@ is called, the generator will have been stepped
- *             %$\lceil b/k \rceil% times.
+ *             %$\lceil b/k \rceil$% times.
  */
 
 extern void bbs_wrap(bbs */*b*/);
@@ -210,7 +237,7 @@ extern void bbs_wrap(bbs */*b*/);
 /* --- @bbs_ff@ --- *
  *
  * Arguments:  @bbs *b@ = pointer to a BBS generator state
- *             @bbs_params *bp@ = pointer to BBS modulus factors
+ *             @bbs_priv *bp@ = pointer to BBS modulus factors
  *             @unsigned long n@ = number of steps to make
  *
  * Returns:    ---
@@ -220,12 +247,12 @@ extern void bbs_wrap(bbs */*b*/);
  *             efficiently.
  */
 
-extern void bbs_ff(bbs */*b*/, bbs_params */*bp*/, unsigned long /*n*/);
+extern void bbs_ff(bbs */*b*/, bbs_priv */*bp*/, unsigned long /*n*/);
 
 /* --- @bbs_rew@ --- *
  *
  * Arguments:  @bbs *b@ = pointer to a BBS generator state
- *             @bbs_params *bp@ = pointer to BBS modulus factors
+ *             @bbs_priv *bp@ = pointer to BBS modulus factors
  *             @unsigned long n@ = number of steps to make
  *
  * Returns:    ---
@@ -235,20 +262,20 @@ extern void bbs_ff(bbs */*b*/, bbs_params */*bp*/, unsigned long /*n*/);
  *             at all.
  */
 
-extern void bbs_rew(bbs */*b*/, bbs_params */*bp*/, unsigned long /*n*/);
+extern void bbs_rew(bbs */*b*/, bbs_priv */*bp*/, unsigned long /*n*/);
 
 /*----- Parameter generation ----------------------------------------------*/
 
 /* --- @bbs_gen@ --- *
  *
- * Arguments:  @bbs_params *bp@ = pointer to parameter block
- *             @mp *p, *q@ = initial numbers to search from
- *             @size_t n@ = number of attempts to make
- *             @void (*proc)(int ev, mp *m, void *p)@ = event handler
- *             @void *arg@ = argument for event handler
+ * Arguments:  @bbs_priv *bp@ = pointer to parameter block
+ *             @unsigned nbits@ = number of bits in the modulus
+ *             @grand *r@ = pointer to random number source
+ *             @unsigned n@ = number of attempts to make
+ *             @pgen_proc *event@ = event handler function
+ *             @void *ectx@ = argument for event handler
  *
- * Returns:    Zero if all went well, otherwise an event code which explains
- *             the problem.
+ * Returns:    If it worked OK, @PGEN_DONE@, otherwise @PGEN_ABORT@.
  *
  * Use:                Finds two prime numbers %$p'$% and %$q'$% such that both are
  *             congruent to %$3 \bmod 4$%, and  $(p - 1)/2$% and
@@ -257,9 +284,8 @@ extern void bbs_rew(bbs */*b*/, bbs_params */*bp*/, unsigned long /*n*/);
  *             Shub pseudorandom bit generator.
  */
 
-extern int bbs_gen(bbs_params */*bp*/, mp */*p*/, mp */*q*/, size_t /*n*/,
-                  int (*/*proc*/)(int /*ev*/, mp */*m*/, void */*p*/),
-                  void */*arg*/);
+extern int bbs_gen(bbs_priv */*bp*/, unsigned /*nbits*/, grand */*r*/,
+                  unsigned /*n*/, pgen_proc */*event*/, void */*ectx*/);
 
 /*----- Generic random number generator interface -------------------------*/