3 # $Id: pgen.xs,v 1.1 2004/04/02 18:04:01 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 #----- Revision history -----------------------------------------------------
31 # Revision 1.1 2004/04/02 18:04:01 mdw
35 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Filter
42 RETVAL = CREATE(MP_Prime_Filter);
43 RETVAL->rc = pfilt_create(&RETVAL->pf, x);
51 pfilt_destroy(&pf->pf);
70 croak("multiplier too large in Catacomb::MP::Prime::Filter::muladd");
72 croak("step too large in Catacomb::MP::Prime::Filter::muladd");
73 RETVAL = CREATE(MP_Prime_Filter);
74 RETVAL->rc = pfilt_muladd(&RETVAL->pf, &pf->pf, m, a);
84 croak("step too large in Catacomb::MP::Prime::Filter::step");
85 RETVAL = pf->rc = pfilt_step(&pf->pf, n);
94 RETVAL = pf->rc = pfilt_jump(&pf->pf, &j->pf);
102 RETVAL = mp_copy(pf->pf.m);
106 MP_Prime_Gen_FilterStepper *
111 RETVAL = CREATE(MP_Prime_Gen_FilterStepper);
112 RETVAL->f.step = step;
113 RETVAL->mg.p = pgen_filter;
114 RETVAL->mg.ctx = &RETVAL->f;
118 MP_Prime_Gen_JumpStepper *
123 RETVAL = CREATE(MP_Prime_Gen_JumpStepper);
124 pfilt_create(&RETVAL->pf, j);
125 RETVAL->j.j = &RETVAL->pf;
126 RETVAL->mg.p = pgen_jump;
127 RETVAL->mg.ctx = &RETVAL->j;
131 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Rabin PREFIX = rabin_
139 croak("Argument to Catacomb::MP::Prime::Rabin must be positive");
140 if (x->v == x->vl || !(x->v[0] & 1u))
141 croak("Argument to Catacomb::MP::Prime::Rabin must be odd");
142 RETVAL = CREATE(MP_Prime_Rabin);
143 rabin_create(RETVAL, x);
170 RETVAL = rabin_iters(bits);
174 MP_Prime_Gen_RabinTester *
178 RETVAL = CREATE(MP_Prime_Gen_RabinTester);
179 RETVAL->mg.p = pgen_test;
180 RETVAL->mg.ctx = &RETVAL->r;
184 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::MagicProc
188 MP_Prime_Gen_MagicProc *proc
193 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::FilterStepper
197 MP_Prime_Gen_FilterStepper *s
202 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::JumpStepper
206 MP_Prime_Gen_JumpStepper *s
208 pfilt_destroy(&s->pf);
212 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::RabinTester
216 MP_Prime_Gen_RabinTester *t
221 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Proc
223 MP_Prime_Gen_MagicProc *
227 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
233 MP_Prime_Gen_MagicProc *
237 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
238 RETVAL->p = pgen_evspin;
243 MP_Prime_Gen_MagicProc *
247 RETVAL = CREATE(MP_Prime_Gen_MagicProc);
248 RETVAL->p = pgen_subev;
253 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime
256 gen(name, m, steps, stepper, tests, tester, events = &PL_sv_undef)
259 MP_Prime_Gen_NullProc *events
261 MP_Prime_Gen_Proc *stepper
263 MP_Prime_Gen_Proc *tester
265 pgen_proc *ev, *step, *test;
266 void *ectx, *sctx, *tctx;
268 pgproc_get(events, &ev, &ectx);
269 pgproc_get(stepper, &step, &sctx);
270 pgproc_get(tester, &test, &tctx);
271 RETVAL = pgen(name, MP_NEW, m, ev, ectx,
272 steps, step, sctx, tests, test, tctx);
277 strongprime_setup(name, bits, r = &rand_global, n = 0, events = &PL_sv_undef)
282 MP_Prime_Gen_NullProc *events
287 MP_Prime_Gen_JumpStepper *j;
289 pgproc_get(events, &ev, &ectx);
290 j = CREATE(MP_Prime_Gen_JumpStepper);
291 d = strongprime_setup(name, MP_NEW, &j->pf, bits, r, n, ev, ectx);
302 PUSHs(RET(j, "Catacomb::MP::Prime::Gen::JumpStepper"));
306 limlee(name, qbits, pbits, r = &rand_global, on = 0, oevents = &PL_sv_undef, ievents = &PL_sv_undef)
312 MP_Prime_Gen_NullProc *oevents
313 MP_Prime_Gen_NullProc *ievents
315 pgen_proc *oev, *iev;
321 pgproc_get(oevents, &oev, &oec);
322 pgproc_get(ievents, &iev, &iec);
323 if (GIMME_V == G_SCALAR) {
324 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
325 oev, oec, iev, iec, 0, 0);
329 x = limlee(name, MP_NEW, MP_NEW, qbits, pbits, r, on,
330 oev, oec, iev, iec, &nf, &f);
333 for (i = 0; i < nf; i++)
338 MODULE = Catacomb PACKAGE = Catacomb::MP::Prime::Gen::Event
342 MP_Prime_Gen_Event *ev
344 RETVAL = (char *)ev->name;
350 MP_Prime_Gen_Event *ev
353 RETVAL = mp_copy(ev->m);
363 MP_Prime_Gen_Event *ev
365 RETVAL = MAKE(ev->r, "Catacomb::Rand::Magic");
369 #----- That's all, folks ----------------------------------------------------