X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/052b36d05a622a93733b735acce2de865b14627b..f41f820e4b3e230d9314cc4323abf59babdd4e67:/bbs.h diff --git a/bbs.h b/bbs.h index 6e23d02..7217f65 100644 --- a/bbs.h +++ b/bbs.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: bbs.h,v 1.3 2000/02/12 18:21:02 mdw Exp $ + * $Id: bbs.h,v 1.5 2000/07/01 11:20:24 mdw Exp $ * * The Blum-Blum-Shub random bit generator * @@ -30,6 +30,13 @@ /*----- 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). * @@ -47,14 +54,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 @@ -72,6 +79,10 @@ # include "grand.h" #endif +#ifndef CATACOMB_KEY_H +# include "key.h" +#endif + #ifndef CATACOMB_MP_H # include "mp.h" #endif @@ -98,10 +109,34 @@ typedef struct bbs { /* --- Parameters --- */ -typedef struct bbs_param { +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_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 + +/* --- @bbs_pubfree@, @bbs_privfree@ --- * + * + * Arguments: @bbs_pub *bp@, @bbs_priv *bp@ = pointer to key block + * + * Returns: --- + * + * Use: Frees a BBS key block. + */ + +extern void bbs_pubfree(bbs_pub */*bp*/); +extern void bbs_privfree(bbs_priv */*bp*/); /*----- The basic generator -----------------------------------------------*/ @@ -192,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*/); @@ -202,7 +237,7 @@ extern void bbs_wrap(bbs */*b*/); /* --- @bbs_ff@ --- * * * Arguments: @bbs *b@ = pointer to a BBS generator state - * @bbs_param *bp@ = pointer to BBS modulus factors + * @bbs_priv *bp@ = pointer to BBS modulus factors * @unsigned long n@ = number of steps to make * * Returns: --- @@ -212,12 +247,12 @@ extern void bbs_wrap(bbs */*b*/); * efficiently. */ -extern void bbs_ff(bbs */*b*/, bbs_param */*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_param *bp@ = pointer to BBS modulus factors + * @bbs_priv *bp@ = pointer to BBS modulus factors * @unsigned long n@ = number of steps to make * * Returns: --- @@ -227,13 +262,13 @@ extern void bbs_ff(bbs */*b*/, bbs_param */*bp*/, unsigned long /*n*/); * at all. */ -extern void bbs_rew(bbs */*b*/, bbs_param */*bp*/, unsigned long /*n*/); +extern void bbs_rew(bbs */*b*/, bbs_priv */*bp*/, unsigned long /*n*/); /*----- Parameter generation ----------------------------------------------*/ /* --- @bbs_gen@ --- * * - * Arguments: @bbs_param *bp@ = pointer to parameter block + * 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 @@ -249,7 +284,7 @@ extern void bbs_rew(bbs */*b*/, bbs_param */*bp*/, unsigned long /*n*/); * Shub pseudorandom bit generator. */ -extern int bbs_gen(bbs_param */*bp*/, unsigned /*nbits*/, grand */*r*/, +extern int bbs_gen(bbs_priv */*bp*/, unsigned /*nbits*/, grand */*r*/, unsigned /*n*/, pgen_proc */*event*/, void */*ectx*/); /*----- Generic random number generator interface -------------------------*/