3 * $Id: limlee.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
5 * Generate Lim-Lee primes
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 #ifndef CATACOMB_LIMLEE_H
31 #define CATACOMB_LIMLEE_H
37 /*----- Header files ------------------------------------------------------*/
39 #ifndef CATACOMB_GRAND_H
47 #ifndef CATACOMB_PGEN_H
51 /*----- Data structures ---------------------------------------------------*/
53 typedef struct limlee_factor
{
54 mp
*p
; /* The actual prime */
55 unsigned tag
; /* A tag, usable by the generator */
56 void *more
; /* Pointer to more data */
59 typedef struct limlee_stepctx
{
61 /* --- To be initialized by the caller --- */
63 unsigned f
; /* Various useful flags */
64 mp
*newp
; /* Initial valid for new primes */
65 unsigned ql
, pl
; /* Size of factors and result */
66 const struct limlee_primeops
*pops
; /* Pointer to generator ops */
67 void *pc
; /* Context ptr for generator ops */
68 pgen_proc
*iev
; /* Event handler for inner @pgen@ */
69 void *iec
; /* Context for inner @pgen@ */
70 grand
*r
; /* Random number generator */
72 /* --- Output values --- */
74 size_t nf
; /* Number of factors wanted */
75 limlee_factor
*v
; /* Vector of factors */
77 /* --- Maintained internally --- */
79 octet
*c
; /* Combination byte-flag vector */
80 unsigned long seq
; /* Sequence number for primes */
81 size_t poolsz
; /* Size of the small-prime pool */
82 dstr d
; /* String for subprime name */
83 limlee_factor qq
; /* Big prime to pick up slack */
87 typedef struct limlee_primeops
{
88 void (*pgen
)(limlee_factor */
*f*/
, unsigned /*pl*/, limlee_stepctx */
*l*/
);
89 void (*pfree
)(limlee_factor */
*f*/
, limlee_stepctx */
*l*/
);
94 #define LIMLEE_KEEPFACTORS 1u
96 /*----- The Lim-Lee stepper function --------------------------------------*/
98 extern pgen_proc limlee_step
;
100 /*----- Functions provided ------------------------------------------------*/
102 /* --- @limlee@ --- *
104 * Arguments: @const char *name@ = pointer to name root
105 * @mp *d@ = pointer to destination integer
106 * @mp *newp@ = how to generate factor primes
107 * @unsigned ql@ = size of individual factors
108 * @unsigned pl@ = size of large prime
109 * @grand *r@ = a random number source
110 * @unsigned on@ = number of outer attempts to make
111 * @pgen_proc *oev@ = outer event handler function
112 * @void *oec@ = argument for the outer event handler
113 * @pgen_proc *iev@ = inner event handler function
114 * @void *iec@ = argument for the inner event handler
115 * @size_t *nf@, @mp ***f@ = output array for factors
117 * Returns: A Lim-Lee prime, or null if generation failed.
119 * Use: Generates Lim-Lee primes. A Lim-Lee prime %$p$% is one which
120 * satisfies %$p = 2 \prod_i q_i + 1$%, where all of the %$q_i$%
121 * are large enough to resist square-root discrete log
124 * If we succeed, and @f@ is non-null, we write the array of
125 * factors chosen to @f@ for the benefit of the caller.
128 extern mp
*limlee(const char */
*name*/
, mp */
*d*/
, mp */
*newp*/
,
129 unsigned /*ql*/, unsigned /*pl*/, grand */
*r*/
,
130 unsigned /*on*/, pgen_proc */
*oev*/
, void */
*oec*/
,
131 pgen_proc */
*iev*/
, void */
*iec*/
,
132 size_t */
*nf*/
, mp
***/
*f*/
);
134 /*----- That's all, folks -------------------------------------------------*/