X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/4f743df55ac05e51bc69aaabd188132f2f94543b..d34decd2b2b88240cf4ca68a2a5feb7bf36de6e7:/bbs.h diff --git a/bbs.h b/bbs.h index 485fb76..2098745 100644 --- a/bbs.h +++ b/bbs.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: bbs.h,v 1.2 1999/12/22 15:52:08 mdw Exp $ + * $Id: bbs.h,v 1.4 2000/06/17 10:45:48 mdw Exp $ * * The Blum-Blum-Shub random bit generator * @@ -30,6 +30,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: bbs.h,v $ + * 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. * @@ -44,14 +50,14 @@ * 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 @@ -69,6 +75,10 @@ # include "grand.h" #endif +#ifndef CATACOMB_KEY_H +# include "key.h" +#endif + #ifndef CATACOMB_MP_H # include "mp.h" #endif @@ -95,10 +105,22 @@ typedef struct bbs { /* --- Parameters --- */ +typedef struct bbs_pub { + mp *n; +} bbs_pub; + typedef struct bbs_param { mp *p, *q; /* Prime factors (3 mod 4) */ mp *n; /* Product @pq@ -- a Blum integer */ -} bbs_param; +} bbs_param, bbs_priv; + +/*----- Key fetching ------------------------------------------------------*/ + +extern const key_fetchdef bbs_pubfetch[]; +#define BBS_PUBFETCHSZ 3 + +extern const key_fetchdef bbs_privfetch[]; +#define BBS_PRIVFETCHSZ 7 /*----- The basic generator -----------------------------------------------*/ @@ -189,7 +211,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*/); @@ -231,8 +253,9 @@ extern void bbs_rew(bbs */*b*/, bbs_param */*bp*/, unsigned long /*n*/); /* --- @bbs_gen@ --- * * * Arguments: @bbs_param *bp@ = pointer to parameter block - * @mp *p, *q@ = initial numbers to search from - * @size_t n@ = number of attempts to make + * @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 * @@ -245,8 +268,8 @@ extern void bbs_rew(bbs */*b*/, bbs_param */*bp*/, unsigned long /*n*/); * Shub pseudorandom bit generator. */ -extern int bbs_gen(bbs_param */*bp*/, mp */*p*/, mp */*q*/, size_t /*n*/, - pgen_proc */*event*/, void */*ectx*/); +extern int bbs_gen(bbs_param */*bp*/, unsigned /*nbits*/, grand */*r*/, + unsigned /*n*/, pgen_proc */*event*/, void */*ectx*/); /*----- Generic random number generator interface -------------------------*/