04361334 |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: limlee.h,v 1.5 2004/04/08 01:36:15 mdw Exp $ |
04361334 |
4 | * |
5 | * Generate Lim-Lee primes |
6 | * |
7 | * (c) 2000 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
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. |
18 | * |
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. |
23 | * |
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, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
04361334 |
30 | #ifndef CATACOMB_LIMLEE_H |
31 | #define CATACOMB_LIMLEE_H |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif |
36 | |
37 | /*----- Header files ------------------------------------------------------*/ |
38 | |
39 | #ifndef CATACOMB_GRAND_H |
40 | # include "grand.h" |
41 | #endif |
42 | |
43 | #ifndef CATACOMB_MP_H |
44 | # include "mp.h" |
45 | #endif |
46 | |
47 | #ifndef CATACOMB_PGEN_H |
48 | # include "pgen.h" |
49 | #endif |
50 | |
10217a5c |
51 | /*----- Data structures ---------------------------------------------------*/ |
52 | |
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 */ |
57 | } limlee_factor; |
58 | |
59 | typedef struct limlee_stepctx { |
60 | |
61 | /* --- To be initialized by the caller --- */ |
62 | |
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@ */ |
383e235b |
70 | grand *r; /* Random number generator */ |
10217a5c |
71 | |
72 | /* --- Output values --- */ |
73 | |
74 | size_t nf; /* Number of factors wanted */ |
75 | limlee_factor *v; /* Vector of factors */ |
76 | |
77 | /* --- Maintained internally --- */ |
78 | |
79 | octet *c; /* Combination byte-flag vector */ |
10217a5c |
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 */ |
84 | |
85 | } limlee_stepctx; |
86 | |
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*/); |
90 | } limlee_primeops; |
91 | |
92 | /* --- Flags --- */ |
93 | |
16efd15b |
94 | #define LIMLEE_KEEPFACTORS 1u |
10217a5c |
95 | |
96 | /*----- The Lim-Lee stepper function --------------------------------------*/ |
97 | |
98 | extern int limlee_step(int /*rq*/, pgen_event */*ev*/, void */*p*/); |
99 | |
04361334 |
100 | /*----- Functions provided ------------------------------------------------*/ |
101 | |
102 | /* --- @limlee@ --- * |
103 | * |
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 |
116 | * |
117 | * Returns: A Lim-Lee prime, or null if generation failed. |
118 | * |
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 |
122 | * algorithms. |
123 | * |
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. |
126 | */ |
127 | |
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*/); |
133 | |
134 | /*----- That's all, folks -------------------------------------------------*/ |
135 | |
136 | #ifdef __cplusplus |
137 | } |
138 | #endif |
139 | |
140 | #endif |