From d2679863cf27b0812a4b88397be1ebf0b1319305 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 28 Apr 2022 18:21:47 +0100 Subject: [PATCH] pub/keycheck-mp.c (keycheck_prime): Use `pgen_primep' to do the legwork. This will now use Baillie--PSW rather than Rabin--Miller, giving more useful, faster results. --- pub/keycheck-mp.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/pub/keycheck-mp.c b/pub/keycheck-mp.c index c5779a4c..237cfd20 100644 --- a/pub/keycheck-mp.c +++ b/pub/keycheck-mp.c @@ -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); } -- 2.11.0