5 # Prime generation gubbins
7 # (c) 2001 Straylight/Edgeware
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of the Perl interface to Catacomb.
14 # Catacomb/Perl is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # Catacomb/Perl 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 General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with Catacomb/Perl; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Filter
35 RETVAL = CREATE(MP_Prime_Filter);
36 RETVAL->rc = pfilt_create(&RETVAL->pf, x);
44 pfilt_destroy(&pf->pf);
63 croak("multiplier too large");
65 croak("step too large");
66 RETVAL = CREATE(MP_Prime_Filter);
67 RETVAL->rc = pfilt_muladd(&RETVAL->pf, &pf->pf, m, a);
77 croak("step too large");
78 RETVAL = pf->rc = pfilt_step(&pf->pf, n);
87 RETVAL = pf->rc = pfilt_jump(&pf->pf, &j->pf);
95 RETVAL = mp_copy(pf->pf.m);
99 MP_Prime_Gen_FilterStepper *
104 RETVAL = CREATE(MP_Prime_Gen_FilterStepper);
105 RETVAL->f.step = step;
106 RETVAL->mg.p = pgen_filter;
107 RETVAL->mg.ctx = &RETVAL->f;
111 MP_Prime_Gen_JumpStepper *
116 RETVAL = CREATE(MP_Prime_Gen_JumpStepper);
117 pfilt_create(&RETVAL->pf, j);
118 RETVAL->j.j = &RETVAL->pf;
119 RETVAL->mg.p = pgen_jump;
120 RETVAL->mg.ctx = &RETVAL->j;
124 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Rabin PREFIX = rabin_
131 RETVAL = CREATE(MP_Prime_Rabin);
132 if (rabin_create(RETVAL, x)) {
156 RETVAL = MP_COPY(r->mm.m);
171 RETVAL = rabin_iters(bits);
175 MP_Prime_Gen_RabinTester *
179 RETVAL = CREATE(MP_Prime_Gen_RabinTester);
180 RETVAL->mg.p = pgen_test;
181 RETVAL->mg.ctx = &RETVAL->r;
185 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::MagicProc
189 MP_Prime_Gen_MagicProc *proc
194 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::FilterStepper
198 MP_Prime_Gen_FilterStepper *s
203 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::JumpStepper
207 MP_Prime_Gen_JumpStepper *s
209 pfilt_destroy(&s->pf);
213 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::RabinTester
217 MP_Prime_Gen_RabinTester *t
222 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Proc
224 MP_Prime_Gen_MagicProc *
228 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
234 MP_Prime_Gen_MagicProc *
238 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
239 RETVAL->p = pgen_evspin;
244 MP_Prime_Gen_MagicProc *
248 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
249 RETVAL->p = pgen_subev;
257 MP_Prime_Gen_Event *ev
269 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime
272 gen(me, name, m, steps, stepper, tests, tester, events = &PL_sv_undef)
276 MP_Prime_Gen_NullProc *events
278 MP_Prime_Gen_Proc *stepper
280 MP_Prime_Gen_Proc *tester
282 pgen_proc *ev, *step, *test;
283 void *ectx, *sctx, *tctx;
285 pgproc_get(events, &ev, &ectx);
286 pgproc_get(stepper, &step, &sctx);
287 pgproc_get(tester, &test, &tctx);
288 RETVAL = pgen(name, MP_NEW, m, ev, ectx,
289 steps, step, sctx, tests, test, tctx);
294 strongprime_setup(me, name, bits, r = &rand_global, n = 0, events = &PL_sv_undef)
300 MP_Prime_Gen_NullProc *events
305 MP_Prime_Gen_JumpStepper *j;
307 pgproc_get(events, &ev, &ectx);
308 j = CREATE(MP_Prime_Gen_JumpStepper);
309 d = strongprime_setup(name, MP_NEW, &j->pf, bits, r, n, ev, ectx);
318 PUSHs(RET(j, "Catacomb::MP::Prime::Gen::JumpStepper"));
322 limlee(me, name, qbits, pbits, r = &rand_global, on = 0, oevents = &PL_sv_undef, ievents = &PL_sv_undef)
329 MP_Prime_Gen_NullProc *oevents
330 MP_Prime_Gen_NullProc *ievents
332 pgen_proc *oev, *iev;
338 pgproc_get(oevents, &oev, &oec);
339 pgproc_get(ievents, &iev, &iec);
340 if (GIMME_V == G_SCALAR) {
341 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
342 oev, oec, iev, iec, 0, 0);
347 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
348 oev, oec, iev, iec, &nf, &f);
352 for (i = 0; i < nf; i++)
357 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Event
361 MP_Prime_Gen_Event *ev
363 RETVAL = (char *)ev->name;
368 m(ev, x = &PL_sv_undef)
369 MP_Prime_Gen_Event *ev
374 RETVAL = mp_copy(ev->m);
376 if ((y = mp_fromsv(x, "x", 0, 1)) == 0)
377 croak("bad integer");
386 MP_Prime_Gen_Event *ev
394 MP_Prime_Gen_Event *ev
402 MP_Prime_Gen_Event *ev
404 RETVAL = MAKE(ev->r, "Catacomb::Rand::Magic");
408 #----- That's all, folks ----------------------------------------------------