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::Group PREFIX = group_
42 RETVAL = group_prime(&gp);
58 RETVAL = group_binary(&gb);
77 RETVAL = group_ec(&ei);
88 if ((e = group_fromstring(n, &RETVAL)) != 0)
89 croak("bad group name: `%s'", e);
104 RETVAL = G_CREATE(g);
105 G_COPY(g, RETVAL, g->i);
113 RETVAL = G_CREATE(g);
114 G_COPY(g, RETVAL, g->g);
122 RETVAL = MP_COPY(g->r);
130 RETVAL = MP_COPY(g->h);
140 check(g, rng = &rand_global)
149 XPUSHs(&PL_sv_undef);
150 if (GIMME_V == G_ARRAY)
151 XPUSHs(sv_2mortal(newSVpv(e, 0)));
158 if (group_check(g, x))
164 _destroyelement(g, x)
176 RETVAL = G_IDENTP(g, x);
184 RETVAL = info_group(g);
194 RETVAL = G_EQ(g, x, y);
204 RETVAL = G_CREATE(g);
205 G_MUL(g, RETVAL, x, y);
214 RETVAL = G_CREATE(g);
224 RETVAL = G_CREATE(g);
235 RETVAL = G_CREATE(g);
236 G_DIV(g, RETVAL, x, y);
246 RETVAL = G_CREATE(g);
247 G_EXP(g, RETVAL, x, n);
258 if (items < 3 || !(items & 1)) {
259 croak("Usage: Catacomb::Group::mexp"
260 "(g, x_0, n_0, x_1, n_1, ...");
263 v = xmalloc(n * sizeof(group_expfactor));
264 for (i = 1, j = 0; i < items; i += 2, j++) {
265 v[j].base = ptrfromsv(ST(i), "Catacomb::Group::Element", "p_i");
266 v[j].exp = mp_fromsv(ST(i + 1), "x_i", 0, 0);
268 RETVAL = G_CREATE(g);
269 G_MEXP(g, RETVAL, v, n);
279 RETVAL = G_TOINT(g, MP_NEW, x);
288 RETVAL = G_CREATE(g);
289 if (G_FROMINT(g, RETVAL, x)) {
290 G_DESTROY(g, RETVAL);
303 if (G_TOEC(g, RETVAL, x)) {
315 RETVAL = G_CREATE(g);
316 if (G_FROMEC(g, RETVAL, x)) {
317 G_DESTROY(g, RETVAL);
329 size_t n = g->noctets + 8; /* Guess */
331 RETVAL = NEWSV(0, n);
332 buf_init(&b, SvPVX(RETVAL), n);
333 if (G_TOBUF(g, &b, x))
334 croak("unexpected failure in Catacomb::Group::putbuf");
335 SvCUR_set(RETVAL, BLEN(&b));
352 if (G_FROMBUF(g, &b, x))
355 XPUSHs(RET(x, "Catacomb::Group::Element"));
356 if (GIMME_V == G_ARRAY)
357 XPUSHs(sv_2mortal(newSVpvn((char *)BCUR(&b), BLEFT(&b))));
366 size_t n = g->noctets;
368 RETVAL = NEWSV(0, n);
369 buf_init(&b, SvPVX(RETVAL), n);
370 if (G_TORAW(g, &b, x))
371 croak("unexpected failure in Catacomb::Group::putraw");
372 SvCUR_set(RETVAL, BLEN(&b));
389 if (G_FROMRAW(g, &b, x))
392 XPUSHs(RET(x, "Catacomb::Group::Element"));
393 if (GIMME_V == G_ARRAY)
394 XPUSHs(sv_2mortal(newSVpvn((char *)BCUR(&b), BLEFT(&b))));
402 RETVAL = NEWSV(0, 64);
403 if (group_writesv(g, x, RETVAL)) {
404 SvREFCNT_dec(RETVAL);
419 ms.buf = SvPV(s, len);
420 ms.lim = ms.buf + len;
422 if (G_READ(g, x, &mptext_stringops, &ms))
425 XPUSHs(RET(x, "Catacomb::Group::Element"));
426 if (GIMME_V == G_ARRAY)
427 XPUSHs(sv_2mortal(newSVpvn(ms.buf, ms.lim - ms.buf)));