3 * Exponentiation for abstract groups
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
31 #include "group-exp.h"
33 /*----- Main code ---------------------------------------------------------*/
35 /* --- @group_stdexp@ --- *
37 * Arguments: @group *g@ = abstract group
38 * @ge *d@ = destination pointer
39 * @ge *x@ = base element
44 * Use: Computes %$d = x^n$% efficiently.
47 void group_stdexp(group
*gg
, ge
*d
, ge
*x
, mp
*n
)
61 if (MP_LEN(n
) < EXP_THRESH
)
69 /* --- @group_stdmexp@ --- *
71 * Arguments: @group *g@ = abstract group
72 * @ge *d@ = destination pointer
73 * @const group_expfactor *f@ = vector of factors
74 * @size_t n@ = number of factors
78 * Use: Computes %$d = g_0^{x_0} g_1^{x_1} \ldots$% efficiently.
84 void group_stdmexp(group
*gg
, ge
*d
, const group_expfactor
*f
, size_t n
)
86 group_expfactor
*ff
= xmalloc(n
* sizeof(group_expfactor
));
89 for (i
= 0; i
< n
; i
++) {
90 ff
[i
].base
= G_CREATE(gg
);
92 if (MP_NEGP(f
[i
].exp
))
93 G_INV(gg
, ff
[i
].base
, f
[i
].base
);
95 G_COPY(gg
, ff
[i
].base
, f
[i
].base
);
96 if (f
[i
].exp
->f
& MP_BURN
)
97 G_BURN(gg
, ff
[i
].base
);
100 G_COPY(gg
, d
, gg
->i
);
102 for (i
= 0; i
< n
; i
++)
103 G_DESTROY(gg
, ff
[i
].base
);
107 /*----- That's all, folks -------------------------------------------------*/