Add new functions.
authormdw <mdw>
Thu, 22 Jun 2000 19:02:01 +0000 (19:02 +0000)
committermdw <mdw>
Thu, 22 Jun 2000 19:02:01 +0000 (19:02 +0000)
mp.h

diff --git a/mp.h b/mp.h
index 92f1209..12003d0 100644 (file)
--- a/mp.h
+++ b/mp.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp.h,v 1.7 2000/06/17 11:45:09 mdw Exp $
+ * $Id: mp.h,v 1.8 2000/06/22 19:02:01 mdw Exp $
  *
  * Simple multiprecision arithmetic
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mp.h,v $
+ * Revision 1.8  2000/06/22 19:02:01  mdw
+ * Add new functions.
+ *
  * Revision 1.7  2000/06/17 11:45:09  mdw
  * Major memory management overhaul.  Added arena support.  Use the secure
  * arena for secret integers.  Replace and improve the MP management macros
@@ -629,8 +632,39 @@ extern mp *mp_sqr(mp */*d*/, mp */*a*/);
 
 extern void mp_div(mp **/*qq*/, mp **/*rr*/, mp */*a*/, mp */*b*/);
 
+/* --- @mp_odd@ --- *
+ *
+ * Arguments:  @mp *d@ = pointer to destination integer
+ *             @mp *m@ = pointer to source integer
+ *             @size_t *s@ = where to store the power of 2
+ *
+ * Returns:    An odd integer integer %$t$% such that %$m = 2^s t$%.
+ *
+ * Use:                Computes a power of two and an odd integer which, when
+ *             multiplied, give a specified result.  This sort of thing is
+ *             useful in number theory quite often.
+ */
+
+extern mp *mp_odd(mp */*d*/, mp */*m*/, size_t */*s*/);
+
 /*----- More advanced algorithms ------------------------------------------*/
 
+/* --- @mp_sqrt@ --- *
+ *
+ * Arguments:  @mp *d@ = pointer to destination integer
+ *             @mp *a@ = (nonnegative) integer to take square root of
+ *
+ * Returns:    The largest integer %$x$% such that %$x^2 \le a$%.
+ *
+ * Use:                Computes integer square roots.
+ *
+ *             The current implementation isn't very good: it uses the
+ *             Newton-Raphson method to find an approximation to %$a$%.  If
+ *             there's any demand for a better version, I'll write one.
+ */
+
+extern mp *mp_sqrt(mp */*d*/, mp */*a*/);
+
 /* --- @mp_gcd@ --- *
  *
  * Arguments:  @mp **gcd, **xx, **yy@ = where to write the results
@@ -659,7 +693,25 @@ extern void mp_gcd(mp **/*gcd*/, mp **/*xx*/, mp **/*yy*/,
  *             @a@ and @n@ have a common factor greater than one.
  */
 
-int mp_jacobi(mp */*a*/, mp */*n*/);
+extern int mp_jacobi(mp */*a*/, mp */*n*/);
+
+/* --- @mp_modsqrt@ --- *
+ *
+ * Arguments:  @mp *d@ = destination integer
+ *             @mp *a@ = source integer
+ *             @mp *p@ = modulus (must be prime)
+ *
+ * Returns:    If %$a$% is a quadratic residue, a square root of %$a$%; else
+ *             a null pointer.
+ *
+ * Use:                Returns an integer %$x$% such that %$x^2 \equiv a \pmod{p}$%,
+ *             if one exists; else a null pointer.  This function will not
+ *             work if %$p$% is composite: you must factor the modulus, take
+ *             a square root mod each factor, and recombine the results
+ *             using the Chinese Remainder Theorem.
+ */
+
+extern mp *mp_modsqrt(mp */*d*/, mp */*a*/, mp */*p*/);
 
 /*----- Test harness support ----------------------------------------------*/