From 4a548fc1d5673b2e827e6d0fc3d21b78016f70e2 Mon Sep 17 00:00:00 2001 From: mdw Date: Thu, 11 Nov 2004 00:56:25 +0000 Subject: [PATCH] Error return for Rabin-Miller context creation. --- rabin.c | 12 ++++++++---- rabin.h | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) 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@ --- * diff --git a/rabin.h b/rabin.h index 7fe4965..9bc0eb6 100644 --- a/rabin.h +++ b/rabin.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: rabin.h,v 1.7 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Miller-Rabin primality test * @@ -64,13 +64,13 @@ typedef struct rabin { * Arguments: @rabin *r@ = pointer to Rabin-Miller context * @mp *m@ = pointer to number to test * - * Returns: --- + * Returns: Zero on success, nonzero for failure. * * Use: Precomputes some useful values for performing the * Miller-Rabin probabilistic primality test. */ -extern void rabin_create(rabin */*r*/, mp */*m*/); +extern int rabin_create(rabin */*r*/, mp */*m*/); /* --- @rabin_destroy@ --- * * -- 2.11.0