added libtommath-0.39
This commit is contained in:
parent
21adca01da
commit
f0b91a572e
2
bn.tex
2
bn.tex
|
@ -49,7 +49,7 @@
|
|||
\begin{document}
|
||||
\frontmatter
|
||||
\pagestyle{empty}
|
||||
\title{LibTomMath User Manual \\ v0.38}
|
||||
\title{LibTomMath User Manual \\ v0.39}
|
||||
\author{Tom St Denis \\ tomstdenis@iahu.ca}
|
||||
\maketitle
|
||||
This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
static const struct {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes the modular inverse via binary extended euclidean algorithm,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes xR**-1 == x (mod N) via Montgomery Reduction
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Fast (comba) multiplier
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* this is a modified version of fast_s_mul_digs that only produces
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* the jist of squaring...
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes a = 2**b
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* b = |a|
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* high level addition (handles signs) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* single digit addition */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* d = a + b (mod c) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* AND two ints together */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* trim unused digits
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* clear one (frees) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* compare two ints (signed)*/
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* compare a digit */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* compare maginitude of two ints (unsigned) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
static const int lnz[16] = {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* copy, b = a */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* returns the number of bits in an int */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
#ifdef BN_MP_DIV_SMALL
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* b = a/2 */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* divide by three (based on routine from MPI and the GMP manual) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
static int s_is_power_of_two(mp_digit b, int *p)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines if a number is a valid DR modulus */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines the setup value */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* swap the elements of two integers, for cases where you can't simply swap the
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* calculate c = a**b using a square-multiply algorithm */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Extended euclidean algorithm of (a, b) produces
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* read a bigint from a file stream in ASCII */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
int mp_fwrite(mp_int *a, int radix, FILE *stream)
|
||||
|
|
14
bn_mp_gcd.c
14
bn_mp_gcd.c
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Greatest Common Divisor using the binary method */
|
||||
|
@ -22,21 +22,13 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
|
|||
int k, u_lsb, v_lsb, res;
|
||||
|
||||
/* either zero than gcd is the largest */
|
||||
if (mp_iszero (a) == 1 && mp_iszero (b) == 0) {
|
||||
if (mp_iszero (a) == MP_YES) {
|
||||
return mp_abs (b, c);
|
||||
}
|
||||
if (mp_iszero (a) == 0 && mp_iszero (b) == 1) {
|
||||
if (mp_iszero (b) == MP_YES) {
|
||||
return mp_abs (a, c);
|
||||
}
|
||||
|
||||
/* optimized. At this point if a == 0 then
|
||||
* b must equal zero too
|
||||
*/
|
||||
if (mp_iszero (a) == 1) {
|
||||
mp_zero(c);
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
/* get copies of a and b we can modify */
|
||||
if ((res = mp_init_copy (&u, a)) != MP_OKAY) {
|
||||
return res;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* get the lower 32-bits of an mp_int */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* grow as required */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* init a new mp_int */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* creates "a" then copies b into it */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* initialize and set a digit */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* initialize and set a digit */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* init an mp_init for a given size */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* hac 14.61, pp608 */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* hac 14.61, pp608 */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Check if remainders are possible squares - fast exclude non-squares */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes the jacobi c = (a | n) (or Legendre if n is prime)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* c = |a| * |b| using Karatsuba Multiplication using
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Karatsuba squaring, computes b = a*a using three
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes least common multiple as |a*b|/(a, b) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* shift left a certain amount of digits */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* c = a mod b, 0 <= c < b */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* calc a value mod 2**b */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
int
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/*
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes xR**-1 == x (mod N) via Montgomery Reduction */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* setups the montgomery reduction stuff */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* high level multiplication (handles sign) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* b = a*2 */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* shift left by a certain bit count */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* multiply by a digit */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* d = a * b (mod c) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* find the n'th root of an integer
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* b = -a */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* OR two ints together */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* performs one Fermat test.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines if an integers is divisible by one
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* performs a variable number of rounds of Miller-Rabin
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* Miller-Rabin test of "a" to the base of "b" as described in
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* finds the next prime after the number "a" using "t" trials
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* makes a truly random prime of a given size (bits),
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* returns size of ASCII reprensentation */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* chars used in radix conversions */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* makes a pseudo-random int of a given size */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* read a string [ASCII] in a given radix */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* read signed bin, big endian, first byte is 0==positive or 1==negative */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* reads a unsigned char array, assumes the msb is stored first [big endian] */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* reduces x mod m, assumes 0 < x < m**2, mu is
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* reduces a modulo n where n is of the form 2**p - d */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* reduces a modulo n where n is of the form 2**p - d
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines the setup value */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines the setup value */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines if mp_reduce_2k can be used */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* determines if reduce_2k_l can be used */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* pre-calculate the value required for Barrett reduction
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* shift right a certain amount of digits */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* set to a digit */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* set a 32-bit const */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* shrink a bignum */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* get the size for an signed equivalent */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* computes b = a*a */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* c = a * a (mod b) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* this function is less generic than mp_n_root, simpler and faster */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* high level subtraction (handles signs) */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
|
||||
/* single digit subtraction */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue