/* -*-c-*-
*
- * $Id: gf-arith.c,v 1.4 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
*
* Basic arithmetic on binary polynomials
*
* (c) 2004 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* Catacomb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with Catacomb; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
int gf_irreduciblep(mp *f)
{
- unsigned long m = mp_bits(f) - 1;
+ unsigned long m;
mp *u = MP_TWO;
mp *v = MP_NEW;
- m /= 2;
+ if (MP_ZEROP(f))
+ return (0);
+ else if (MP_LEN(f) == 1) {
+ if (f->v[0] < 2) return (0);
+ if (f->v[0] < 4) return (1);
+ }
+ m = (mp_bits(f) - 1)/2;
while (m) {
u = gf_sqr(u, u);
gf_div(0, &u, u, f);
{
if (!MP_EQ(expect, result)) {
fprintf(stderr, "\n*** %s failed", op);
- fputs("\n*** a = ", stderr); mp_writefile(a, stderr, 16);
- fputs("\n*** b = ", stderr); mp_writefile(b, stderr, 16);
+ fputs("\n*** a = ", stderr); mp_writefile(a, stderr, 16);
+ fputs("\n*** b = ", stderr); mp_writefile(b, stderr, 16);
fputs("\n*** result = ", stderr); mp_writefile(result, stderr, 16);
fputs("\n*** expect = ", stderr); mp_writefile(expect, stderr, 16);
fputc('\n', stderr);
RIG(add, gf_add)
RIG(mul, gf_mul)
+RIG(exp, gf_exp)
#undef RIG
if (r != c) {
ok = 0;
fprintf(stderr, "\n*** irred failed");
- fputs("\n*** a = ", stderr); mp_writefile(a, stderr, 16);
- fprintf(stderr, "\n*** r = %d\n", r);
- fprintf(stderr, "*** c = %d\n", c);
+ fputs("\n*** a = ", stderr); mp_writefile(a, stderr, 16);
+ fprintf(stderr, "\n*** r = %d\n", r);
+ fprintf(stderr, "*** c = %d\n", c);
}
mp_drop(a);
assert(mparena_count(MPARENA_GLOBAL) == 0);
{ "mul", tmul, { &type_mp, &type_mp, &type_mp, 0 } },
{ "sqr", tsqr, { &type_mp, &type_mp, 0 } },
{ "div", tdiv, { &type_mp, &type_mp, &type_mp, &type_mp, 0 } },
+ { "exp", texp, { &type_mp, &type_mp, &type_mp, 0 } },
{ "irred", tirred, { &type_mp, &type_int, 0 } },
{ 0, 0, { 0 } },
};