Skip to content

Commit f0b91a5

Browse files
Tom St Denissjaeckel
Tom St Denis
authored andcommitted
added libtommath-0.39
1 parent 21adca0 commit f0b91a5

File tree

133 files changed

+474
-4674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+474
-4674
lines changed

bn.pdf

7 Bytes
Binary file not shown.

bn.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
\begin{document}
5050
\frontmatter
5151
\pagestyle{empty}
52-
\title{LibTomMath User Manual \\ v0.38}
52+
\title{LibTomMath User Manual \\ v0.39}
5353
\author{Tom St Denis \\ tomstdenis@iahu.ca}
5454
\maketitle
5555
This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been

bn_error.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
static const struct {

bn_fast_mp_invmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* computes the modular inverse via binary extended euclidean algorithm,

bn_fast_mp_montgomery_reduce.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* computes xR**-1 == x (mod N) via Montgomery Reduction

bn_fast_s_mp_mul_digs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* Fast (comba) multiplier

bn_fast_s_mp_mul_high_digs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* this is a modified version of fast_s_mul_digs that only produces

bn_fast_s_mp_sqr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* the jist of squaring...

bn_mp_2expt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* computes a = 2**b

bn_mp_abs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* b = |a|

bn_mp_add.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* high level addition (handles signs) */

bn_mp_add_d.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* single digit addition */

bn_mp_addmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* d = a + b (mod c) */

bn_mp_and.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* AND two ints together */

bn_mp_clamp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* trim unused digits

bn_mp_clear.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* clear one (frees) */

bn_mp_clear_multi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717
#include <stdarg.h>
1818

bn_mp_cmp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* compare two ints (signed)*/

bn_mp_cmp_d.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* compare a digit */

bn_mp_cmp_mag.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* compare maginitude of two ints (unsigned) */

bn_mp_cnt_lsb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
static const int lnz[16] = {

bn_mp_copy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* copy, b = a */

bn_mp_count_bits.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* returns the number of bits in an int */

bn_mp_div.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
#ifdef BN_MP_DIV_SMALL

bn_mp_div_2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* b = a/2 */

bn_mp_div_2d.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* shift right by a certain bit count (store quotient in c, optional remainder in d) */

bn_mp_div_3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* divide by three (based on routine from MPI and the GMP manual) */

bn_mp_div_d.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
static int s_is_power_of_two(mp_digit b, int *p)

bn_mp_dr_is_modulus.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* determines if a number is a valid DR modulus */

bn_mp_dr_reduce.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* reduce "x" in place modulo "n" using the Diminished Radix algorithm.

bn_mp_dr_setup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* determines the setup value */

bn_mp_exch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* swap the elements of two integers, for cases where you can't simply swap the

bn_mp_expt_d.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* calculate c = a**b using a square-multiply algorithm */

bn_mp_exptmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818

bn_mp_exptmod_fast.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85

bn_mp_exteuclid.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* Extended euclidean algorithm of (a, b) produces

bn_mp_fread.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* read a bigint from a file stream in ASCII */

bn_mp_fwrite.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
int mp_fwrite(mp_int *a, int radix, FILE *stream)

bn_mp_gcd.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* Greatest Common Divisor using the binary method */
@@ -22,21 +22,13 @@ int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
2222
int k, u_lsb, v_lsb, res;
2323

2424
/* either zero than gcd is the largest */
25-
if (mp_iszero (a) == 1 && mp_iszero (b) == 0) {
25+
if (mp_iszero (a) == MP_YES) {
2626
return mp_abs (b, c);
2727
}
28-
if (mp_iszero (a) == 0 && mp_iszero (b) == 1) {
28+
if (mp_iszero (b) == MP_YES) {
2929
return mp_abs (a, c);
3030
}
3131

32-
/* optimized. At this point if a == 0 then
33-
* b must equal zero too
34-
*/
35-
if (mp_iszero (a) == 1) {
36-
mp_zero(c);
37-
return MP_OKAY;
38-
}
39-
4032
/* get copies of a and b we can modify */
4133
if ((res = mp_init_copy (&u, a)) != MP_OKAY) {
4234
return res;

bn_mp_get_int.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* get the lower 32-bits of an mp_int */

bn_mp_grow.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* grow as required */

bn_mp_init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* The library is free for all purposes without any express
1313
* guarantee it works.
1414
*
15-
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
15+
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1616
*/
1717

1818
/* init a new mp_int */

0 commit comments

Comments
 (0)