X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b817bfc642225b8c3c0b6a7e42d1fb949b61a606..02dfbd5b7af7816959dbd39c1fe628451204e35f:/rabin.c diff --git a/rabin.c b/rabin.c index 729ecce..4c08f87 100644 --- a/rabin.c +++ b/rabin.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rabin.c,v 1.9 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Miller-Rabin primality test * @@ -42,19 +42,23 @@ * Arguments: @rabin *r@ = pointer to Rabin-Miller context * @mp *m@ = pointer to number to test * - * Returns: --- + * Returns: Zero on success, nonzero on failure. * * Use: Precomputes some useful values for performing the * Miller-Rabin probabilistic primality test. */ -void rabin_create(rabin *r, mp *m) +int rabin_create(rabin *r, mp *m) { mp *m1 = mp_sub(MP_NEW, m, MP_ONE); - mpmont_create(&r->mm, m); + if (mpmont_create(&r->mm, m)) { + MP_DROP(m1); + return (-1); + } r->r = mp_odd(MP_NEW, m1, &r->s); r->m1 = mp_sub(MP_NEW, m, r->mm.r); mp_drop(m1); + return (0); } /* --- @rabin_destroy@ --- *