3 # $Id: pgen.xs,v 1.2 2004/04/08 01:36:21 mdw Exp $
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 in Catacomb::MP::Prime::Filter::muladd");
65 croak("step too large in Catacomb::MP::Prime::Filter::muladd");
66 RETVAL = CREATE(MP_Prime_Filter);
67 RETVAL->rc = pfilt_muladd(&RETVAL->pf, &pf->pf, m, a);
77 croak("step too large in Catacomb::MP::Prime::Filter::step");
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_
132 croak("Argument to Catacomb::MP::Prime::Rabin must be positive");
133 if (x->v == x->vl || !(x->v[0] & 1u))
134 croak("Argument to Catacomb::MP::Prime::Rabin must be odd");
135 RETVAL = CREATE(MP_Prime_Rabin);
136 rabin_create(RETVAL, x);
163 RETVAL = rabin_iters(bits);
167 MP_Prime_Gen_RabinTester *
171 RETVAL = CREATE(MP_Prime_Gen_RabinTester);
172 RETVAL->mg.p = pgen_test;
173 RETVAL->mg.ctx = &RETVAL->r;
177 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::MagicProc
181 MP_Prime_Gen_MagicProc *proc
186 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::FilterStepper
190 MP_Prime_Gen_FilterStepper *s
195 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::JumpStepper
199 MP_Prime_Gen_JumpStepper *s
201 pfilt_destroy(&s->pf);
205 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::RabinTester
209 MP_Prime_Gen_RabinTester *t
214 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Proc
216 MP_Prime_Gen_MagicProc *
220 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
226 MP_Prime_Gen_MagicProc *
230 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
231 RETVAL->p = pgen_evspin;
236 MP_Prime_Gen_MagicProc *
240 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
241 RETVAL->p = pgen_subev;
246 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime
249 gen(name, m, steps, stepper, tests, tester, events = &PL_sv_undef)
252 MP_Prime_Gen_NullProc *events
254 MP_Prime_Gen_Proc *stepper
256 MP_Prime_Gen_Proc *tester
258 pgen_proc *ev, *step, *test;
259 void *ectx, *sctx, *tctx;
261 pgproc_get(events, &ev, &ectx);
262 pgproc_get(stepper, &step, &sctx);
263 pgproc_get(tester, &test, &tctx);
264 RETVAL = pgen(name, MP_NEW, m, ev, ectx,
265 steps, step, sctx, tests, test, tctx);
270 strongprime_setup(name, bits, r = &rand_global, n = 0, events = &PL_sv_undef)
275 MP_Prime_Gen_NullProc *events
280 MP_Prime_Gen_JumpStepper *j;
282 pgproc_get(events, &ev, &ectx);
283 j = CREATE(MP_Prime_Gen_JumpStepper);
284 d = strongprime_setup(name, MP_NEW, &j->pf, bits, r, n, ev, ectx);
295 PUSHs(RET(j, "Catacomb::MP::Prime::Gen::JumpStepper"));
299 limlee(name, qbits, pbits, r = &rand_global, on = 0, oevents = &PL_sv_undef, ievents = &PL_sv_undef)
305 MP_Prime_Gen_NullProc *oevents
306 MP_Prime_Gen_NullProc *ievents
308 pgen_proc *oev, *iev;
314 pgproc_get(oevents, &oev, &oec);
315 pgproc_get(ievents, &iev, &iec);
316 if (GIMME_V == G_SCALAR) {
317 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
318 oev, oec, iev, iec, 0, 0);
322 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
323 oev, oec, iev, iec, &nf, &f);
326 for (i = 0; i < nf; i++)
331 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Event
335 MP_Prime_Gen_Event *ev
337 RETVAL = (char *)ev->name;
343 MP_Prime_Gen_Event *ev
346 RETVAL = mp_copy(ev->m);
356 MP_Prime_Gen_Event *ev
358 RETVAL = MAKE(ev->r, "Catacomb::Rand::Magic");
362 #----- That's all, folks ----------------------------------------------------