pub/keycheck-mp.c (keycheck_prime): Use `pgen_primep' to do the legwork.
[catacomb] / pub / keycheck-mp.c
index c5779a4..237cfd2 100644 (file)
@@ -57,29 +57,8 @@ int keycheck_prime(keycheck *kc, unsigned sev, mp *m, const char *name)
 {
   int rc;
 
-  rc = pfilt_smallfactor(m);
-  if (rc == PGEN_TRY) {
-    rabin rn;
-    grand *r = fibrand_create(0);
-    unsigned n;
-    mp *x = MP_NEW;
-
-    r->ops->misc(r, GRAND_SEEDRAND, &rand_global);
-    n = rabin_iters(mp_bits(m));
-    rabin_create(&rn, m);
-    do {
-      x = mprand_range(x, m, r, 0);
-      rc = rabin_test(&rn, x);
-      n--;
-    } while (n && rc == PGEN_PASS);
-    rabin_destroy(&rn);
-    mp_drop(x);
-    r->ops->destroy(r);
-  }
-  if (rc != PGEN_FAIL)
-    rc = 0;
-  else
-    rc = keycheck_report(kc, sev, "%s not prime", name);
+  if (pgen_primep(m, &rand_global)) rc = 0;
+  else rc = keycheck_report(kc, sev, "%s not prime", name);
   return (rc);
 }