Fix division-by-zero error for argument zero, and segfaults for
arguments with degree less than 2 due to skipping the main loop. Handle
these as a special case.
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);
}
irred {
+ 0 0;
+ 1 0;
+ 2 1;
0xc1a7bd3b4e853fc92d4e1588719986aa 0;
0x800000000000000000000000000000000000000c9 1;
0x2000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001 1;