X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b817bfc642225b8c3c0b6a7e42d1fb949b61a606..bccb92dd7abb72205fb3835f746145d271d2b998:/gf-arith.c diff --git a/gf-arith.c b/gf-arith.c index c23aa19..eabbff8 100644 --- a/gf-arith.c +++ b/gf-arith.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: gf-arith.c,v 1.4 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Basic arithmetic on binary polynomials * @@ -179,11 +179,17 @@ void gf_div(mp **qq, mp **rr, mp *a, mp *b) 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); @@ -230,6 +236,7 @@ static int verify(const char *op, mp *expect, mp *result, mp *a, mp *b) RIG(add, gf_add) RIG(mul, gf_mul) +RIG(exp, gf_exp) #undef RIG @@ -285,6 +292,7 @@ static test_chunk tests[] = { { "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 } }, };