Error return for Rabin-Miller context creation.
authormdw <mdw>
Thu, 11 Nov 2004 00:56:25 +0000 (00:56 +0000)
committermdw <mdw>
Thu, 11 Nov 2004 00:56:25 +0000 (00:56 +0000)
rabin.c
rabin.h

diff --git a/rabin.c b/rabin.c
index 729ecce..4c08f87 100644 (file)
--- 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
  *
  * 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 (file)
--- 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@ --- *
  *