From 22a073c05a6237e8e4b3c4d9a761b04656209efe Mon Sep 17 00:00:00 2001 From: mdw Date: Thu, 22 Jun 2000 19:02:01 +0000 Subject: [PATCH] Add new functions. --- mp.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/mp.h b/mp.h index 92f1209..12003d0 100644 --- 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 ----------------------------------------------*/ -- 2.11.0