changeset 386:97db060d0ef5 libtommath-orig libtommath-0.40

Update to LibTomMath 0.40
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 03:11:15 +0000
parents 91fbc376f010
children 4663ced4968f
files TODO bn.ind bn.pdf bn.tex bn_error.c bn_fast_mp_invmod.c bn_fast_mp_montgomery_reduce.c bn_fast_s_mp_mul_digs.c bn_fast_s_mp_mul_high_digs.c bn_fast_s_mp_sqr.c bn_mp_2expt.c bn_mp_abs.c bn_mp_add.c bn_mp_add_d.c bn_mp_addmod.c bn_mp_and.c bn_mp_clamp.c bn_mp_clear.c bn_mp_clear_multi.c bn_mp_cmp.c bn_mp_cmp_d.c bn_mp_cmp_mag.c bn_mp_cnt_lsb.c bn_mp_copy.c bn_mp_count_bits.c bn_mp_div.c bn_mp_div_2.c bn_mp_div_2d.c bn_mp_div_3.c bn_mp_div_d.c bn_mp_dr_is_modulus.c bn_mp_dr_reduce.c bn_mp_dr_setup.c bn_mp_exch.c bn_mp_expt_d.c bn_mp_exptmod.c bn_mp_exptmod_fast.c bn_mp_exteuclid.c bn_mp_fread.c bn_mp_fwrite.c bn_mp_gcd.c bn_mp_get_int.c bn_mp_grow.c bn_mp_init.c bn_mp_init_copy.c bn_mp_init_multi.c bn_mp_init_set.c bn_mp_init_set_int.c bn_mp_init_size.c bn_mp_invmod.c bn_mp_invmod_slow.c bn_mp_is_square.c bn_mp_jacobi.c bn_mp_karatsuba_mul.c bn_mp_karatsuba_sqr.c bn_mp_lcm.c bn_mp_lshd.c bn_mp_mod.c bn_mp_mod_2d.c bn_mp_mod_d.c bn_mp_montgomery_calc_normalization.c bn_mp_montgomery_reduce.c bn_mp_montgomery_setup.c bn_mp_mul.c bn_mp_mul_2.c bn_mp_mul_2d.c bn_mp_mul_d.c bn_mp_mulmod.c bn_mp_n_root.c bn_mp_neg.c bn_mp_or.c bn_mp_prime_fermat.c bn_mp_prime_is_divisible.c bn_mp_prime_is_prime.c bn_mp_prime_miller_rabin.c bn_mp_prime_next_prime.c bn_mp_prime_rabin_miller_trials.c bn_mp_prime_random_ex.c bn_mp_radix_size.c bn_mp_radix_smap.c bn_mp_rand.c bn_mp_read_radix.c bn_mp_read_signed_bin.c bn_mp_read_unsigned_bin.c bn_mp_reduce.c bn_mp_reduce_2k.c bn_mp_reduce_2k_l.c bn_mp_reduce_2k_setup.c bn_mp_reduce_2k_setup_l.c bn_mp_reduce_is_2k.c bn_mp_reduce_is_2k_l.c bn_mp_reduce_setup.c bn_mp_rshd.c bn_mp_set.c bn_mp_set_int.c bn_mp_shrink.c bn_mp_signed_bin_size.c bn_mp_sqr.c bn_mp_sqrmod.c bn_mp_sqrt.c bn_mp_sub.c bn_mp_sub_d.c bn_mp_submod.c bn_mp_to_signed_bin.c bn_mp_to_signed_bin_n.c bn_mp_to_unsigned_bin.c bn_mp_to_unsigned_bin_n.c bn_mp_toom_mul.c bn_mp_toom_sqr.c bn_mp_toradix.c bn_mp_toradix_n.c bn_mp_unsigned_bin_size.c bn_mp_xor.c bn_mp_zero.c bn_prime_tab.c bn_reverse.c bn_s_mp_add.c bn_s_mp_exptmod.c bn_s_mp_mul_digs.c bn_s_mp_mul_high_digs.c bn_s_mp_sqr.c bn_s_mp_sub.c bncore.c booker.pl changes.txt demo/demo.c demo/timing.c etc/2kprime.c etc/drprime.c etc/drprimes.txt etc/makefile.icc etc/mersenne.c etc/mont.c etc/pprime.c etc/tune.c logs/expt.log logs/expt_2k.log logs/expt_2kl.log logs/expt_dr.log logs/index.html logs/sqr.old makefile makefile.bcc makefile.cygwin_dll makefile.icc makefile.msvc makefile.shared mess.sh mtest/logtab.h mtest/mpi-config.h mtest/mpi-types.h mtest/mpi.c mtest/mpi.h mtest/mtest.c poster.pdf pre_gen/mpi.c tommath.h tommath.pdf tommath.src tommath.tex tommath_class.h tommath_superclass.h
diffstat 162 files changed, 2320 insertions(+), 1192 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Wed Mar 08 13:16:18 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-things for book in order of importance...
-
-- Fix up pseudo-code [only] for combas that are not consistent with source
-- Start in chapter 3 [basics] and work up...
-   - re-write to prose [less abrupt]
-   - clean up pseudo code [spacing]
-   - more examples where appropriate and figures
-
-Goal:
-   - Get sync done by mid January [roughly 8-12 hours work]
-   - Finish ch3-6 by end of January [roughly 12-16 hours of work]
-   - Finish ch7-end by mid Feb [roughly 20-24 hours of work].
-
-Goal isn't "first edition" but merely cleaner to read.
-
-
--- a/bn.ind	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn.ind	Thu Jan 11 03:11:15 2007 +0000
@@ -1,82 +1,82 @@
 \begin{theindex}
 
-  \item mp\_add, \hyperpage{29}
-  \item mp\_add\_d, \hyperpage{52}
-  \item mp\_and, \hyperpage{29}
-  \item mp\_clear, \hyperpage{11}
-  \item mp\_clear\_multi, \hyperpage{12}
-  \item mp\_cmp, \hyperpage{24}
-  \item mp\_cmp\_d, \hyperpage{25}
+  \item mp\_add, \hyperpage{31}
+  \item mp\_add\_d, \hyperpage{56}
+  \item mp\_and, \hyperpage{31}
+  \item mp\_clear, \hyperpage{12}
+  \item mp\_clear\_multi, \hyperpage{13}
+  \item mp\_cmp, \hyperpage{25}
+  \item mp\_cmp\_d, \hyperpage{26}
   \item mp\_cmp\_mag, \hyperpage{23}
-  \item mp\_div, \hyperpage{30}
-  \item mp\_div\_2, \hyperpage{26}
-  \item mp\_div\_2d, \hyperpage{28}
-  \item mp\_div\_d, \hyperpage{52}
-  \item mp\_dr\_reduce, \hyperpage{40}
-  \item mp\_dr\_setup, \hyperpage{40}
-  \item MP\_EQ, \hyperpage{22}
-  \item mp\_error\_to\_string, \hyperpage{10}
-  \item mp\_expt\_d, \hyperpage{43}
-  \item mp\_exptmod, \hyperpage{43}
-  \item mp\_exteuclid, \hyperpage{51}
-  \item mp\_gcd, \hyperpage{51}
+  \item mp\_div, \hyperpage{32}
+  \item mp\_div\_2, \hyperpage{28}
+  \item mp\_div\_2d, \hyperpage{30}
+  \item mp\_div\_d, \hyperpage{56}
+  \item mp\_dr\_reduce, \hyperpage{45}
+  \item mp\_dr\_setup, \hyperpage{45}
+  \item MP\_EQ, \hyperpage{23}
+  \item mp\_error\_to\_string, \hyperpage{9}
+  \item mp\_expt\_d, \hyperpage{47}
+  \item mp\_exptmod, \hyperpage{47}
+  \item mp\_exteuclid, \hyperpage{55}
+  \item mp\_gcd, \hyperpage{55}
   \item mp\_get\_int, \hyperpage{20}
-  \item mp\_grow, \hyperpage{16}
-  \item MP\_GT, \hyperpage{22}
+  \item mp\_grow, \hyperpage{17}
+  \item MP\_GT, \hyperpage{23}
   \item mp\_init, \hyperpage{11}
-  \item mp\_init\_copy, \hyperpage{13}
-  \item mp\_init\_multi, \hyperpage{12}
+  \item mp\_init\_copy, \hyperpage{14}
+  \item mp\_init\_multi, \hyperpage{13}
   \item mp\_init\_set, \hyperpage{21}
   \item mp\_init\_set\_int, \hyperpage{21}
-  \item mp\_init\_size, \hyperpage{14}
+  \item mp\_init\_size, \hyperpage{15}
   \item mp\_int, \hyperpage{10}
-  \item mp\_invmod, \hyperpage{52}
-  \item mp\_jacobi, \hyperpage{52}
-  \item mp\_lcm, \hyperpage{51}
-  \item mp\_lshd, \hyperpage{28}
-  \item MP\_LT, \hyperpage{22}
+  \item mp\_invmod, \hyperpage{56}
+  \item mp\_jacobi, \hyperpage{56}
+  \item mp\_lcm, \hyperpage{56}
+  \item mp\_lshd, \hyperpage{30}
+  \item MP\_LT, \hyperpage{23}
   \item MP\_MEM, \hyperpage{9}
-  \item mp\_mod, \hyperpage{35}
-  \item mp\_mod\_d, \hyperpage{52}
-  \item mp\_montgomery\_calc\_normalization, \hyperpage{38}
-  \item mp\_montgomery\_reduce, \hyperpage{37}
-  \item mp\_montgomery\_setup, \hyperpage{37}
-  \item mp\_mul, \hyperpage{31}
-  \item mp\_mul\_2, \hyperpage{26}
-  \item mp\_mul\_2d, \hyperpage{28}
-  \item mp\_mul\_d, \hyperpage{52}
-  \item mp\_n\_root, \hyperpage{44}
-  \item mp\_neg, \hyperpage{29}
+  \item mp\_mod, \hyperpage{39}
+  \item mp\_mod\_d, \hyperpage{56}
+  \item mp\_montgomery\_calc\_normalization, \hyperpage{42}
+  \item mp\_montgomery\_reduce, \hyperpage{42}
+  \item mp\_montgomery\_setup, \hyperpage{42}
+  \item mp\_mul, \hyperpage{33}
+  \item mp\_mul\_2, \hyperpage{28}
+  \item mp\_mul\_2d, \hyperpage{29}
+  \item mp\_mul\_d, \hyperpage{56}
+  \item mp\_n\_root, \hyperpage{48}
+  \item mp\_neg, \hyperpage{31, 32}
   \item MP\_NO, \hyperpage{9}
   \item MP\_OKAY, \hyperpage{9}
-  \item mp\_or, \hyperpage{29}
-  \item mp\_prime\_fermat, \hyperpage{45}
-  \item mp\_prime\_is\_divisible, \hyperpage{45}
-  \item mp\_prime\_is\_prime, \hyperpage{46}
-  \item mp\_prime\_miller\_rabin, \hyperpage{45}
-  \item mp\_prime\_next\_prime, \hyperpage{46}
-  \item mp\_prime\_rabin\_miller\_trials, \hyperpage{46}
-  \item mp\_prime\_random, \hyperpage{47}
-  \item mp\_prime\_random\_ex, \hyperpage{47}
-  \item mp\_radix\_size, \hyperpage{49}
-  \item mp\_read\_radix, \hyperpage{49}
-  \item mp\_read\_unsigned\_bin, \hyperpage{50}
-  \item mp\_reduce, \hyperpage{36}
-  \item mp\_reduce\_2k, \hyperpage{41}
-  \item mp\_reduce\_2k\_setup, \hyperpage{41}
-  \item mp\_reduce\_setup, \hyperpage{36}
-  \item mp\_rshd, \hyperpage{28}
+  \item mp\_or, \hyperpage{31}
+  \item mp\_prime\_fermat, \hyperpage{49}
+  \item mp\_prime\_is\_divisible, \hyperpage{49}
+  \item mp\_prime\_is\_prime, \hyperpage{51}
+  \item mp\_prime\_miller\_rabin, \hyperpage{50}
+  \item mp\_prime\_next\_prime, \hyperpage{51}
+  \item mp\_prime\_rabin\_miller\_trials, \hyperpage{50}
+  \item mp\_prime\_random, \hyperpage{51}
+  \item mp\_prime\_random\_ex, \hyperpage{52}
+  \item mp\_radix\_size, \hyperpage{53}
+  \item mp\_read\_radix, \hyperpage{53}
+  \item mp\_read\_unsigned\_bin, \hyperpage{54}
+  \item mp\_reduce, \hyperpage{40}
+  \item mp\_reduce\_2k, \hyperpage{46}
+  \item mp\_reduce\_2k\_setup, \hyperpage{46}
+  \item mp\_reduce\_setup, \hyperpage{40}
+  \item mp\_rshd, \hyperpage{30}
   \item mp\_set, \hyperpage{19}
   \item mp\_set\_int, \hyperpage{20}
-  \item mp\_shrink, \hyperpage{15}
-  \item mp\_sqr, \hyperpage{33}
-  \item mp\_sub, \hyperpage{29}
-  \item mp\_sub\_d, \hyperpage{52}
-  \item mp\_to\_unsigned\_bin, \hyperpage{50}
-  \item mp\_toradix, \hyperpage{49}
-  \item mp\_unsigned\_bin\_size, \hyperpage{50}
+  \item mp\_shrink, \hyperpage{16}
+  \item mp\_sqr, \hyperpage{35}
+  \item mp\_sub, \hyperpage{31}
+  \item mp\_sub\_d, \hyperpage{56}
+  \item mp\_to\_unsigned\_bin, \hyperpage{54}
+  \item mp\_toradix, \hyperpage{53}
+  \item mp\_unsigned\_bin\_size, \hyperpage{54}
   \item MP\_VAL, \hyperpage{9}
-  \item mp\_xor, \hyperpage{29}
+  \item mp\_xor, \hyperpage{31}
   \item MP\_YES, \hyperpage{9}
 
 \end{theindex}
Binary file bn.pdf has changed
--- a/bn.tex	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn.tex	Thu Jan 11 03:11:15 2007 +0000
@@ -1,4 +1,4 @@
-\documentclass[b5paper]{book}
+\documentclass[synpaper]{book}
 \usepackage{hyperref}
 \usepackage{makeidx}
 \usepackage{amssymb}
@@ -49,8 +49,8 @@
 \begin{document}
 \frontmatter
 \pagestyle{empty}
-\title{LibTomMath User Manual \\ v0.35}
-\author{Tom St Denis \\ [email protected]}
+\title{LibTomMath User Manual \\ v0.40}
+\author{Tom St Denis \\ [email protected]}
 \maketitle
 This text, the library and the accompanying textbook are all hereby placed in the public domain.  This book has been 
 formatted for B5 [176x250] paper using the \LaTeX{} {\em book} macro package.
--- a/bn_error.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_error.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static const struct {
@@ -41,3 +41,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_fast_mp_invmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_fast_mp_invmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes the modular inverse via binary extended euclidean algorithm, 
@@ -142,3 +142,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_fast_mp_montgomery_reduce.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_fast_mp_montgomery_reduce.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction
@@ -166,3 +166,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_montgomery_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_fast_s_mp_mul_digs.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_fast_s_mp_mul_digs.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Fast (comba) multiplier
@@ -70,6 +70,7 @@
       /* execute loop */
       for (iz = 0; iz < iy; ++iz) {
          _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
+
       }
 
       /* store term */
@@ -77,10 +78,7 @@
 
       /* make next carry */
       _W = _W >> ((mp_word)DIGIT_BIT);
-  }
-
-  /* store final carry */
-  W[ix] = (mp_digit)(_W & MP_MASK);
+ }
 
   /* setup dest */
   olduse  = c->used;
@@ -103,3 +101,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_fast_s_mp_mul_high_digs.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_fast_s_mp_mul_high_digs.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* this is a modified version of fast_s_mul_digs that only produces
@@ -70,9 +70,6 @@
       _W = _W >> ((mp_word)DIGIT_BIT);
   }
   
-  /* store final carry */
-  W[ix] = (mp_digit)(_W & MP_MASK);
-
   /* setup dest */
   olduse  = c->used;
   c->used = pa;
@@ -81,7 +78,7 @@
     register mp_digit *tmpc;
 
     tmpc = c->dp + digs;
-    for (ix = digs; ix <= pa; ix++) {
+    for (ix = digs; ix < pa; ix++) {
       /* now extract the previous digit [below the carry] */
       *tmpc++ = W[ix];
     }
@@ -95,3 +92,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_high_digs.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/11/14 03:46:25 $ */
--- a/bn_fast_s_mp_sqr.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_fast_s_mp_sqr.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* the jist of squaring...
@@ -108,3 +108,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_2expt.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_2expt.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes a = 2**b 
@@ -42,3 +42,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_abs.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_abs.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = |a| 
@@ -37,3 +37,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_add.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_add.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level addition (handles signs) */
@@ -47,3 +47,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_add_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_add_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* single digit addition */
@@ -40,6 +40,9 @@
      /* fix sign  */
      a->sign = c->sign = MP_NEG;
 
+     /* clamp */
+     mp_clamp(c);
+
      return res;
   }
 
@@ -103,3 +106,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_addmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_addmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a + b (mod c) */
@@ -35,3 +35,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_and.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_and.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* AND two ints together */
@@ -51,3 +51,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_clamp.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_clamp.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* trim unused digits 
@@ -38,3 +38,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_clear.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_clear.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* clear one (frees)  */
@@ -38,3 +38,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_clear_multi.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_clear_multi.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 #include <stdarg.h>
 
@@ -28,3 +28,7 @@
     va_end(args);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_cmp.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_cmp.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare two ints (signed)*/
@@ -37,3 +37,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_cmp_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_cmp_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare a digit */
@@ -38,3 +38,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_cmp_mag.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_cmp_mag.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare maginitude of two ints (unsigned) */
@@ -49,3 +49,7 @@
   return MP_EQ;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_cnt_lsb.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_cnt_lsb.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static const int lnz[16] = { 
@@ -47,3 +47,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_copy.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_copy.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* copy, b = a */
@@ -62,3 +62,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_copy.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_count_bits.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_count_bits.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* returns the number of bits in an int */
@@ -39,3 +39,7 @@
   return r;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_div.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_div.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 #ifdef BN_MP_DIV_SMALL
@@ -286,3 +286,7 @@
 #endif
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_div.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_div_2.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_div_2.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = a/2 */
@@ -62,3 +62,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_div_2d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_div_2d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
@@ -91,3 +91,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_div_3.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_div_3.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* divide by three (based on routine from MPI and the GMP manual) */
@@ -73,3 +73,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_3.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_div_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_div_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static int s_is_power_of_two(mp_digit b, int *p)
@@ -104,3 +104,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_dr_is_modulus.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_dr_is_modulus.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if a number is a valid DR modulus */
@@ -37,3 +37,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_dr_reduce.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_dr_reduce.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
@@ -88,3 +88,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_dr_setup.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_dr_setup.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -26,3 +26,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_exch.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_exch.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* swap the elements of two integers, for cases where you can't simply swap the 
@@ -28,3 +28,7 @@
   *b = t;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_expt_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_expt_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* calculate c = a**b  using a square-multiply algorithm */
@@ -51,3 +51,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_exptmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_exptmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 
@@ -66,7 +66,7 @@
   }
 
 /* modified diminished radix reduction */
-#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C)
+#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
   if (mp_reduce_is_2k_l(P) == MP_YES) {
      return s_mp_exptmod(G, X, P, Y, 1);
   }
@@ -106,3 +106,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_exptmod_fast.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_exptmod_fast.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
@@ -315,3 +315,7 @@
 }
 #endif
 
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod_fast.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_exteuclid.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_exteuclid.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Extended euclidean algorithm of (a, b) produces 
@@ -76,3 +76,7 @@
    return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_exteuclid.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_fread.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_fread.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read a bigint from a file stream in ASCII */
@@ -61,3 +61,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_fread.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_fwrite.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_fwrite.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 int mp_fwrite(mp_int *a, int radix, FILE *stream)
@@ -46,3 +46,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_gcd.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_gcd.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Greatest Common Divisor using the binary method */
@@ -22,21 +22,13 @@
   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;
@@ -107,3 +99,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_get_int.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_get_int.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the lower 32-bits of an mp_int */
@@ -39,3 +39,7 @@
   return res & 0xFFFFFFFFUL;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_grow.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_grow.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* grow as required */
@@ -51,3 +51,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* init a new mp_int */
@@ -40,3 +40,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init_copy.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init_copy.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* creates "a" then copies b into it */
@@ -26,3 +26,7 @@
   return mp_copy (b, a);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init_multi.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init_multi.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 #include <stdarg.h>
 
@@ -53,3 +53,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init_set.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init_set.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* initialize and set a digit */
@@ -26,3 +26,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init_set_int.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init_set_int.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* initialize and set a digit */
@@ -25,3 +25,7 @@
   return mp_set_int(a, b);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_init_size.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_init_size.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* init an mp_init for a given size */
@@ -42,3 +42,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_invmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_invmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* hac 14.61, pp608 */
@@ -37,3 +37,7 @@
   return MP_VAL;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_invmod_slow.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_invmod_slow.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* hac 14.61, pp608 */
@@ -169,3 +169,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod_slow.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_is_square.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_is_square.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Check if remainders are possible squares - fast exclude non-squares */
@@ -103,3 +103,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_jacobi.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_jacobi.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes the jacobi c = (a | n) (or Legendre if n is prime)
@@ -99,3 +99,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_jacobi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_karatsuba_mul.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_karatsuba_mul.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = |a| * |b| using Karatsuba Multiplication using 
@@ -26,12 +26,12 @@
  * b = b1 * B**n + b0
  *
  * Then, a * b => 
-   a1b1 * B**2n + ((a1 - a0)(b1 - b0) + a0b0 + a1b1) * B + a0b0
+   a1b1 * B**2n + ((a1 + a0)(b1 + b0) - (a0b0 + a1b1)) * B + a0b0
  *
  * Note that a1b1 and a0b0 are used twice and only need to be 
  * computed once.  So in total three half size (half # of 
  * digit) multiplications are performed, a0b0, a1b1 and 
- * (a1-b1)(a0-b0)
+ * (a1+b1)(a0+b0)
  *
  * Note that a multiplication of half the digits requires
  * 1/4th the number of single precision multiplications so in 
@@ -122,19 +122,19 @@
   if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
     goto X1Y1;          /* x1y1 = x1*y1 */
 
-  /* now calc x1-x0 and y1-y0 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+  /* now calc x1+x0 and y1+y0 */
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
     goto X1Y1;          /* t1 = x1 - x0 */
-  if (mp_sub (&y1, &y0, &x0) != MP_OKAY)
+  if (s_mp_add (&y1, &y0, &x0) != MP_OKAY)
     goto X1Y1;          /* t2 = y1 - y0 */
   if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = (x1 - x0) * (y1 - y0) */
+    goto X1Y1;          /* t1 = (x1 + x0) * (y1 + y0) */
 
   /* add x0y0 */
   if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
     goto X1Y1;          /* t2 = x0y0 + x1y1 */
-  if (mp_sub (&x0, &t1, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = x0y0 + x1y1 - (x1-x0)*(y1-y0) */
+  if (s_mp_sub (&t1, &x0, &t1) != MP_OKAY)
+    goto X1Y1;          /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
 
   /* shift by B */
   if (mp_lshd (&t1, B) != MP_OKAY)
@@ -161,3 +161,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_mul.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_karatsuba_sqr.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_karatsuba_sqr.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Karatsuba squaring, computes b = a*a using three 
@@ -80,8 +80,8 @@
   if (mp_sqr (&x1, &x1x1) != MP_OKAY)
     goto X1X1;           /* x1x1 = x1*x1 */
 
-  /* now calc (x1-x0)**2 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+  /* now calc (x1+x0)**2 */
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
     goto X1X1;           /* t1 = x1 - x0 */
   if (mp_sqr (&t1, &t1) != MP_OKAY)
     goto X1X1;           /* t1 = (x1 - x0) * (x1 - x0) */
@@ -89,8 +89,8 @@
   /* add x0y0 */
   if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
     goto X1X1;           /* t2 = x0x0 + x1x1 */
-  if (mp_sub (&t2, &t1, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */
+  if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
+    goto X1X1;           /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
 
   /* shift by B */
   if (mp_lshd (&t1, B) != MP_OKAY)
@@ -115,3 +115,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_lcm.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_lcm.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes least common multiple as |a*b|/(a, b) */
@@ -54,3 +54,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_lcm.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_lshd.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_lshd.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift left a certain amount of digits */
@@ -61,3 +61,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_lshd.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = a mod b, 0 <= c < b */
@@ -42,3 +42,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mod_2d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mod_2d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* calc a value mod 2**b */
@@ -49,3 +49,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mod_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mod_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 int
@@ -21,3 +21,7 @@
   return mp_div_d(a, b, NULL, c);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_montgomery_calc_normalization.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_montgomery_calc_normalization.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /*
@@ -53,3 +53,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_calc_normalization.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_montgomery_reduce.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_montgomery_reduce.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction */
@@ -112,3 +112,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_montgomery_setup.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_montgomery_setup.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* setups the montgomery reduction stuff */
@@ -48,8 +48,12 @@
 #endif
 
   /* rho = -1/m mod b */
-  *rho = (((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
+  *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
 
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_setup.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/12/04 21:34:03 $ */
--- a/bn_mp_mul.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mul.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level multiplication (handles sign) */
@@ -60,3 +60,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mul_2.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mul_2.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = a*2 */
@@ -76,3 +76,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mul_2d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mul_2d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift left by a certain bit count */
@@ -79,3 +79,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mul_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mul_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiply by a digit */
@@ -73,3 +73,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_mulmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_mulmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,12 +12,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a * b (mod c) */
-int
-mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
+int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 {
   int     res;
   mp_int  t;
@@ -35,3 +34,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_n_root.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_n_root.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* find the n'th root of an integer 
@@ -126,3 +126,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_n_root.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_neg.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_neg.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = -a */
@@ -34,3 +34,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_or.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_or.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* OR two ints together */
@@ -44,3 +44,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_fermat.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_fermat.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* performs one Fermat test.
@@ -56,3 +56,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_fermat.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_is_divisible.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_is_divisible.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if an integers is divisible by one 
@@ -44,3 +44,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_is_prime.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_is_prime.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* performs a variable number of rounds of Miller-Rabin
@@ -77,3 +77,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_miller_rabin.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_miller_rabin.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Miller-Rabin test of "a" to the base of "b" as described in 
@@ -97,3 +97,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_miller_rabin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_next_prime.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_next_prime.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* finds the next prime after the number "a" using "t" trials
@@ -164,3 +164,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_next_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_rabin_miller_trials.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_rabin_miller_trials.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 
@@ -46,3 +46,7 @@
 
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_prime_random_ex.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_prime_random_ex.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* makes a truly random prime of a given size (bits),
@@ -62,10 +62,8 @@
    maskOR_msb        = 0;
    maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
    if (flags & LTM_PRIME_2MSB_ON) {
-      maskOR_msb     |= 1 << ((size - 2) & 7);
-   } else if (flags & LTM_PRIME_2MSB_OFF) {
-      maskAND        &= ~(1 << ((size - 2) & 7));
-   } 
+      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
+   }  
 
    /* get the maskOR_lsb */
    maskOR_lsb         = 1;
@@ -121,3 +119,7 @@
 
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_random_ex.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_radix_size.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_radix_size.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* returns size of ASCII reprensentation */
@@ -36,7 +36,7 @@
   }
 
   if (mp_iszero(a) == MP_YES) {
-     *size = 2;
+    *size = 2;
     return MP_OKAY;
   }
 
@@ -72,3 +72,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_radix_smap.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_radix_smap.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,9 +12,13 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* chars used in radix conversions */
 const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_rand.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_rand.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* makes a pseudo-random int of a given size */
@@ -49,3 +49,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_read_radix.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_read_radix.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read a string [ASCII] in a given radix */
@@ -21,6 +21,9 @@
   int     y, res, neg;
   char    ch;
 
+  /* zero the digit bignum */
+  mp_zero(a);
+
   /* make sure the radix is ok */
   if (radix < 2 || radix > 64) {
     return MP_VAL;
@@ -76,3 +79,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_read_signed_bin.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_read_signed_bin.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,12 +12,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
-int
-mp_read_signed_bin (mp_int * a, unsigned char *b, int c)
+int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -36,3 +35,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_read_unsigned_bin.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_read_unsigned_bin.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,12 +12,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
-int
-mp_read_unsigned_bin (mp_int * a, unsigned char *b, int c)
+int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -50,3 +49,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces x mod m, assumes 0 < x < m**2, mu is 
@@ -94,3 +94,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_2k.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_2k.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces a modulo n where n is of the form 2**p - d */
@@ -55,3 +55,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_2k_l.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_2k_l.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces a modulo n where n is of the form 2**p - d 
@@ -56,3 +56,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_2k_setup.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_2k_setup.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -41,3 +41,7 @@
    return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_2k_setup_l.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_2k_setup_l.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -38,3 +38,7 @@
    return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_is_2k.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_is_2k.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if mp_reduce_2k can be used */
@@ -46,3 +46,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_is_2k_l.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_is_2k_l.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if reduce_2k_l can be used */
@@ -38,3 +38,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_reduce_setup.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_reduce_setup.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* pre-calculate the value required for Barrett reduction
@@ -28,3 +28,7 @@
   return mp_div (a, b, a, NULL);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_rshd.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_rshd.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift right a certain amount of digits */
@@ -66,3 +66,7 @@
   a->used -= b;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_set.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_set.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set to a digit */
@@ -23,3 +23,7 @@
   a->used  = (a->dp[0] != 0) ? 1 : 0;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_set_int.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_set_int.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set a 32-bit const */
@@ -42,3 +42,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_shrink.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_shrink.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shrink a bignum */
@@ -29,3 +29,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_signed_bin_size.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_signed_bin_size.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the size for an signed equivalent */
@@ -21,3 +21,7 @@
   return 1 + mp_unsigned_bin_size (a);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_sqr.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_sqr.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes b = a*a */
@@ -52,3 +52,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_sqrmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_sqrmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = a * a (mod b) */
@@ -35,3 +35,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_sqrt.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_sqrt.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* this function is less generic than mp_n_root, simpler and faster */
@@ -75,3 +75,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_sub.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_sub.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level subtraction (handles signs) */
@@ -53,3 +53,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_sub_d.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_sub_d.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* single digit subtraction */
@@ -36,6 +36,10 @@
      a->sign = MP_ZPOS;
      res     = mp_add_d(a, b, c);
      a->sign = c->sign = MP_NEG;
+
+     /* clamp */
+     mp_clamp(c);
+
      return res;
   }
 
@@ -83,3 +87,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub_d.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_submod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_submod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a - b (mod c) */
@@ -36,3 +36,7 @@
   return res;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_to_signed_bin.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_to_signed_bin.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in signed [big endian] format */
@@ -27,3 +27,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_to_signed_bin_n.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_to_signed_bin_n.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in signed [big endian] format */
@@ -25,3 +25,7 @@
    return mp_to_signed_bin(a, b);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_to_unsigned_bin.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_to_unsigned_bin.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in unsigned [big endian] format */
@@ -42,3 +42,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_to_unsigned_bin_n.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_to_unsigned_bin_n.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in unsigned [big endian] format */
@@ -25,3 +25,7 @@
    return mp_to_unsigned_bin(a, b);
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_toom_mul.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_toom_mul.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplication using the Toom-Cook 3-way algorithm 
@@ -278,3 +278,7 @@
 }     
      
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_mul.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_toom_sqr.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_toom_sqr.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* squaring using Toom-Cook 3-way algorithm */
@@ -220,3 +220,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_toradix.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_toradix.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) */
@@ -69,3 +69,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_toradix_n.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_toradix_n.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) 
@@ -27,12 +27,12 @@
   char   *_s = str;
 
   /* check range of the maxlen, radix */
-  if (maxlen < 3 || radix < 2 || radix > 64) {
+  if (maxlen < 2 || radix < 2 || radix > 64) {
     return MP_VAL;
   }
 
   /* quick out if its zero */
-  if (mp_iszero(a) == 1) {
+  if (mp_iszero(a) == MP_YES) {
      *str++ = '0';
      *str = '\0';
      return MP_OKAY;
@@ -57,21 +57,20 @@
 
   digs = 0;
   while (mp_iszero (&t) == 0) {
+    if (--maxlen < 1) {
+       /* no more room */
+       break;
+    }
     if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
       mp_clear (&t);
       return res;
     }
     *str++ = mp_s_rmap[d];
     ++digs;
-
-    if (--maxlen == 1) {
-       /* no more room */
-       break;
-    }
   }
 
   /* reverse the digits of the string.  In this case _s points
-   * to the first digit [exluding the sign] of the number]
+   * to the first digit [exluding the sign] of the number
    */
   bn_reverse ((unsigned char *)_s, digs);
 
@@ -83,3 +82,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix_n.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_unsigned_bin_size.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_unsigned_bin_size.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the size for an unsigned equivalent */
@@ -22,3 +22,7 @@
   return (size / 8 + ((size & 7) != 0 ? 1 : 0));
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_xor.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_xor.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* XOR two ints together */
@@ -45,3 +45,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_mp_zero.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_mp_zero.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set to zero */
@@ -30,3 +30,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_prime_tab.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_prime_tab.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 const mp_digit ltm_prime_tab[] = {
   0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
@@ -55,3 +55,7 @@
 #endif
 };
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_prime_tab.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_reverse.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_reverse.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reverse an array, used for radix code */
@@ -33,3 +33,7 @@
   }
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_add.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_add.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
@@ -103,3 +103,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_add.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_exptmod.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_exptmod.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,9 +12,8 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
-
 #ifdef MP_LOW_MEM
    #define TAB_SIZE 32
 #else
@@ -247,3 +246,7 @@
   return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_mul_digs.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_mul_digs.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplies |a| * |b| and only computes upto digs digits of result
@@ -84,3 +84,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_mul_high_digs.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_mul_high_digs.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplies |a| * |b| and does not compute the lower digs digits
@@ -75,3 +75,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_sqr.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_sqr.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
@@ -78,3 +78,7 @@
   return MP_OKAY;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bn_s_mp_sub.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bn_s_mp_sub.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
@@ -83,3 +83,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sub.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/bncore.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/bncore.c	Thu Jan 11 03:11:15 2007 +0000
@@ -12,7 +12,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Known optimal configurations
@@ -20,13 +20,17 @@
  CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
 -------------------------------------------------------------
  Intel P4 Northwood     /GCC v3.4.1   /        88/       128/LTM 0.32 ;-)
- AMD Athlon64           /GCC v3.4.4   /        74/       124/LTM 0.34
+ AMD Athlon64           /GCC v3.4.4   /        80/       120/LTM 0.35
  
 */
 
-int     KARATSUBA_MUL_CUTOFF = 74,      /* Min. number of digits before Karatsuba multiplication is used. */
-        KARATSUBA_SQR_CUTOFF = 124,     /* Min. number of digits before Karatsuba squaring is used. */
+int     KARATSUBA_MUL_CUTOFF = 80,      /* Min. number of digits before Karatsuba multiplication is used. */
+        KARATSUBA_SQR_CUTOFF = 120,     /* Min. number of digits before Karatsuba squaring is used. */
         
         TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
         TOOM_SQR_CUTOFF      = 400; 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/bncore.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
--- a/booker.pl	Wed Mar 08 13:16:18 2006 +0000
+++ b/booker.pl	Thu Jan 11 03:11:15 2007 +0000
@@ -82,13 +82,16 @@
          # scan till next end of comment, e.g. skip license 
          while (<SRC>) {
             $text[$line++] = $_;
-            last if ($_ =~ /math\.libtomcrypt\.org/);
+            last if ($_ =~ /math\.libtomcrypt\.com/);
          }
          <SRC>;   
       }
       
       $inline = 0;
       while (<SRC>) {
+      next if ($_ =~ /\$Source/);
+      next if ($_ =~ /\$Revision/);
+      next if ($_ =~ /\$Date/);
          $text[$line++] = $_;
          ++$inline;
          chomp($_);
@@ -218,7 +221,7 @@
                      $str = "chapter eight";
                   } elsif ($a == 9) {
                      $str = "chapter nine";
-                  } elsif ($a == 2) {
+                  } elsif ($a == 10) {
                      $str = "chapter ten";
                   }
                } else {
--- a/changes.txt	Wed Mar 08 13:16:18 2006 +0000
+++ b/changes.txt	Thu Jan 11 03:11:15 2007 +0000
@@ -1,3 +1,36 @@
+December 24th, 2006
+v0.40  -- Updated makefile to properly support LIBNAME
+       -- Fixed bug in fast_s_mp_mul_high_digs() which overflowed (line 83), thanks Valgrind!
+
+April 4th, 2006
+v0.39  -- Jim Wigginton pointed out my Montgomery examples in figures 6.4 and 6.6 were off by one, k should be 9 not 8
+       -- Bruce Guenter suggested I use --tag=CC for libtool builds where the compiler may think it's C++.
+       -- "mm" from sci.crypt pointed out that my mp_gcd was sub-optimal (I also updated and corrected the book)
+       -- updated some of the @@ tags in tommath.src to reflect source changes.
+       -- updated email and url info in all source files
+
+Jan 26th, 2006
+v0.38  -- broken makefile.shared fixed
+       -- removed some carry stores that were not required [updated text]
+       
+November 18th, 2005
+v0.37  -- [Don Porter] reported on a TCL list [HEY SEND ME BUGREPORTS ALREADY!!!] that mp_add_d() would compute -0 with some inputs.  Fixed.
+       -- [[email protected]] reported the makefile.bcc was messed up.  Fixed.
+       -- [Kevin Kenny] reported some issues with mp_toradix_n().  Now it doesn't require a min of 3 chars of output.  
+       -- Made the make command renamable.  Wee
+
+August 1st, 2005
+v0.36  -- LTM_PRIME_2MSB_ON was fixed and the "OFF" flag was removed.
+       -- [Peter LaDow] found a typo in the XREALLOC macro
+       -- [Peter LaDow] pointed out that mp_read_(un)signed_bin should have "const" on the input
+       -- Ported LTC patch to fix the prime_random_ex() function to get the bitsize correct [and the maskOR flags]
+       -- Kevin Kenny pointed out a stray //
+       -- David Hulton pointed out a typo in the textbook [mp_montgomery_setup() pseudo-code]
+       -- Neal Hamilton (Elliptic Semiconductor) pointed out that my Karatsuba notation was backwards and that I could use 
+          unsigned operations in the routine.  
+       -- Paul Schmidt pointed out a linking error in mp_exptmod() when BN_S_MP_EXPTMOD_C is undefined (and another for read_radix)
+       -- Updated makefiles to be way more flexible
+
 March 12th, 2005
 v0.35  -- Stupid XOR function missing line again... oops.
        -- Fixed bug in invmod not handling negative inputs correctly [Wolfgang Ehrhardt]
--- a/demo/demo.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/demo/demo.c	Thu Jan 11 03:11:15 2007 +0000
@@ -389,8 +389,8 @@
       sub_d_n = 0;
 
    /* force KARA and TOOM to enable despite cutoffs */
-   KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 110;
-   TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 150;
+   KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
+   TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
 
    for (;;) {
       /* randomly clear and re-init one variable, this has the affect of triming the alloc space */
@@ -734,3 +734,7 @@
    }
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/demo/demo.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/06/24 11:32:07 $ */
--- a/demo/timing.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/demo/timing.c	Thu Jan 11 03:11:15 2007 +0000
@@ -313,3 +313,7 @@
 
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/demo/timing.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/etc/2kprime.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/2kprime.c	Thu Jan 11 03:11:15 2007 +0000
@@ -78,3 +78,7 @@
             
             
           
+
+/* $Source: /cvs/libtom/libtommath/etc/2kprime.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/etc/drprime.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/drprime.c	Thu Jan 11 03:11:15 2007 +0000
@@ -58,3 +58,7 @@
    return 0;
 }
 
+
+/* $Source: /cvs/libtom/libtommath/etc/drprime.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/etc/drprimes.txt	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/drprimes.txt	Thu Jan 11 03:11:15 2007 +0000
@@ -1,6 +1,9 @@
-280-bit prime:
-p == 1942668892225729070919461906823518906642406839052139521251812409738904285204940164839
+300-bit prime:
+p == 2037035976334486086268445688409378161051468393665936250636140449354381298610415201576637819
 
-532-bit prime:
-p == 14059105607947488696282932836518693308967803494693489478439861164411992439598399594747002144074658928593502845729752797260025831423419686528151609940203368691747
+540-bit prime:
+p == 3599131035634557106248430806148785487095757694641533306480604458089470064537190296255232548883112685719936728506816716098566612844395439751206810991770626477344739
 
+780-bit prime:
+p == 6359114106063703798370219984742410466332205126109989319225557147754704702203399726411277962562135973685197744935448875852478791860694279747355800678568677946181447581781401213133886609947027230004277244697462656003655947791725966271167
+
--- a/etc/makefile.icc	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/makefile.icc	Thu Jan 11 03:11:15 2007 +0000
@@ -16,7 +16,7 @@
 #   B - Blend of P4 and PM [mobile]
 #
 # Default to just generic max opts
-CFLAGS += -O3 -xN -ip
+CFLAGS += -O3 -xP -ip
 
 # default lib name (requires install with root)
 # LIBNAME=-ltommath
--- a/etc/mersenne.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/mersenne.c	Thu Jan 11 03:11:15 2007 +0000
@@ -1,6 +1,6 @@
 /* Finds Mersenne primes using the Lucas-Lehmer test 
  *
- * Tom St Denis, [email protected]
+ * Tom St Denis, [email protected]
  */
 #include <time.h>
 #include <tommath.h>
@@ -138,3 +138,7 @@
   }
   return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/etc/mersenne.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:47 $ */
--- a/etc/mont.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/mont.c	Thu Jan 11 03:11:15 2007 +0000
@@ -44,3 +44,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtommath/etc/mont.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/etc/pprime.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/pprime.c	Thu Jan 11 03:11:15 2007 +0000
@@ -1,8 +1,8 @@
 /* Generates provable primes
  *
- * See http://iahu.ca:8080/papers/pp.pdf for more info.
+ * See http://gmail.com:8080/papers/pp.pdf for more info.
  *
- * Tom St Denis, [email protected], http://tom.iahu.ca
+ * Tom St Denis, [email protected], http://tom.gmail.com
  */
 #include <time.h>
 #include "tommath.h"
@@ -394,3 +394,7 @@
 
   return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/etc/pprime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:47 $ */
--- a/etc/tune.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/etc/tune.c	Thu Jan 11 03:11:15 2007 +0000
@@ -1,6 +1,6 @@
 /* Tune the Karatsuba parameters
  *
- * Tom St Denis, [email protected]
+ * Tom St Denis, [email protected]
  */
 #include <tommath.h>
 #include <time.h>
@@ -136,3 +136,7 @@
 
   return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/etc/tune.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:47 $ */
--- a/logs/expt.log	Wed Mar 08 13:16:18 2006 +0000
+++ b/logs/expt.log	Thu Jan 11 03:11:15 2007 +0000
@@ -1,7 +1,7 @@
-513   1489160
-769   3688476
-1025   8162061
-2049  49260015
-2561  89579052
-3073 148797060
-4097 324449263
+513   1435869
+769   3544970
+1025   7791638
+2049  46902238
+2561  85334899
+3073 141451412
+4097 308770310
--- a/logs/expt_2k.log	Wed Mar 08 13:16:18 2006 +0000
+++ b/logs/expt_2k.log	Thu Jan 11 03:11:15 2007 +0000
@@ -1,5 +1,5 @@
-607   2272809
-1279   9557382
-2203  36250309
-3217  87666486
-4253 174168369
+607   2109225
+1279  10148314
+2203  34126877
+3217  82716424
+4253 161569606
--- a/logs/expt_2kl.log	Wed Mar 08 13:16:18 2006 +0000
+++ b/logs/expt_2kl.log	Thu Jan 11 03:11:15 2007 +0000
@@ -1,4 +1,4 @@
-1024   6954080
-2048  35993987
-4096 176068521
-521   1683720
+1024   7705271
+2048  34286851
+4096 165207491
+521   1618631
--- a/logs/expt_dr.log	Wed Mar 08 13:16:18 2006 +0000
+++ b/logs/expt_dr.log	Thu Jan 11 03:11:15 2007 +0000
@@ -1,7 +1,7 @@
-532   1989592
-784   3898697
-1036   6519700
-1540  15676650
-2072  33128187
-3080  82963362
-4116 168358337
+532   1928550
+784   3763908
+1036   7564221
+1540  16566059
+2072  32283784
+3080  79851565
+4116 157843530
--- a/logs/index.html	Wed Mar 08 13:16:18 2006 +0000
+++ b/logs/index.html	Thu Jan 11 03:11:15 2007 +0000
@@ -21,4 +21,7 @@
 <hr>
 
 </body>
-</html>
\ No newline at end of file
+</html>
+/* $Source: /cvs/libtom/libtommath/logs/index.html,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/logs/sqr.old	Wed Mar 08 13:16:18 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-896    382617
-1344    207161
-1792    131522
-2240     90775
-2688     66652
-3136     50955
-3584     11678
-4032      9342
-4480      7684
-4928      6382
-5376      5399
-5824      4545
-6272      3994
-6720      3490
-7168      3075
-7616      2733
-8064      2428
--- a/makefile	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile	Thu Jan 11 03:11:15 2007 +0000
@@ -3,12 +3,18 @@
 #Tom St Denis
 
 #version of library 
-VERSION=0.35
+VERSION=0.40
 
 CFLAGS  +=  -I./ -Wall -W -Wshadow -Wsign-compare
 
+ifndef MAKE
+   MAKE=make
+endif
+
+ifndef IGNORE_SPEED
+
 #for speed 
-CFLAGS += -O3 -funroll-all-loops
+CFLAGS += -O3 -funroll-loops
 
 #for size 
 #CFLAGS += -Os
@@ -19,14 +25,28 @@
 #debug
 #CFLAGS += -g3
 
+endif
+
 #install as this user
-USER=root
-GROUP=root
+ifndef INSTALL_GROUP
+   GROUP=wheel
+else
+   GROUP=$(INSTALL_GROUP)
+endif
 
-default: libtommath.a
+ifndef INSTALL_USER
+   USER=root
+else
+   USER=$(INSTALL_USER)
+endif
 
 #default files to install
-LIBNAME=libtommath.a
+ifndef LIBNAME
+   LIBNAME=libtommath.a
+endif
+
+default: ${LIBNAME}
+
 HEADERS=tommath.h tommath_class.h tommath_superclass.h
 
 #LIBPATH-The directory for libtommath to be installed to.
@@ -65,9 +85,9 @@
 bn_mp_init_set_int.o bn_mp_invmod_slow.o bn_mp_prime_rabin_miller_trials.o \
 bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o
 
-libtommath.a:  $(OBJECTS)
-	$(AR) $(ARFLAGS) libtommath.a $(OBJECTS)
-	ranlib libtommath.a
+$(LIBNAME):  $(OBJECTS)
+	$(AR) $(ARFLAGS) $@ $(OBJECTS)
+	ranlib $@
 
 #make a profiled library (takes a while!!!)
 #
@@ -89,27 +109,27 @@
 	./ltmtest
 	rm -f *.o ltmtest
 	$(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
-	$(AR) $(ARFLAGS) libtommath.a mpi.o
-	ranlib libtommath.a	
+	$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
+	ranlib $(LIBNAME)	
 
-install: libtommath.a
+install: $(LIBNAME)
 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
 	install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
 	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
 
-test: libtommath.a demo/demo.o
-	$(CC) $(CFLAGS) demo/demo.o libtommath.a -o test
+test: $(LIBNAME) demo/demo.o
+	$(CC) $(CFLAGS) demo/demo.o $(LIBNAME) -o test
 	
 mtest: test	
 	cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest
         
-timing: libtommath.a
-	$(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest
+timing: $(LIBNAME)
+	$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o ltmtest
 
 # makes the LTM book DVI file, requires tetex, perl and makeindex [part of tetex I think]
 docdvi: tommath.src
-	cd pics ; make 
+	cd pics ; MAKE=${MAKE} ${MAKE} 
 	echo "hello" > tommath.ind
 	perl booker.pl
 	latex tommath > /dev/null
@@ -126,7 +146,7 @@
 docs:   docdvi
 	dvipdf tommath
 	rm -f tommath.log tommath.aux tommath.dvi tommath.idx tommath.toc tommath.lof tommath.ind tommath.ilg
-	cd pics ; make clean
+	cd pics ; MAKE=${MAKE} ${MAKE} clean
 	
 #LTM user manual
 mandvi: bn.tex
@@ -146,14 +166,21 @@
 
 clean:
 	rm -f *.bat *.pdf *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test ltmtest mpitest mtest/mtest mtest/mtest.exe \
-        *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.da *.dyn *.dpi tommath.tex `find -type f | grep [~] | xargs` *.lo *.la
+        *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.da *.dyn *.dpi tommath.tex `find . -type f | grep [~] | xargs` *.lo *.la
 	rm -rf .libs
-	cd etc ; make clean
-	cd pics ; make clean
+	cd etc ; MAKE=${MAKE} ${MAKE} clean
+	cd pics ; MAKE=${MAKE} ${MAKE} clean
+
+#zipup the project (take that!)
+no_oops: clean
+	cd .. ; cvs commit 
+	echo Scanning for scratch/dirty files
+	find . -type f | grep -v CVS | xargs -n 1 bash mess.sh
 
 zipup: clean manual poster docs
 	perl gen.pl ; mv mpi.c pre_gen/ ; \
 	cd .. ; rm -rf ltm* libtommath-$(VERSION) ; mkdir libtommath-$(VERSION) ; \
 	cp -R ./libtommath/* ./libtommath-$(VERSION)/ ; \
 	tar -c libtommath-$(VERSION)/* | bzip2 -9vvc > ltm-$(VERSION).tar.bz2 ; \
-	zip -9 -r ltm-$(VERSION).zip libtommath-$(VERSION)/*
+	zip -9 -r ltm-$(VERSION).zip libtommath-$(VERSION)/* ; \
+	mv -f ltm* ~ ; rm -rf libtommath-$(VERSION)
--- a/makefile.bcc	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile.bcc	Thu Jan 11 03:11:15 2007 +0000
@@ -39,6 +39,6 @@
 
 $(TARGET): $(OBJECTS)
 
-.c.objbjbjbj:
+.c.obj:
 	$(CC) $(CFLAGS) $<
 	$(LIB) $(TARGET) -+$@
--- a/makefile.cygwin_dll	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile.cygwin_dll	Thu Jan 11 03:11:15 2007 +0000
@@ -49,3 +49,7 @@
 test: $(OBJECTS) windll
 	gcc $(CFLAGS) demo/demo.c libtommath.dll.a -Wl,--enable-auto-import -o test -s
 	cd mtest ; $(CC) -O3 -fomit-frame-pointer -funroll-loops mtest.c -o mtest -s
+
+/* $Source: /cvs/libtom/libtommath/makefile.cygwin_dll,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:45 $ */
--- a/makefile.icc	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile.icc	Thu Jan 11 03:11:15 2007 +0000
@@ -19,7 +19,7 @@
 #   B - Blend of P4 and PM [mobile]
 #
 # Default to just generic max opts
-CFLAGS += -O3 -xN
+CFLAGS += -O3 -xP -ip
 
 #install as this user
 USER=root
--- a/makefile.msvc	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile.msvc	Thu Jan 11 03:11:15 2007 +0000
@@ -2,7 +2,7 @@
 #
 #Tom St Denis
 
-CFLAGS = /I. /Ox /DWIN32 /W4
+CFLAGS = /I. /Ox /DWIN32 /W3 /Fo$@
 
 default: library
 
@@ -34,5 +34,7 @@
 bn_mp_init_set.obj bn_mp_init_set_int.obj bn_mp_invmod_slow.obj bn_mp_prime_rabin_miller_trials.obj \
 bn_mp_to_signed_bin_n.obj bn_mp_to_unsigned_bin_n.obj
 
+HEADERS=tommath.h tommath_class.h tommath_superclass.h
+
 library: $(OBJECTS)
 	lib /out:tommath.lib $(OBJECTS)
--- a/makefile.shared	Wed Mar 08 13:16:18 2006 +0000
+++ b/makefile.shared	Thu Jan 11 03:11:15 2007 +0000
@@ -1,11 +1,14 @@
 #Makefile for GCC
 #
 #Tom St Denis
-VERSION=0:35
+VERSION=0:40
+
+CC = libtool --mode=compile --tag=CC gcc
 
-CC = libtool --mode=compile gcc
 CFLAGS  +=  -I./ -Wall -W -Wshadow -Wsign-compare
 
+ifndef IGNORE_SPEED
+
 #for speed 
 CFLAGS += -O3 -funroll-loops
 
@@ -15,14 +18,30 @@
 #x86 optimizations [should be valid for any GCC install though]
 CFLAGS  += -fomit-frame-pointer
 
+endif
+
 #install as this user
-USER=root
-GROUP=root
+ifndef INSTALL_GROUP
+   GROUP=wheel
+else
+   GROUP=$(INSTALL_GROUP)
+endif
+
+ifndef INSTALL_USER
+   USER=root
+else
+   USER=$(INSTALL_USER)
+endif
 
 default: libtommath.la
 
 #default files to install
-LIBNAME=libtommath.la
+ifndef LIBNAME
+   LIBNAME=libtommath.la
+endif
+ifndef LIBNAME_S
+   LIBNAME_S=libtommath.a
+endif
 HEADERS=tommath.h tommath_class.h tommath_superclass.h
 
 #LIBPATH-The directory for libtommath to be installed to.
@@ -61,20 +80,23 @@
 bn_mp_init_set_int.o bn_mp_invmod_slow.o bn_mp_prime_rabin_miller_trials.o \
 bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o
 
+objs: $(OBJECTS)
 
-libtommath.la:  $(OBJECTS)
-	libtool --mode=link gcc *.lo -o libtommath.la -rpath $(LIBPATH) -version-info $(VERSION)
-	libtool --mode=link gcc *.o -o libtommath.a 
-	libtool --mode=install install -c libtommath.la $(LIBPATH)/libtommath.la
+$(LIBNAME):  $(OBJECTS)
+	libtool --mode=link gcc *.lo -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION)
+
+install: $(LIBNAME)
+	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
+	libtool --mode=install install -c $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME)
 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
 	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
 
-test: libtommath.a demo/demo.o
+test: $(LIBNAME) demo/demo.o
 	gcc $(CFLAGS) -c demo/demo.c -o demo/demo.o
-	libtool --mode=link gcc -o test demo/demo.o libtommath.la
+	libtool --mode=link gcc -o test demo/demo.o $(LIBNAME_S)
 	
 mtest: test	
-	cd mtest ; gcc $(CFLAGS) mtest.c -o mtest -s
+	cd mtest ; gcc $(CFLAGS) mtest.c -o mtest
         
-timing: libtommath.la
-	gcc $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest -s
+timing: $(LIBNAME)
+	gcc $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME_S) -o ltmtest
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mess.sh	Thu Jan 11 03:11:15 2007 +0000
@@ -0,0 +1,4 @@
+#!/bin/bash
+if cvs log $1 >/dev/null 2>/dev/null; then exit 0; else echo "$1 shouldn't be here" ; exit 1; fi
+
+
--- a/mtest/logtab.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/logtab.h	Thu Jan 11 03:11:15 2007 +0000
@@ -18,3 +18,7 @@
    0.166666667
 };
 
+
+/* $Source: /cvs/libtom/libtommath/mtest/logtab.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/mtest/mpi-config.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/mpi-config.h	Thu Jan 11 03:11:15 2007 +0000
@@ -1,5 +1,5 @@
 /* Default configuration for MPI library */
-/* $Id: mpi-config.h,v 1.8 2000/07/11 04:28:14 sting Exp sting $ */
+/* $Id: mpi-config.h,v 1.2 2005/05/05 14:38:47 tom Exp $ */
 
 #ifndef MPI_CONFIG_H_
 #define MPI_CONFIG_H_
@@ -84,3 +84,7 @@
 
 
 /* crc==3287762869, version==2, Sat Feb 02 06:43:53 2002 */
+
+/* $Source: /cvs/libtom/libtommath/mtest/mpi-config.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/mtest/mpi-types.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/mpi-types.h	Thu Jan 11 03:11:15 2007 +0000
@@ -14,3 +14,7 @@
 #define DIGIT_FMT          "%04X"
 #define RADIX              (MP_DIGIT_MAX+1)
 
+
+/* $Source: /cvs/libtom/libtommath/mtest/mpi-types.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/mtest/mpi.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/mpi.c	Thu Jan 11 03:11:15 2007 +0000
@@ -6,7 +6,7 @@
 
     Arbitrary precision integer arithmetic library
 
-    $Id: mpi.c,v 1.22 2001/09/14 15:11:20 sting Exp sting $
+    $Id: mpi.c,v 1.2 2005/05/05 14:38:47 tom Exp $
  */
 
 #include "mpi.h"
@@ -3979,3 +3979,7 @@
 /*------------------------------------------------------------------------*/
 /* HERE THERE BE DRAGONS                                                  */
 /* crc==4242132123, version==2, Sat Feb 02 06:43:52 2002 */
+
+/* $Source: /cvs/libtom/libtommath/mtest/mpi.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/mtest/mpi.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/mpi.h	Thu Jan 11 03:11:15 2007 +0000
@@ -6,7 +6,7 @@
 
     Arbitrary precision integer arithmetic library
 
-    $Id: mpi.h,v 1.15 2001/09/17 14:16:22 sting Exp $
+    $Id: mpi.h,v 1.2 2005/05/05 14:38:47 tom Exp $
  */
 
 #ifndef _H_MPI_
@@ -225,3 +225,7 @@
 const  char  *mp_strerror(mp_err ec);
 
 #endif /* end _H_MPI_ */
+
+/* $Source: /cvs/libtom/libtommath/mtest/mpi.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
--- a/mtest/mtest.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/mtest/mtest.c	Thu Jan 11 03:11:15 2007 +0000
@@ -302,3 +302,7 @@
    fclose(rng);
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtommath/mtest/mtest.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:38:47 $ */
Binary file poster.pdf has changed
--- a/pre_gen/mpi.c	Wed Mar 08 13:16:18 2006 +0000
+++ b/pre_gen/mpi.c	Thu Jan 11 03:11:15 2007 +0000
@@ -13,7 +13,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static const struct {
@@ -43,6 +43,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_error.c */
 
 /* Start: bn_fast_mp_invmod.c */
@@ -60,7 +64,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes the modular inverse via binary extended euclidean algorithm, 
@@ -191,6 +195,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_fast_mp_invmod.c */
 
 /* Start: bn_fast_mp_montgomery_reduce.c */
@@ -208,7 +216,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction
@@ -363,6 +371,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_montgomery_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_fast_mp_montgomery_reduce.c */
 
 /* Start: bn_fast_s_mp_mul_digs.c */
@@ -380,7 +392,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Fast (comba) multiplier
@@ -438,6 +450,7 @@
       /* execute loop */
       for (iz = 0; iz < iy; ++iz) {
          _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
+
       }
 
       /* store term */
@@ -445,10 +458,7 @@
 
       /* make next carry */
       _W = _W >> ((mp_word)DIGIT_BIT);
-  }
-
-  /* store final carry */
-  W[ix] = (mp_digit)(_W & MP_MASK);
+ }
 
   /* setup dest */
   olduse  = c->used;
@@ -472,6 +482,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_fast_s_mp_mul_digs.c */
 
 /* Start: bn_fast_s_mp_mul_high_digs.c */
@@ -489,7 +503,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* this is a modified version of fast_s_mul_digs that only produces
@@ -547,9 +561,6 @@
       _W = _W >> ((mp_word)DIGIT_BIT);
   }
   
-  /* store final carry */
-  W[ix] = (mp_digit)(_W & MP_MASK);
-
   /* setup dest */
   olduse  = c->used;
   c->used = pa;
@@ -558,7 +569,7 @@
     register mp_digit *tmpc;
 
     tmpc = c->dp + digs;
-    for (ix = digs; ix <= pa; ix++) {
+    for (ix = digs; ix < pa; ix++) {
       /* now extract the previous digit [below the carry] */
       *tmpc++ = W[ix];
     }
@@ -573,6 +584,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_high_digs.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/11/14 03:46:25 $ */
+
 /* End: bn_fast_s_mp_mul_high_digs.c */
 
 /* Start: bn_fast_s_mp_sqr.c */
@@ -590,7 +605,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* the jist of squaring...
@@ -687,6 +702,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_fast_s_mp_sqr.c */
 
 /* Start: bn_mp_2expt.c */
@@ -704,7 +723,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes a = 2**b 
@@ -735,6 +754,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_2expt.c */
 
 /* Start: bn_mp_abs.c */
@@ -752,7 +775,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = |a| 
@@ -778,6 +801,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_abs.c */
 
 /* Start: bn_mp_add.c */
@@ -795,7 +822,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level addition (handles signs) */
@@ -831,6 +858,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_add.c */
 
 /* Start: bn_mp_add_d.c */
@@ -848,7 +879,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* single digit addition */
@@ -876,6 +907,9 @@
      /* fix sign  */
      a->sign = c->sign = MP_NEG;
 
+     /* clamp */
+     mp_clamp(c);
+
      return res;
   }
 
@@ -940,6 +974,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_add_d.c */
 
 /* Start: bn_mp_addmod.c */
@@ -957,7 +995,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a + b (mod c) */
@@ -981,6 +1019,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_addmod.c */
 
 /* Start: bn_mp_and.c */
@@ -998,7 +1040,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* AND two ints together */
@@ -1038,6 +1080,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_and.c */
 
 /* Start: bn_mp_clamp.c */
@@ -1055,7 +1101,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* trim unused digits 
@@ -1082,6 +1128,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_clamp.c */
 
 /* Start: bn_mp_clear.c */
@@ -1099,7 +1149,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* clear one (frees)  */
@@ -1126,6 +1176,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_clear.c */
 
 /* Start: bn_mp_clear_multi.c */
@@ -1143,7 +1197,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 #include <stdarg.h>
 
@@ -1160,6 +1214,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_clear_multi.c */
 
 /* Start: bn_mp_cmp.c */
@@ -1177,7 +1235,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare two ints (signed)*/
@@ -1203,6 +1261,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_cmp.c */
 
 /* Start: bn_mp_cmp_d.c */
@@ -1220,7 +1282,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare a digit */
@@ -1247,6 +1309,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_cmp_d.c */
 
 /* Start: bn_mp_cmp_mag.c */
@@ -1264,7 +1330,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* compare maginitude of two ints (unsigned) */
@@ -1302,6 +1368,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_cmp_mag.c */
 
 /* Start: bn_mp_cnt_lsb.c */
@@ -1319,7 +1389,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static const int lnz[16] = { 
@@ -1355,6 +1425,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_cnt_lsb.c */
 
 /* Start: bn_mp_copy.c */
@@ -1372,7 +1446,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* copy, b = a */
@@ -1423,6 +1497,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_copy.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_copy.c */
 
 /* Start: bn_mp_count_bits.c */
@@ -1440,7 +1518,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* returns the number of bits in an int */
@@ -1468,6 +1546,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_count_bits.c */
 
 /* Start: bn_mp_div.c */
@@ -1485,7 +1567,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 #ifdef BN_MP_DIV_SMALL
@@ -1760,6 +1842,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_div.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_div.c */
 
 /* Start: bn_mp_div_2.c */
@@ -1777,7 +1863,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = a/2 */
@@ -1828,6 +1914,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_div_2.c */
 
 /* Start: bn_mp_div_2d.c */
@@ -1845,7 +1935,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
@@ -1925,6 +2015,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_div_2d.c */
 
 /* Start: bn_mp_div_3.c */
@@ -1942,7 +2036,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* divide by three (based on routine from MPI and the GMP manual) */
@@ -2004,6 +2098,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_3.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_div_3.c */
 
 /* Start: bn_mp_div_d.c */
@@ -2021,7 +2119,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 static int s_is_power_of_two(mp_digit b, int *p)
@@ -2114,6 +2212,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_div_d.c */
 
 /* Start: bn_mp_dr_is_modulus.c */
@@ -2131,7 +2233,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if a number is a valid DR modulus */
@@ -2157,6 +2259,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_dr_is_modulus.c */
 
 /* Start: bn_mp_dr_reduce.c */
@@ -2174,7 +2280,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
@@ -2251,6 +2357,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_dr_reduce.c */
 
 /* Start: bn_mp_dr_setup.c */
@@ -2268,7 +2378,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -2283,6 +2393,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_dr_setup.c */
 
 /* Start: bn_mp_exch.c */
@@ -2300,7 +2414,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* swap the elements of two integers, for cases where you can't simply swap the 
@@ -2317,6 +2431,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_exch.c */
 
 /* Start: bn_mp_expt_d.c */
@@ -2334,7 +2452,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* calculate c = a**b  using a square-multiply algorithm */
@@ -2374,6 +2492,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_expt_d.c */
 
 /* Start: bn_mp_exptmod.c */
@@ -2391,7 +2513,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 
@@ -2445,7 +2567,7 @@
   }
 
 /* modified diminished radix reduction */
-#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C)
+#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
   if (mp_reduce_is_2k_l(P) == MP_YES) {
      return s_mp_exptmod(G, X, P, Y, 1);
   }
@@ -2486,6 +2608,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_exptmod.c */
 
 /* Start: bn_mp_exptmod_fast.c */
@@ -2503,7 +2629,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
@@ -2807,6 +2933,10 @@
 #endif
 
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod_fast.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_exptmod_fast.c */
 
 /* Start: bn_mp_exteuclid.c */
@@ -2824,7 +2954,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Extended euclidean algorithm of (a, b) produces 
@@ -2889,6 +3019,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_exteuclid.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_exteuclid.c */
 
 /* Start: bn_mp_fread.c */
@@ -2906,7 +3040,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read a bigint from a file stream in ASCII */
@@ -2956,6 +3090,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_fread.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_fread.c */
 
 /* Start: bn_mp_fwrite.c */
@@ -2973,7 +3111,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 int mp_fwrite(mp_int *a, int radix, FILE *stream)
@@ -3008,6 +3146,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_fwrite.c */
 
 /* Start: bn_mp_gcd.c */
@@ -3025,7 +3167,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Greatest Common Divisor using the binary method */
@@ -3035,21 +3177,13 @@
   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;
@@ -3121,6 +3255,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_gcd.c */
 
 /* Start: bn_mp_get_int.c */
@@ -3138,7 +3276,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the lower 32-bits of an mp_int */
@@ -3166,6 +3304,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_get_int.c */
 
 /* Start: bn_mp_grow.c */
@@ -3183,7 +3325,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* grow as required */
@@ -3223,6 +3365,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_grow.c */
 
 /* Start: bn_mp_init.c */
@@ -3240,7 +3386,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* init a new mp_int */
@@ -3269,6 +3415,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init.c */
 
 /* Start: bn_mp_init_copy.c */
@@ -3286,7 +3436,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* creates "a" then copies b into it */
@@ -3301,6 +3451,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init_copy.c */
 
 /* Start: bn_mp_init_multi.c */
@@ -3318,7 +3472,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 #include <stdarg.h>
 
@@ -3360,6 +3514,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init_multi.c */
 
 /* Start: bn_mp_init_set.c */
@@ -3377,7 +3535,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* initialize and set a digit */
@@ -3392,6 +3550,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init_set.c */
 
 /* Start: bn_mp_init_set_int.c */
@@ -3409,7 +3571,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* initialize and set a digit */
@@ -3423,6 +3585,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init_set_int.c */
 
 /* Start: bn_mp_init_size.c */
@@ -3440,7 +3606,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* init an mp_init for a given size */
@@ -3471,6 +3637,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_init_size.c */
 
 /* Start: bn_mp_invmod.c */
@@ -3488,7 +3658,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* hac 14.61, pp608 */
@@ -3514,6 +3684,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_invmod.c */
 
 /* Start: bn_mp_invmod_slow.c */
@@ -3531,7 +3705,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* hac 14.61, pp608 */
@@ -3689,6 +3863,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod_slow.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_invmod_slow.c */
 
 /* Start: bn_mp_is_square.c */
@@ -3706,7 +3884,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Check if remainders are possible squares - fast exclude non-squares */
@@ -3798,6 +3976,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_is_square.c */
 
 /* Start: bn_mp_jacobi.c */
@@ -3815,7 +3997,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes the jacobi c = (a | n) (or Legendre if n is prime)
@@ -3903,6 +4085,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_jacobi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_jacobi.c */
 
 /* Start: bn_mp_karatsuba_mul.c */
@@ -3920,7 +4106,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = |a| * |b| using Karatsuba Multiplication using 
@@ -3934,12 +4120,12 @@
  * b = b1 * B**n + b0
  *
  * Then, a * b => 
-   a1b1 * B**2n + ((a1 - a0)(b1 - b0) + a0b0 + a1b1) * B + a0b0
+   a1b1 * B**2n + ((a1 + a0)(b1 + b0) - (a0b0 + a1b1)) * B + a0b0
  *
  * Note that a1b1 and a0b0 are used twice and only need to be 
  * computed once.  So in total three half size (half # of 
  * digit) multiplications are performed, a0b0, a1b1 and 
- * (a1-b1)(a0-b0)
+ * (a1+b1)(a0+b0)
  *
  * Note that a multiplication of half the digits requires
  * 1/4th the number of single precision multiplications so in 
@@ -4030,19 +4216,19 @@
   if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
     goto X1Y1;          /* x1y1 = x1*y1 */
 
-  /* now calc x1-x0 and y1-y0 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+  /* now calc x1+x0 and y1+y0 */
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
     goto X1Y1;          /* t1 = x1 - x0 */
-  if (mp_sub (&y1, &y0, &x0) != MP_OKAY)
+  if (s_mp_add (&y1, &y0, &x0) != MP_OKAY)
     goto X1Y1;          /* t2 = y1 - y0 */
   if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = (x1 - x0) * (y1 - y0) */
+    goto X1Y1;          /* t1 = (x1 + x0) * (y1 + y0) */
 
   /* add x0y0 */
   if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
     goto X1Y1;          /* t2 = x0y0 + x1y1 */
-  if (mp_sub (&x0, &t1, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = x0y0 + x1y1 - (x1-x0)*(y1-y0) */
+  if (s_mp_sub (&t1, &x0, &t1) != MP_OKAY)
+    goto X1Y1;          /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
 
   /* shift by B */
   if (mp_lshd (&t1, B) != MP_OKAY)
@@ -4070,6 +4256,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_mul.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_karatsuba_mul.c */
 
 /* Start: bn_mp_karatsuba_sqr.c */
@@ -4087,7 +4277,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Karatsuba squaring, computes b = a*a using three 
@@ -4155,8 +4345,8 @@
   if (mp_sqr (&x1, &x1x1) != MP_OKAY)
     goto X1X1;           /* x1x1 = x1*x1 */
 
-  /* now calc (x1-x0)**2 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+  /* now calc (x1+x0)**2 */
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
     goto X1X1;           /* t1 = x1 - x0 */
   if (mp_sqr (&t1, &t1) != MP_OKAY)
     goto X1X1;           /* t1 = (x1 - x0) * (x1 - x0) */
@@ -4164,8 +4354,8 @@
   /* add x0y0 */
   if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
     goto X1X1;           /* t2 = x0x0 + x1x1 */
-  if (mp_sub (&t2, &t1, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */
+  if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
+    goto X1X1;           /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
 
   /* shift by B */
   if (mp_lshd (&t1, B) != MP_OKAY)
@@ -4191,6 +4381,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_karatsuba_sqr.c */
 
 /* Start: bn_mp_lcm.c */
@@ -4208,7 +4402,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes least common multiple as |a*b|/(a, b) */
@@ -4251,6 +4445,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_lcm.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_lcm.c */
 
 /* Start: bn_mp_lshd.c */
@@ -4268,7 +4466,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift left a certain amount of digits */
@@ -4318,6 +4516,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_lshd.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_lshd.c */
 
 /* Start: bn_mp_mod.c */
@@ -4335,7 +4537,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = a mod b, 0 <= c < b */
@@ -4366,6 +4568,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mod.c */
 
 /* Start: bn_mp_mod_2d.c */
@@ -4383,7 +4589,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* calc a value mod 2**b */
@@ -4421,6 +4627,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mod_2d.c */
 
 /* Start: bn_mp_mod_d.c */
@@ -4438,7 +4648,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 int
@@ -4448,6 +4658,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mod_d.c */
 
 /* Start: bn_mp_montgomery_calc_normalization.c */
@@ -4465,7 +4679,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /*
@@ -4507,6 +4721,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_calc_normalization.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_montgomery_calc_normalization.c */
 
 /* Start: bn_mp_montgomery_reduce.c */
@@ -4524,7 +4742,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction */
@@ -4625,6 +4843,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_montgomery_reduce.c */
 
 /* Start: bn_mp_montgomery_setup.c */
@@ -4642,7 +4864,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* setups the montgomery reduction stuff */
@@ -4678,12 +4900,16 @@
 #endif
 
   /* rho = -1/m mod b */
-  *rho = (((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
+  *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
 
   return MP_OKAY;
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_setup.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/12/04 21:34:03 $ */
+
 /* End: bn_mp_montgomery_setup.c */
 
 /* Start: bn_mp_mul.c */
@@ -4701,7 +4927,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level multiplication (handles sign) */
@@ -4750,6 +4976,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mul.c */
 
 /* Start: bn_mp_mul_2.c */
@@ -4767,7 +4997,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = a*2 */
@@ -4832,6 +5062,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mul_2.c */
 
 /* Start: bn_mp_mul_2d.c */
@@ -4849,7 +5083,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift left by a certain bit count */
@@ -4917,6 +5151,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mul_2d.c */
 
 /* Start: bn_mp_mul_d.c */
@@ -4934,7 +5172,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiply by a digit */
@@ -4996,6 +5234,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_d.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mul_d.c */
 
 /* Start: bn_mp_mulmod.c */
@@ -5013,12 +5255,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a * b (mod c) */
-int
-mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
+int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
 {
   int     res;
   mp_int  t;
@@ -5037,6 +5278,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_mulmod.c */
 
 /* Start: bn_mp_n_root.c */
@@ -5054,7 +5299,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* find the n'th root of an integer 
@@ -5169,6 +5414,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_n_root.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_n_root.c */
 
 /* Start: bn_mp_neg.c */
@@ -5186,7 +5435,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* b = -a */
@@ -5209,6 +5458,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_neg.c */
 
 /* Start: bn_mp_or.c */
@@ -5226,7 +5479,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* OR two ints together */
@@ -5259,6 +5512,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_or.c */
 
 /* Start: bn_mp_prime_fermat.c */
@@ -5276,7 +5533,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* performs one Fermat test.
@@ -5321,6 +5578,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_fermat.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_fermat.c */
 
 /* Start: bn_mp_prime_is_divisible.c */
@@ -5338,7 +5599,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if an integers is divisible by one 
@@ -5371,6 +5632,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_is_divisible.c */
 
 /* Start: bn_mp_prime_is_prime.c */
@@ -5388,7 +5653,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* performs a variable number of rounds of Miller-Rabin
@@ -5454,6 +5719,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_is_prime.c */
 
 /* Start: bn_mp_prime_miller_rabin.c */
@@ -5471,7 +5740,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Miller-Rabin test of "a" to the base of "b" as described in 
@@ -5557,6 +5826,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_miller_rabin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_miller_rabin.c */
 
 /* Start: bn_mp_prime_next_prime.c */
@@ -5574,7 +5847,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* finds the next prime after the number "a" using "t" trials
@@ -5727,6 +6000,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_next_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_next_prime.c */
 
 /* Start: bn_mp_prime_rabin_miller_trials.c */
@@ -5744,7 +6021,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 
@@ -5779,6 +6056,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_rabin_miller_trials.c */
 
 /* Start: bn_mp_prime_random_ex.c */
@@ -5796,7 +6077,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* makes a truly random prime of a given size (bits),
@@ -5846,10 +6127,8 @@
    maskOR_msb        = 0;
    maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
    if (flags & LTM_PRIME_2MSB_ON) {
-      maskOR_msb     |= 1 << ((size - 2) & 7);
-   } else if (flags & LTM_PRIME_2MSB_OFF) {
-      maskAND        &= ~(1 << ((size - 2) & 7));
-   } 
+      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
+   }  
 
    /* get the maskOR_lsb */
    maskOR_lsb         = 1;
@@ -5906,6 +6185,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_random_ex.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_prime_random_ex.c */
 
 /* Start: bn_mp_radix_size.c */
@@ -5923,7 +6206,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* returns size of ASCII reprensentation */
@@ -5947,7 +6230,7 @@
   }
 
   if (mp_iszero(a) == MP_YES) {
-     *size = 2;
+    *size = 2;
     return MP_OKAY;
   }
 
@@ -5984,6 +6267,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_radix_size.c */
 
 /* Start: bn_mp_radix_smap.c */
@@ -6001,13 +6288,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* chars used in radix conversions */
 const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_radix_smap.c */
 
 /* Start: bn_mp_rand.c */
@@ -6025,7 +6316,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* makes a pseudo-random int of a given size */
@@ -6063,6 +6354,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_rand.c */
 
 /* Start: bn_mp_read_radix.c */
@@ -6080,7 +6375,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read a string [ASCII] in a given radix */
@@ -6089,6 +6384,9 @@
   int     y, res, neg;
   char    ch;
 
+  /* zero the digit bignum */
+  mp_zero(a);
+
   /* make sure the radix is ok */
   if (radix < 2 || radix > 64) {
     return MP_VAL;
@@ -6145,6 +6443,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_read_radix.c */
 
 /* Start: bn_mp_read_signed_bin.c */
@@ -6162,12 +6464,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
-int
-mp_read_signed_bin (mp_int * a, unsigned char *b, int c)
+int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -6187,6 +6488,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_read_signed_bin.c */
 
 /* Start: bn_mp_read_unsigned_bin.c */
@@ -6204,12 +6509,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
-int
-mp_read_unsigned_bin (mp_int * a, unsigned char *b, int c)
+int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -6243,6 +6547,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_read_unsigned_bin.c */
 
 /* Start: bn_mp_reduce.c */
@@ -6260,7 +6568,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces x mod m, assumes 0 < x < m**2, mu is 
@@ -6343,6 +6651,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce.c */
 
 /* Start: bn_mp_reduce_2k.c */
@@ -6360,7 +6672,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces a modulo n where n is of the form 2**p - d */
@@ -6404,6 +6716,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_2k.c */
 
 /* Start: bn_mp_reduce_2k_l.c */
@@ -6421,7 +6737,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reduces a modulo n where n is of the form 2**p - d 
@@ -6466,6 +6782,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_2k_l.c */
 
 /* Start: bn_mp_reduce_2k_setup.c */
@@ -6483,7 +6803,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -6513,6 +6833,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_2k_setup.c */
 
 /* Start: bn_mp_reduce_2k_setup_l.c */
@@ -6530,7 +6854,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines the setup value */
@@ -6557,6 +6881,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_2k_setup_l.c */
 
 /* Start: bn_mp_reduce_is_2k.c */
@@ -6574,7 +6902,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if mp_reduce_2k can be used */
@@ -6609,6 +6937,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_is_2k.c */
 
 /* Start: bn_mp_reduce_is_2k_l.c */
@@ -6626,7 +6958,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* determines if reduce_2k_l can be used */
@@ -6653,6 +6985,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_is_2k_l.c */
 
 /* Start: bn_mp_reduce_setup.c */
@@ -6670,7 +7006,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* pre-calculate the value required for Barrett reduction
@@ -6687,6 +7023,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_reduce_setup.c */
 
 /* Start: bn_mp_rshd.c */
@@ -6704,7 +7044,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shift right a certain amount of digits */
@@ -6759,6 +7099,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_rshd.c */
 
 /* Start: bn_mp_set.c */
@@ -6776,7 +7120,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set to a digit */
@@ -6788,6 +7132,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_set.c */
 
 /* Start: bn_mp_set_int.c */
@@ -6805,7 +7153,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set a 32-bit const */
@@ -6836,6 +7184,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_set_int.c */
 
 /* Start: bn_mp_shrink.c */
@@ -6853,7 +7205,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* shrink a bignum */
@@ -6871,6 +7223,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_shrink.c */
 
 /* Start: bn_mp_signed_bin_size.c */
@@ -6888,7 +7244,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the size for an signed equivalent */
@@ -6898,6 +7254,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_signed_bin_size.c */
 
 /* Start: bn_mp_sqr.c */
@@ -6915,7 +7275,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* computes b = a*a */
@@ -6956,6 +7316,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_sqr.c */
 
 /* Start: bn_mp_sqrmod.c */
@@ -6973,7 +7337,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* c = a * a (mod b) */
@@ -6997,6 +7361,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_sqrmod.c */
 
 /* Start: bn_mp_sqrt.c */
@@ -7014,7 +7382,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* this function is less generic than mp_n_root, simpler and faster */
@@ -7078,6 +7446,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_sqrt.c */
 
 /* Start: bn_mp_sub.c */
@@ -7095,7 +7467,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* high level subtraction (handles signs) */
@@ -7137,6 +7509,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_sub.c */
 
 /* Start: bn_mp_sub_d.c */
@@ -7154,7 +7530,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* single digit subtraction */
@@ -7178,6 +7554,10 @@
      a->sign = MP_ZPOS;
      res     = mp_add_d(a, b, c);
      a->sign = c->sign = MP_NEG;
+
+     /* clamp */
+     mp_clamp(c);
+
      return res;
   }
 
@@ -7226,6 +7606,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub_d.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_sub_d.c */
 
 /* Start: bn_mp_submod.c */
@@ -7243,7 +7627,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* d = a - b (mod c) */
@@ -7268,6 +7652,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_submod.c */
 
 /* Start: bn_mp_to_signed_bin.c */
@@ -7285,7 +7673,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in signed [big endian] format */
@@ -7301,6 +7689,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_to_signed_bin.c */
 
 /* Start: bn_mp_to_signed_bin_n.c */
@@ -7318,7 +7710,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in signed [big endian] format */
@@ -7332,6 +7724,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_to_signed_bin_n.c */
 
 /* Start: bn_mp_to_unsigned_bin.c */
@@ -7349,7 +7745,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in unsigned [big endian] format */
@@ -7380,6 +7776,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_to_unsigned_bin.c */
 
 /* Start: bn_mp_to_unsigned_bin_n.c */
@@ -7397,7 +7797,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* store in unsigned [big endian] format */
@@ -7411,6 +7811,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_to_unsigned_bin_n.c */
 
 /* Start: bn_mp_toom_mul.c */
@@ -7428,7 +7832,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplication using the Toom-Cook 3-way algorithm 
@@ -7695,6 +8099,10 @@
      
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_mul.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_toom_mul.c */
 
 /* Start: bn_mp_toom_sqr.c */
@@ -7712,7 +8120,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* squaring using Toom-Cook 3-way algorithm */
@@ -7921,6 +8329,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_toom_sqr.c */
 
 /* Start: bn_mp_toradix.c */
@@ -7938,7 +8350,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) */
@@ -7996,6 +8408,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_toradix.c */
 
 /* Start: bn_mp_toradix_n.c */
@@ -8013,7 +8429,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) 
@@ -8028,12 +8444,12 @@
   char   *_s = str;
 
   /* check range of the maxlen, radix */
-  if (maxlen < 3 || radix < 2 || radix > 64) {
+  if (maxlen < 2 || radix < 2 || radix > 64) {
     return MP_VAL;
   }
 
   /* quick out if its zero */
-  if (mp_iszero(a) == 1) {
+  if (mp_iszero(a) == MP_YES) {
      *str++ = '0';
      *str = '\0';
      return MP_OKAY;
@@ -8058,21 +8474,20 @@
 
   digs = 0;
   while (mp_iszero (&t) == 0) {
+    if (--maxlen < 1) {
+       /* no more room */
+       break;
+    }
     if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
       mp_clear (&t);
       return res;
     }
     *str++ = mp_s_rmap[d];
     ++digs;
-
-    if (--maxlen == 1) {
-       /* no more room */
-       break;
-    }
   }
 
   /* reverse the digits of the string.  In this case _s points
-   * to the first digit [exluding the sign] of the number]
+   * to the first digit [exluding the sign] of the number
    */
   bn_reverse ((unsigned char *)_s, digs);
 
@@ -8085,6 +8500,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix_n.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_toradix_n.c */
 
 /* Start: bn_mp_unsigned_bin_size.c */
@@ -8102,7 +8521,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* get the size for an unsigned equivalent */
@@ -8113,6 +8532,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_unsigned_bin_size.c */
 
 /* Start: bn_mp_xor.c */
@@ -8130,7 +8553,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* XOR two ints together */
@@ -8164,6 +8587,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_xor.c */
 
 /* Start: bn_mp_zero.c */
@@ -8181,7 +8608,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* set to zero */
@@ -8200,6 +8627,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_mp_zero.c */
 
 /* Start: bn_prime_tab.c */
@@ -8217,7 +8648,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 const mp_digit ltm_prime_tab[] = {
   0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
@@ -8261,6 +8692,10 @@
 };
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_prime_tab.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_prime_tab.c */
 
 /* Start: bn_reverse.c */
@@ -8278,7 +8713,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* reverse an array, used for radix code */
@@ -8300,6 +8735,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_reverse.c */
 
 /* Start: bn_s_mp_add.c */
@@ -8317,7 +8756,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
@@ -8409,6 +8848,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_add.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_add.c */
 
 /* Start: bn_s_mp_exptmod.c */
@@ -8426,9 +8869,8 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
- */
-
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ */
 #ifdef MP_LOW_MEM
    #define TAB_SIZE 32
 #else
@@ -8662,6 +9104,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_exptmod.c */
 
 /* Start: bn_s_mp_mul_digs.c */
@@ -8679,7 +9125,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplies |a| * |b| and only computes upto digs digits of result
@@ -8752,6 +9198,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_mul_digs.c */
 
 /* Start: bn_s_mp_mul_high_digs.c */
@@ -8769,7 +9219,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* multiplies |a| * |b| and does not compute the lower digs digits
@@ -8833,6 +9283,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_mul_high_digs.c */
 
 /* Start: bn_s_mp_sqr.c */
@@ -8850,7 +9304,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
@@ -8917,6 +9371,10 @@
 }
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_sqr.c */
 
 /* Start: bn_s_mp_sub.c */
@@ -8934,7 +9392,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
@@ -9006,6 +9464,10 @@
 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sub.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bn_s_mp_sub.c */
 
 /* Start: bncore.c */
@@ -9023,7 +9485,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 
 /* Known optimal configurations
@@ -9031,17 +9493,21 @@
  CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
 -------------------------------------------------------------
  Intel P4 Northwood     /GCC v3.4.1   /        88/       128/LTM 0.32 ;-)
- AMD Athlon64           /GCC v3.4.4   /        74/       124/LTM 0.34
+ AMD Athlon64           /GCC v3.4.4   /        80/       120/LTM 0.35
  
 */
 
-int     KARATSUBA_MUL_CUTOFF = 74,      /* Min. number of digits before Karatsuba multiplication is used. */
-        KARATSUBA_SQR_CUTOFF = 124,     /* Min. number of digits before Karatsuba squaring is used. */
+int     KARATSUBA_MUL_CUTOFF = 80,      /* Min. number of digits before Karatsuba multiplication is used. */
+        KARATSUBA_SQR_CUTOFF = 120,     /* Min. number of digits before Karatsuba squaring is used. */
         
         TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
         TOOM_SQR_CUTOFF      = 400; 
 #endif
 
+/* $Source: /cvs/libtom/libtommath/bncore.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
+
 /* End: bncore.c */
 
 
--- a/tommath.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/tommath.h	Thu Jan 11 03:11:15 2007 +0000
@@ -10,7 +10,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.org
+ * Tom St Denis, [email protected], http://math.libtomcrypt.com
  */
 #ifndef BN_H_
 #define BN_H_
@@ -23,10 +23,13 @@
 
 #include <tommath_class.h>
 
-#undef MIN
-#define MIN(x,y) ((x)<(y)?(x):(y))
-#undef MAX
-#define MAX(x,y) ((x)>(y)?(x):(y))
+#ifndef MIN
+   #define MIN(x,y) ((x)<(y)?(x):(y))
+#endif
+
+#ifndef MAX
+   #define MAX(x,y) ((x)>(y)?(x):(y))
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -112,7 +115,7 @@
    #else
       /* prototypes for our heap functions */
       extern void *XMALLOC(size_t n);
-      extern void *REALLOC(void *p, size_t n);
+      extern void *XREALLOC(void *p, size_t n);
       extern void *XCALLOC(size_t n, size_t s);
       extern void XFREE(void *p);
    #endif
@@ -147,7 +150,6 @@
 /* Primality generation flags */
 #define LTM_PRIME_BBS      0x0001 /* BBS style prime */
 #define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
-#define LTM_PRIME_2MSB_OFF 0x0004 /* force 2nd MSB to 0 */
 #define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
 
 typedef int           mp_err;
@@ -164,7 +166,7 @@
 /* default precision */
 #ifndef MP_PREC
    #ifndef MP_LOW_MEM
-      #define MP_PREC                 64     /* default digits of precision */
+      #define MP_PREC                 32     /* default digits of precision */
    #else
       #define MP_PREC                 8      /* default digits of precision */
    #endif   
@@ -518,13 +520,13 @@
 int mp_count_bits(mp_int *a);
 
 int mp_unsigned_bin_size(mp_int *a);
-int mp_read_unsigned_bin(mp_int *a, unsigned char *b, int c);
+int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
 int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
 int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
 
 int mp_signed_bin_size(mp_int *a);
-int mp_read_signed_bin(mp_int *a, unsigned char *b, int c);
-int mp_to_signed_bin(mp_int *a, unsigned char *b);
+int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
+int mp_to_signed_bin(mp_int *a,  unsigned char *b);
 int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
 
 int mp_read_radix(mp_int *a, const char *str, int radix);
@@ -576,3 +578,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtommath/tommath.h,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2006/03/31 14:18:44 $ */
Binary file tommath.pdf has changed
--- a/tommath.src	Wed Mar 08 13:16:18 2006 +0000
+++ b/tommath.src	Thu Jan 11 03:11:15 2007 +0000
@@ -66,7 +66,7 @@
 }
 }
 \maketitle
-This text has been placed in the public domain.  This text corresponds to the v0.35 release of the 
+This text has been placed in the public domain.  This text corresponds to the v0.39 release of the 
 LibTomMath project.
 
 \begin{alltt}
@@ -77,7 +77,7 @@
 Canada
 
 Phone: 1-613-836-3160
-Email: [email protected]
+Email: [email protected]
 \end{alltt}
 
 This text is formatted to the international B5 paper size of 176mm wide by 250mm tall using the \LaTeX{} 
@@ -268,7 +268,7 @@
 any form of useful performance in non-trivial applications.  
 
 To solve this problem the focus of this text is on the practical aspects of implementing a multiple precision integer
-package.  As a case study the ``LibTomMath''\footnote{Available at \url{http://math.libtomcrypt.org}} package is used 
+package.  As a case study the ``LibTomMath''\footnote{Available at \url{http://math.libtomcrypt.com}} package is used 
 to demonstrate algorithms with real implementations\footnote{In the ISO C programming language.} that have been field 
 tested and work very well.  The LibTomMath library is freely available on the Internet for all uses and this text 
 discusses a very large portion of the inner workings of the library.
@@ -2190,7 +2190,7 @@
 
 After the digits have been shifted appropriately at most $lg(\beta) - 1$ shifts are left to perform.  Step 5 calculates the number of remaining shifts 
 required.  If it is non-zero a modified shift loop is used to calculate the remaining product.  
-Essentially the loop is a generic version of algorith mp\_mul2 designed to handle any shift count in the range $1 \le x < lg(\beta)$.  The $mask$
+Essentially the loop is a generic version of algorithm mp\_mul\_2 designed to handle any shift count in the range $1 \le x < lg(\beta)$.  The $mask$
 variable is used to extract the upper $d$ bits to form the carry for the next iteration.  
 
 This algorithm is loosely measured as a $O(2n)$ algorithm which means that if the input is $n$-digits that it takes $2n$ ``time'' to 
@@ -2611,17 +2611,16 @@
 \hspace{6mm}5.4.1  $\_ \hat W \leftarrow \_ \hat W + a_{tx+iy}b_{ty-iy}$ \\
 \hspace{3mm}5.5  $W_{ix} \leftarrow \_ \hat W (\mbox{mod }\beta)$\\
 \hspace{3mm}5.6  $\_ \hat W \leftarrow \lfloor \_ \hat W / \beta \rfloor$ \\
-6.  $W_{pa} \leftarrow \_ \hat W (\mbox{mod }\beta)$ \\
 \\
-7.  $oldused \leftarrow c.used$ \\
-8.  $c.used \leftarrow digs$ \\
-9.  for $ix$ from $0$ to $pa$ do \\
-\hspace{3mm}9.1  $c_{ix} \leftarrow W_{ix}$ \\
-10.  for $ix$ from $pa + 1$ to $oldused - 1$ do \\
-\hspace{3mm}10.1 $c_{ix} \leftarrow 0$ \\
+6.  $oldused \leftarrow c.used$ \\
+7.  $c.used \leftarrow digs$ \\
+8.  for $ix$ from $0$ to $pa$ do \\
+\hspace{3mm}8.1  $c_{ix} \leftarrow W_{ix}$ \\
+9.  for $ix$ from $pa + 1$ to $oldused - 1$ do \\
+\hspace{3mm}9.1 $c_{ix} \leftarrow 0$ \\
 \\
-11.  Clamp $c$. \\
-12.  Return MP\_OKAY. \\
+10.  Clamp $c$. \\
+11.  Return MP\_OKAY. \\
 \hline
 \end{tabular}
 \end{center}
@@ -2775,26 +2774,25 @@
 light algebra \cite{KARAP} that the following polynomial is equivalent to multiplication of the two integers the polynomials represent.
 
 \begin{equation}
-f(x) \cdot g(x) = acx^2 + ((a - b)(c - d) - (ac + bd))x + bd
+f(x) \cdot g(x) = acx^2 + ((a + b)(c + d) - (ac + bd))x + bd
 \end{equation}
 
 Using the observation that $ac$ and $bd$ could be re-used only three half sized multiplications would be required to produce the product.  Applying
 this algorithm recursively, the work factor becomes $O(n^{lg(3)})$ which is substantially better than the work factor $O(n^2)$ of the Comba technique.  It turns 
 out what Karatsuba did not know or at least did not publish was that this is simply polynomial basis multiplication with the points 
-$\zeta_0$, $\zeta_{\infty}$ and $-\zeta_{-1}$.  Consider the resultant system of equations.
+$\zeta_0$, $\zeta_{\infty}$ and $\zeta_{1}$.  Consider the resultant system of equations.
 
 \begin{center}
 \begin{tabular}{rcrcrcrc}
 $\zeta_{0}$ &      $=$ &  &  &  & & $w_0$ \\
-$-\zeta_{-1}$ &    $=$ & $-w_2$ & $+$ & $w_1$ & $-$ & $w_0$ \\
+$\zeta_{1}$ &      $=$ & $w_2$ & $+$ & $w_1$ & $+$ & $w_0$ \\
 $\zeta_{\infty}$ & $=$ & $w_2$ &  & &  & \\
 \end{tabular}
 \end{center}
 
 By adding the first and last equation to the equation in the middle the term $w_1$ can be isolated and all three coefficients solved for.  The simplicity
 of this system of equations has made Karatsuba fairly popular.  In fact the cutoff point is often fairly low\footnote{With LibTomMath 0.18 it is 70 and 109 digits for the Intel P4 and AMD Athlon respectively.}
-making it an ideal algorithm to speed up certain public key cryptosystems such as RSA and Diffie-Hellman.  It is worth noting that the point 
-$\zeta_1$ could be substituted for $-\zeta_{-1}$.  In this case the first and third row are subtracted instead of added to the second row.  
+making it an ideal algorithm to speed up certain public key cryptosystems such as RSA and Diffie-Hellman.  
 
 \newpage\begin{figure}[!here]
 \begin{small}
@@ -2817,13 +2815,13 @@
 Calculate the three products. \\
 8.  $x0y0 \leftarrow x0 \cdot y0$ (\textit{mp\_mul}) \\
 9.  $x1y1 \leftarrow x1 \cdot y1$ \\
-10.  $t1 \leftarrow x1 - x0$ (\textit{mp\_sub}) \\
-11.  $x0 \leftarrow y1 - y0$ \\
+10.  $t1 \leftarrow x1 + x0$ (\textit{mp\_add}) \\
+11.  $x0 \leftarrow y1 + y0$ \\
 12.  $t1 \leftarrow t1 \cdot x0$ \\
 \\
 Calculate the middle term. \\
 13.  $x0 \leftarrow x0y0 + x1y1$ \\
-14.  $t1 \leftarrow x0 - t1$ \\
+14.  $t1 \leftarrow t1 - x0$ (\textit{s\_mp\_sub}) \\
 \\
 Calculate the final product. \\
 15.  $t1 \leftarrow t1 \cdot \beta^B$ (\textit{mp\_lshd}) \\
@@ -2850,7 +2848,7 @@
 compute the lower halves.  Step 6 and 7 computer the upper halves.  
 
 After the halves have been computed the three intermediate half-size products must be computed.  Step 8 and 9 compute the trivial products
-$x0 \cdot y0$ and $x1 \cdot y1$.  The mp\_int $x0$ is used as a temporary variable after $x1 - x0$ has been computed.  By using $x0$ instead
+$x0 \cdot y0$ and $x1 \cdot y1$.  The mp\_int $x0$ is used as a temporary variable after $x1 + x0$ has been computed.  By using $x0$ instead
 of an additional temporary variable, the algorithm can avoid an addition memory allocation operation.
 
 The remaining steps 13 through 18 compute the Karatsuba polynomial through a variety of digit shifting and addition operations.
@@ -3246,10 +3244,10 @@
 number with the following equation.
 
 \begin{equation}
-h(x) = a^2x^2 + \left (a^2 + b^2 - (a - b)^2 \right )x + b^2
+h(x) = a^2x^2 + \left ((a + b)^2 - (a^2 + b^2) \right )x + b^2
 \end{equation}
 
-Upon closer inspection this equation only requires the calculation of three half-sized squares: $a^2$, $b^2$ and $(a - b)^2$.  As in 
+Upon closer inspection this equation only requires the calculation of three half-sized squares: $a^2$, $b^2$ and $(a + b)^2$.  As in 
 Karatsuba multiplication, this algorithm can be applied recursively on the input and will achieve an asymptotic running time of 
 $O \left ( n^{lg(3)} \right )$.
 
@@ -3281,12 +3279,12 @@
 Calculate the three squares. \\
 6.  $x0x0 \leftarrow x0^2$ (\textit{mp\_sqr}) \\
 7.  $x1x1 \leftarrow x1^2$ \\
-8.  $t1 \leftarrow x1 - x0$ (\textit{mp\_sub}) \\
+8.  $t1 \leftarrow x1 + x0$ (\textit{s\_mp\_add}) \\
 9.  $t1 \leftarrow t1^2$ \\
 \\
 Compute the middle term. \\
 10.  $t2 \leftarrow x0x0 + x1x1$ (\textit{s\_mp\_add}) \\
-11.  $t1 \leftarrow t2 - t1$ \\
+11.  $t1 \leftarrow t1 - t2$ \\
 \\
 Compute final product. \\
 12.  $t1 \leftarrow t1\beta^B$ (\textit{mp\_lshd}) \\
@@ -3309,7 +3307,7 @@
 placed just below the middle.  Step 3, 4 and 5 compute the two halves required using $B$
 as the radix point.  The first two squares in steps 6 and 7 are rather straightforward while the last square is of a more compact form.
 
-By expanding $\left (x1 - x0 \right )^2$, the $x1^2$ and $x0^2$ terms in the middle disappear, that is $x1^2 + x0^2 - (x1 - x0)^2 = 2 \cdot x0 \cdot x1$.
+By expanding $\left (x1 + x0 \right )^2$, the $x1^2$ and $x0^2$ terms in the middle disappear, that is $(x0 - x1)^2 - (x1^2 + x0^2)  = 2 \cdot x0 \cdot x1$.
 Now if $5n$ single precision additions and a squaring of $n$-digits is faster than multiplying two $n$-digit numbers and doubling then
 this method is faster.  Assuming no further recursions occur, the difference can be estimated with the following inequality.
 
@@ -3732,6 +3730,7 @@
 \hline $6$ & $x/2 = 139$ \\
 \hline $7$ & $x + n = 396$, $x/2 = 198$ \\
 \hline $8$ & $x/2 = 99$ \\
+\hline $9$ & $x + n = 356$, $x/2 = 178$ \\
 \hline
 \end{tabular}
 \end{center}
@@ -3740,8 +3739,8 @@
 \label{fig:MONT1}
 \end{figure}
 
-Consider the example in figure~\ref{fig:MONT1} which reduces $x = 5555$ modulo $n = 257$ when $k = 8$.  The result of the algorithm $r = 99$ is
-congruent to the value of $2^{-8} \cdot 5555 \mbox{ (mod }257\mbox{)}$.  When $r$ is multiplied by $2^8$ modulo $257$ the correct residue 
+Consider the example in figure~\ref{fig:MONT1} which reduces $x = 5555$ modulo $n = 257$ when $k = 9$ (note $\beta^k = 512$ which is larger than $n$).  The result of 
+the algorithm $r = 178$ is congruent to the value of $2^{-9} \cdot 5555 \mbox{ (mod }257\mbox{)}$.  When $r$ is multiplied by $2^9$ modulo $257$ the correct residue 
 $r \equiv 158$ is produced.  
 
 Let $k = \lfloor lg(n) \rfloor + 1$ represent the number of bits in $n$.  The current algorithm requires $2k^2$ single precision shifts
@@ -3753,10 +3752,10 @@
 \begin{center}
 \begin{tabular}{l}
 \hline Algorithm \textbf{Montgomery Reduction} (modified I). \\
-\textbf{Input}.   Integer $x$, $n$ and $k$ \\
+\textbf{Input}.   Integer $x$, $n$ and $k$ ($2^k > n$) \\
 \textbf{Output}.  $2^{-k}x \mbox{ (mod }n\mbox{)}$ \\
 \hline \\
-1.  for $t$ from $0$ to $k - 1$ do \\
+1.  for $t$ from $1$ to $k$ do \\
 \hspace{3mm}1.1  If the $t$'th bit of $x$ is one then \\
 \hspace{6mm}1.1.1  $x \leftarrow x + 2^tn$ \\
 2.  Return $x/2^k$. \\
@@ -3784,7 +3783,8 @@
 \hline $6$ & $8896$ & $10001011000000$ \\
 \hline $7$ & $x + 2^{6}n = 25344$ & $110001100000000$ \\
 \hline $8$ & $25344$ & $110001100000000$ \\
-\hline -- & $x/2^k = 99$ & \\
+\hline $9$ & $x + 2^{7}n = 91136$ & $10110010000000000$ \\
+\hline -- & $x/2^k = 178$ & \\
 \hline
 \end{tabular}
 \end{center}
@@ -3793,7 +3793,7 @@
 \label{fig:MONT2}
 \end{figure}
 
-Figure~\ref{fig:MONT2} demonstrates the modified algorithm reducing $x = 5555$ modulo $n = 257$ with $k = 8$. 
+Figure~\ref{fig:MONT2} demonstrates the modified algorithm reducing $x = 5555$ modulo $n = 257$ with $k = 9$. 
 With this algorithm a single shift right at the end is the only right shift required to reduce the input instead of $k$ right shifts inside the 
 loop.  Note that for the iterations $t = 2, 5, 6$ and $8$ where the result $x$ is not changed.  In those iterations the $t$'th bit of $x$ is 
 zero and the appropriate multiple of $n$ does not need to be added to force the $t$'th bit of the result to zero.  
@@ -3807,7 +3807,7 @@
 \begin{center}
 \begin{tabular}{l}
 \hline Algorithm \textbf{Montgomery Reduction} (modified II). \\
-\textbf{Input}.   Integer $x$, $n$ and $k$ \\
+\textbf{Input}.   Integer $x$, $n$ and $k$ ($\beta^k > n$) \\
 \textbf{Output}.  $\beta^{-k}x \mbox{ (mod }n\mbox{)}$ \\
 \hline \\
 1.  for $t$ from $0$ to $k - 1$ do \\
@@ -4035,7 +4035,7 @@
 \hline \\
 1.  $b \leftarrow n_0$ \\
 2.  If $b$ is even return(\textit{MP\_VAL}) \\
-3.  $x \leftarrow ((b + 2) \mbox{ AND } 4) << 1) + b$ \\
+3.  $x \leftarrow (((b + 2) \mbox{ AND } 4) << 1) + b$ \\
 4.  for $k$ from 0 to $\lceil lg(lg(\beta)) \rceil - 2$ do \\
 \hspace{3mm}4.1  $x \leftarrow x \cdot (2 - bx)$ \\
 5.  $\rho \leftarrow \beta - x \mbox{ (mod }\beta\mbox{)}$ \\
@@ -4939,15 +4939,15 @@
 
 EXAM,bn_s_mp_exptmod.c
 
-Lines @26,if@ through @40,}@ determine the optimal window size based on the length of the exponent in bits.  The window divisions are sorted
+Lines @31,if@ through @45,}@ determine the optimal window size based on the length of the exponent in bits.  The window divisions are sorted
 from smallest to greatest so that in each \textbf{if} statement only one condition must be tested.  For example, by the \textbf{if} statement 
-on line @32,if@ the value of $x$ is already known to be greater than $140$.  
+on line @37,if@ the value of $x$ is already known to be greater than $140$.  
 
 The conditional piece of code beginning on line @42,ifdef@ allows the window size to be restricted to five bits.  This logic is used to ensure
 the table of precomputed powers of $G$ remains relatively small.  
 
-The for loop on line @49,for@ initializes the $M$ array while lines @59,mp_init@ and @62,mp_reduce@ compute the value of $\mu$ required for
-Barrett reduction.  
+The for loop on line @60,for@ initializes the $M$ array while lines @71,mp_init@ and @75,mp_reduce@ through @85,}@ initialize the reduction
+function that will be used for this modulus.
 
 -- More later.
 
@@ -5230,23 +5230,23 @@
 mp_div(&a, &b, &c, NULL);  /* c = [a/b] */
 \end{verbatim}
 
-Lines @37,if@ and @42,if@ handle the two trivial cases of inputs which are division by zero and dividend smaller than the divisor 
-respectively.  After the two trivial cases all of the temporary variables are initialized.  Line @76,neg@ determines the sign of 
-the quotient and line @77,sign@ ensures that both $x$ and $y$ are positive.  
-
-The number of bits in the leading digit is calculated on line @80,norm@.  Implictly an mp\_int with $r$ digits will require $lg(\beta)(r-1) + k$ bits
+Lines @108,if@ and @113,if@ handle the two trivial cases of inputs which are division by zero and dividend smaller than the divisor 
+respectively.  After the two trivial cases all of the temporary variables are initialized.  Line @147,neg@ determines the sign of 
+the quotient and line @148,sign@ ensures that both $x$ and $y$ are positive.  
+
+The number of bits in the leading digit is calculated on line @151,norm@.  Implictly an mp\_int with $r$ digits will require $lg(\beta)(r-1) + k$ bits
 of precision which when reduced modulo $lg(\beta)$ produces the value of $k$.  In this case $k$ is the number of bits in the leading digit which is
 exactly what is required.  For the algorithm to operate $k$ must equal $lg(\beta) - 1$ and when it does not the inputs must be normalized by shifting
 them to the left by $lg(\beta) - 1 - k$ bits.
 
 Throughout the variables $n$ and $t$ will represent the highest digit of $x$ and $y$ respectively.  These are first used to produce the 
-leading digit of the quotient.  The loop beginning on line @113,for@ will produce the remainder of the quotient digits.
-
-The conditional ``continue'' on line @114,if@ is used to prevent the algorithm from reading past the leading edge of $x$ which can occur when the
+leading digit of the quotient.  The loop beginning on line @184,for@ will produce the remainder of the quotient digits.
+
+The conditional ``continue'' on line @186,continue@ is used to prevent the algorithm from reading past the leading edge of $x$ which can occur when the
 algorithm eliminates multiple non-zero digits in a single iteration.  This ensures that $x_i$ is always non-zero since by definition the digits
 above the $i$'th position $x$ must be zero in order for the quotient to be precise\footnote{Precise as far as integer division is concerned.}.  
 
-Lines @142,t1@, @143,t1@ and @150,t2@ through @152,t2@ manually construct the high accuracy estimations by setting the digits of the two mp\_int 
+Lines @214,t1@, @216,t1@ and @222,t2@ through @225,t2@ manually construct the high accuracy estimations by setting the digits of the two mp\_int 
 variables directly.  
 
 \section{Single Digit Helpers}
@@ -5744,33 +5744,30 @@
 \textbf{Input}.   mp\_int $a$ and $b$ \\
 \textbf{Output}.  The greatest common divisor $c = (a, b)$.  \\
 \hline \\
-1.  If $a = 0$ and $b \ne 0$ then \\
-\hspace{3mm}1.1  $c \leftarrow b$ \\
+1.  If $a = 0$ then \\
+\hspace{3mm}1.1  $c \leftarrow \vert b \vert $ \\
 \hspace{3mm}1.2  Return(\textit{MP\_OKAY}). \\
-2.  If $a \ne 0$ and $b = 0$ then \\
-\hspace{3mm}2.1  $c \leftarrow a$ \\
+2.  If $b = 0$ then \\
+\hspace{3mm}2.1  $c \leftarrow \vert a \vert $ \\
 \hspace{3mm}2.2  Return(\textit{MP\_OKAY}). \\
-3.  If $a = b = 0$ then \\
-\hspace{3mm}3.1  $c \leftarrow 1$ \\
-\hspace{3mm}3.2  Return(\textit{MP\_OKAY}). \\
-4.  $u \leftarrow \vert a \vert, v \leftarrow \vert b \vert$ \\
-5.  $k \leftarrow 0$ \\
-6.  While $u.used > 0$ and $v.used > 0$ and $u_0 \equiv v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}6.1  $k \leftarrow k + 1$ \\
-\hspace{3mm}6.2  $u \leftarrow \lfloor u / 2 \rfloor$ \\
-\hspace{3mm}6.3  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-7.  While $u.used > 0$ and $u_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}7.1  $u \leftarrow \lfloor u / 2 \rfloor$ \\
-8.  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}8.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-9.  While $v.used > 0$ \\
-\hspace{3mm}9.1  If $\vert u \vert > \vert v \vert$ then \\
-\hspace{6mm}9.1.1  Swap $u$ and $v$. \\
-\hspace{3mm}9.2  $v \leftarrow \vert v \vert - \vert u \vert$ \\
-\hspace{3mm}9.3  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{6mm}9.3.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-10.  $c \leftarrow u \cdot 2^k$ \\
-11.  Return(\textit{MP\_OKAY}). \\
+3.  $u \leftarrow \vert a \vert, v \leftarrow \vert b \vert$ \\
+4.  $k \leftarrow 0$ \\
+5.  While $u.used > 0$ and $v.used > 0$ and $u_0 \equiv v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}5.1  $k \leftarrow k + 1$ \\
+\hspace{3mm}5.2  $u \leftarrow \lfloor u / 2 \rfloor$ \\
+\hspace{3mm}5.3  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+6.  While $u.used > 0$ and $u_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}6.1  $u \leftarrow \lfloor u / 2 \rfloor$ \\
+7.  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}7.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+8.  While $v.used > 0$ \\
+\hspace{3mm}8.1  If $\vert u \vert > \vert v \vert$ then \\
+\hspace{6mm}8.1.1  Swap $u$ and $v$. \\
+\hspace{3mm}8.2  $v \leftarrow \vert v \vert - \vert u \vert$ \\
+\hspace{3mm}8.3  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{6mm}8.3.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+9.  $c \leftarrow u \cdot 2^k$ \\
+10.  Return(\textit{MP\_OKAY}). \\
 \hline
 \end{tabular}
 \end{center}
@@ -5782,17 +5779,17 @@
 Knuth \cite[pp. 338]{TAOCPV2} but has been modified to be simpler to explain.  In theory it achieves the same asymptotic working time as
 Algorithm B and in practice this appears to be true.  
 
-The first three steps handle the cases where either one of or both inputs are zero.  If either input is zero the greatest common divisor is the 
+The first two steps handle the cases where either one of or both inputs are zero.  If either input is zero the greatest common divisor is the 
 largest input or zero if they are both zero.  If the inputs are not trivial than $u$ and $v$ are assigned the absolute values of 
 $a$ and $b$ respectively and the algorithm will proceed to reduce the pair.
 
-Step six will divide out any common factors of two and keep track of the count in the variable $k$.  After this step two is no longer a
+Step five will divide out any common factors of two and keep track of the count in the variable $k$.  After this step, two is no longer a
 factor of the remaining greatest common divisor between $u$ and $v$ and can be safely evenly divided out of either whenever they are even.  Step 
-seven and eight ensure that the $u$ and $v$ respectively have no more factors of two.  At most only one of the while loops will iterate since 
+six and seven ensure that the $u$ and $v$ respectively have no more factors of two.  At most only one of the while--loops will iterate since 
 they cannot both be even.
 
-By step nine both of $u$ and $v$ are odd which is required for the inner logic.  First the pair are swapped such that $v$ is equal to
-or greater than $u$.  This ensures that the subtraction on step 9.2 will always produce a positive and even result.  Step 9.3 removes any
+By step eight both of $u$ and $v$ are odd which is required for the inner logic.  First the pair are swapped such that $v$ is equal to
+or greater than $u$.  This ensures that the subtraction on step 8.2 will always produce a positive and even result.  Step 8.3 removes any
 factors of two from the difference $u$ to ensure that in the next iteration of the loop both are once again odd.
 
 After $v = 0$ occurs the variable $u$ has the greatest common divisor of the pair $\left < u, v \right >$ just after step six.  The result
@@ -5803,17 +5800,17 @@
 This function makes use of the macros mp\_iszero and mp\_iseven.  The former evaluates to $1$ if the input mp\_int is equivalent to the 
 integer zero otherwise it evaluates to $0$.  The latter evaluates to $1$ if the input mp\_int represents a non-zero even integer otherwise
 it evaluates to $0$.  Note that just because mp\_iseven may evaluate to $0$ does not mean the input is odd, it could also be zero.  The three 
-trivial cases of inputs are handled on lines @25,zero@ through @34,}@.  After those lines the inputs are assumed to be non-zero.
-
-Lines @36,if@ and @40,if@ make local copies $u$ and $v$ of the inputs $a$ and $b$ respectively.  At this point the common factors of two 
-must be divided out of the two inputs.  The while loop on line @49,while@ iterates so long as both are even.  The local integer $k$ is used to
-keep track of how many factors of $2$ are pulled out of both values.  It is assumed that the number of factors will not exceed the maximum 
-value of a C ``int'' data type\footnote{Strictly speaking no array in C may have more than entries than are accessible by an ``int'' so this is not 
-a limitation.}.  
-
-At this point there are no more common factors of two in the two values.  The while loops on lines @60,while@ and @65,while@ remove any independent
-factors of two such that both $u$ and $v$ are guaranteed to be an odd integer before hitting the main body of the algorithm.  The while loop
-on line @71, while@ performs the reduction of the pair until $v$ is equal to zero.  The unsigned comparison and subtraction algorithms are used in
+trivial cases of inputs are handled on lines @23,zero@ through @29,}@.  After those lines the inputs are assumed to be non-zero.
+
+Lines @32,if@ and @36,if@ make local copies $u$ and $v$ of the inputs $a$ and $b$ respectively.  At this point the common factors of two 
+must be divided out of the two inputs.  The block starting at line @43,common@ removes common factors of two by first counting the number of trailing
+zero bits in both.  The local integer $k$ is used to keep track of how many factors of $2$ are pulled out of both values.  It is assumed that 
+the number of factors will not exceed the maximum value of a C ``int'' data type\footnote{Strictly speaking no array in C may have more than 
+entries than are accessible by an ``int'' so this is not a limitation.}.  
+
+At this point there are no more common factors of two in the two values.  The divisions by a power of two on lines @60,div_2d@ and @67,div_2d@ remove 
+any independent factors of two such that both $u$ and $v$ are guaranteed to be an odd integer before hitting the main body of the algorithm.  The while loop
+on line @72, while@ performs the reduction of the pair until $v$ is equal to zero.  The unsigned comparison and subtraction algorithms are used in
 place of the full signed routines since both values are guaranteed to be positive and the result of the subtraction is guaranteed to be non-negative.
 
 \section{Least Common Multiple}
--- a/tommath.tex	Wed Mar 08 13:16:18 2006 +0000
+++ b/tommath.tex	Thu Jan 11 03:11:15 2007 +0000
@@ -66,7 +66,7 @@
 }
 }
 \maketitle
-This text has been placed in the public domain.  This text corresponds to the v0.35 release of the 
+This text has been placed in the public domain.  This text corresponds to the v0.39 release of the 
 LibTomMath project.
 
 \begin{alltt}
@@ -77,7 +77,7 @@
 Canada
 
 Phone: 1-613-836-3160
-Email: [email protected]
+Email: [email protected]
 \end{alltt}
 
 This text is formatted to the international B5 paper size of 176mm wide by 250mm tall using the \LaTeX{} 
@@ -268,7 +268,7 @@
 any form of useful performance in non-trivial applications.  
 
 To solve this problem the focus of this text is on the practical aspects of implementing a multiple precision integer
-package.  As a case study the ``LibTomMath''\footnote{Available at \url{http://math.libtomcrypt.org}} package is used 
+package.  As a case study the ``LibTomMath''\footnote{Available at \url{http://math.libtomcrypt.com}} package is used 
 to demonstrate algorithms with real implementations\footnote{In the ISO C programming language.} that have been field 
 tested and work very well.  The LibTomMath library is freely available on the Internet for all uses and this text 
 discusses a very large portion of the inner workings of the library.
@@ -814,6 +814,7 @@
 039     return MP_OKAY;
 040   \}
 041   #endif
+042   
 \end{alltt}
 \end{small}
 
@@ -902,6 +903,7 @@
 037     \}
 038   \}
 039   #endif
+040   
 \end{alltt}
 \end{small}
 
@@ -1008,6 +1010,7 @@
 050     return MP_OKAY;
 051   \}
 052   #endif
+053   
 \end{alltt}
 \end{small}
 
@@ -1096,6 +1099,7 @@
 041     return MP_OKAY;
 042   \}
 043   #endif
+044   
 \end{alltt}
 \end{small}
 
@@ -1183,6 +1187,7 @@
 052   \}
 053   
 054   #endif
+055   
 \end{alltt}
 \end{small}
 
@@ -1268,6 +1273,7 @@
 037     \}
 038   \}
 039   #endif
+040   
 \end{alltt}
 \end{small}
 
@@ -1405,6 +1411,7 @@
 061     return MP_OKAY;
 062   \}
 063   #endif
+064   
 \end{alltt}
 \end{small}
 
@@ -1519,6 +1526,7 @@
 025     return mp_copy (b, a);
 026   \}
 027   #endif
+028   
 \end{alltt}
 \end{small}
 
@@ -1570,6 +1578,7 @@
 029     \}
 030   \}
 031   #endif
+032   
 \end{alltt}
 \end{small}
 
@@ -1631,6 +1640,7 @@
 036     return MP_OKAY;
 037   \}
 038   #endif
+039   
 \end{alltt}
 \end{small}
 
@@ -1692,6 +1702,7 @@
 033     return MP_OKAY;
 034   \}
 035   #endif
+036   
 \end{alltt}
 \end{small}
 
@@ -1739,6 +1750,7 @@
 022     a->used  = (a->dp[0] != 0) ? 1 : 0;
 023   \}
 024   #endif
+025   
 \end{alltt}
 \end{small}
 
@@ -1819,6 +1831,7 @@
 041     return MP_OKAY;
 042   \}
 043   #endif
+044   
 \end{alltt}
 \end{small}
 
@@ -1921,6 +1934,7 @@
 048     return MP_EQ;
 049   \}
 050   #endif
+051   
 \end{alltt}
 \end{small}
 
@@ -1987,6 +2001,7 @@
 036     \}
 037   \}
 038   #endif
+039   
 \end{alltt}
 \end{small}
 
@@ -2205,6 +2220,7 @@
 102     return MP_OKAY;
 103   \}
 104   #endif
+105   
 \end{alltt}
 \end{small}
 
@@ -2376,6 +2392,7 @@
 082   \}
 083   
 084   #endif
+085   
 \end{alltt}
 \end{small}
 
@@ -2511,6 +2528,7 @@
 046   \}
 047   
 048   #endif
+049   
 \end{alltt}
 \end{small}
 
@@ -2623,6 +2641,7 @@
 052   \}
 053   
 054   #endif
+055   
 \end{alltt}
 \end{small}
 
@@ -2757,6 +2776,7 @@
 075     return MP_OKAY;
 076   \}
 077   #endif
+078   
 \end{alltt}
 \end{small}
 
@@ -2857,6 +2877,7 @@
 061     return MP_OKAY;
 062   \}
 063   #endif
+064   
 \end{alltt}
 \end{small}
 
@@ -2977,6 +2998,7 @@
 060     return MP_OKAY;
 061   \}
 062   #endif
+063   
 \end{alltt}
 \end{small}
 
@@ -3088,6 +3110,7 @@
 065     a->used -= b;
 066   \}
 067   #endif
+068   
 \end{alltt}
 \end{small}
 
@@ -3146,7 +3169,7 @@
 
 After the digits have been shifted appropriately at most $lg(\beta) - 1$ shifts are left to perform.  Step 5 calculates the number of remaining shifts 
 required.  If it is non-zero a modified shift loop is used to calculate the remaining product.  
-Essentially the loop is a generic version of algorith mp\_mul2 designed to handle any shift count in the range $1 \le x < lg(\beta)$.  The $mask$
+Essentially the loop is a generic version of algorithm mp\_mul\_2 designed to handle any shift count in the range $1 \le x < lg(\beta)$.  The $mask$
 variable is used to extract the upper $d$ bits to form the carry for the next iteration.  
 
 This algorithm is loosely measured as a $O(2n)$ algorithm which means that if the input is $n$-digits that it takes $2n$ ``time'' to 
@@ -3221,6 +3244,7 @@
 078     return MP_OKAY;
 079   \}
 080   #endif
+081   
 \end{alltt}
 \end{small}
 
@@ -3357,6 +3381,7 @@
 090     return MP_OKAY;
 091   \}
 092   #endif
+093   
 \end{alltt}
 \end{small}
 
@@ -3448,6 +3473,7 @@
 048     return MP_OKAY;
 049   \}
 050   #endif
+051   
 \end{alltt}
 \end{small}
 
@@ -3687,6 +3713,7 @@
 083     return MP_OKAY;
 084   \}
 085   #endif
+086   
 \end{alltt}
 \end{small}
 
@@ -3837,17 +3864,16 @@
 \hspace{6mm}5.4.1  $\_ \hat W \leftarrow \_ \hat W + a_{tx+iy}b_{ty-iy}$ \\
 \hspace{3mm}5.5  $W_{ix} \leftarrow \_ \hat W (\mbox{mod }\beta)$\\
 \hspace{3mm}5.6  $\_ \hat W \leftarrow \lfloor \_ \hat W / \beta \rfloor$ \\
-6.  $W_{pa} \leftarrow \_ \hat W (\mbox{mod }\beta)$ \\
 \\
-7.  $oldused \leftarrow c.used$ \\
-8.  $c.used \leftarrow digs$ \\
-9.  for $ix$ from $0$ to $pa$ do \\
-\hspace{3mm}9.1  $c_{ix} \leftarrow W_{ix}$ \\
-10.  for $ix$ from $pa + 1$ to $oldused - 1$ do \\
-\hspace{3mm}10.1 $c_{ix} \leftarrow 0$ \\
+6.  $oldused \leftarrow c.used$ \\
+7.  $c.used \leftarrow digs$ \\
+8.  for $ix$ from $0$ to $pa$ do \\
+\hspace{3mm}8.1  $c_{ix} \leftarrow W_{ix}$ \\
+9.  for $ix$ from $pa + 1$ to $oldused - 1$ do \\
+\hspace{3mm}9.1 $c_{ix} \leftarrow 0$ \\
 \\
-11.  Clamp $c$. \\
-12.  Return MP\_OKAY. \\
+10.  Clamp $c$. \\
+11.  Return MP\_OKAY. \\
 \hline
 \end{tabular}
 \end{center}
@@ -3942,39 +3968,38 @@
 069         /* execute loop */
 070         for (iz = 0; iz < iy; ++iz) \{
 071            _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
-072         \}
-073   
-074         /* store term */
-075         W[ix] = ((mp_digit)_W) & MP_MASK;
-076   
-077         /* make next carry */
-078         _W = _W >> ((mp_word)DIGIT_BIT);
-079     \}
-080   
-081     /* store final carry */
-082     W[ix] = (mp_digit)(_W & MP_MASK);
-083   
-084     /* setup dest */
-085     olduse  = c->used;
-086     c->used = pa;
-087   
-088     \{
-089       register mp_digit *tmpc;
-090       tmpc = c->dp;
-091       for (ix = 0; ix < pa+1; ix++) \{
-092         /* now extract the previous digit [below the carry] */
-093         *tmpc++ = W[ix];
-094       \}
-095   
-096       /* clear unused digits [that existed in the old copy of c] */
-097       for (; ix < olduse; ix++) \{
-098         *tmpc++ = 0;
-099       \}
-100     \}
-101     mp_clamp (c);
-102     return MP_OKAY;
-103   \}
-104   #endif
+072   
+073         \}
+074   
+075         /* store term */
+076         W[ix] = ((mp_digit)_W) & MP_MASK;
+077   
+078         /* make next carry */
+079         _W = _W >> ((mp_word)DIGIT_BIT);
+080    \}
+081   
+082     /* setup dest */
+083     olduse  = c->used;
+084     c->used = pa;
+085   
+086     \{
+087       register mp_digit *tmpc;
+088       tmpc = c->dp;
+089       for (ix = 0; ix < pa+1; ix++) \{
+090         /* now extract the previous digit [below the carry] */
+091         *tmpc++ = W[ix];
+092       \}
+093   
+094       /* clear unused digits [that existed in the old copy of c] */
+095       for (; ix < olduse; ix++) \{
+096         *tmpc++ = 0;
+097       \}
+098     \}
+099     mp_clamp (c);
+100     return MP_OKAY;
+101   \}
+102   #endif
+103   
 \end{alltt}
 \end{small}
 
@@ -3982,7 +4007,7 @@
 to produce the individual columns of the product.  We use the two aliases $tmpx$ and $tmpy$ (lines 61, 62) to point
 inside the two multiplicands quickly.  
 
-The inner loop (lines 70 to 72) of this implementation is where the tradeoff come into play.  Originally this comba 
+The inner loop (lines 70 to 73) of this implementation is where the tradeoff come into play.  Originally this comba 
 implementation was ``row--major'' which means it adds to each of the columns in each pass.  After the outer loop it would then fix 
 the carries.  This was very fast except it had an annoying drawback.  You had to read a mp\_word and two mp\_digits and write 
 one mp\_word per iteration.  On processors such as the Athlon XP and P4 this did not matter much since the cache bandwidth 
@@ -3990,8 +4015,8 @@
 slower and also often doesn't exist.  This new algorithm only performs two reads per iteration under the assumption that the 
 compiler has aliased $\_ \hat W$ to a CPU register.
 
-After the inner loop we store the current accumulator in $W$ and shift $\_ \hat W$ (lines 75, 78) to forward it as 
-a carry for the next pass.  After the outer loop we use the final carry (line 82) as the last digit of the product.  
+After the inner loop we store the current accumulator in $W$ and shift $\_ \hat W$ (lines 76, 79) to forward it as 
+a carry for the next pass.  After the outer loop we use the final carry (line 76) as the last digit of the product.  
 
 \subsection{Polynomial Basis Multiplication}
 To break the $O(n^2)$ barrier in multiplication requires a completely different look at integer multiplication.  In the following algorithms
@@ -4095,26 +4120,25 @@
 light algebra \cite{KARAP} that the following polynomial is equivalent to multiplication of the two integers the polynomials represent.
 
 \begin{equation}
-f(x) \cdot g(x) = acx^2 + ((a - b)(c - d) - (ac + bd))x + bd
+f(x) \cdot g(x) = acx^2 + ((a + b)(c + d) - (ac + bd))x + bd
 \end{equation}
 
 Using the observation that $ac$ and $bd$ could be re-used only three half sized multiplications would be required to produce the product.  Applying
 this algorithm recursively, the work factor becomes $O(n^{lg(3)})$ which is substantially better than the work factor $O(n^2)$ of the Comba technique.  It turns 
 out what Karatsuba did not know or at least did not publish was that this is simply polynomial basis multiplication with the points 
-$\zeta_0$, $\zeta_{\infty}$ and $-\zeta_{-1}$.  Consider the resultant system of equations.
+$\zeta_0$, $\zeta_{\infty}$ and $\zeta_{1}$.  Consider the resultant system of equations.
 
 \begin{center}
 \begin{tabular}{rcrcrcrc}
 $\zeta_{0}$ &      $=$ &  &  &  & & $w_0$ \\
-$-\zeta_{-1}$ &    $=$ & $-w_2$ & $+$ & $w_1$ & $-$ & $w_0$ \\
+$\zeta_{1}$ &      $=$ & $w_2$ & $+$ & $w_1$ & $+$ & $w_0$ \\
 $\zeta_{\infty}$ & $=$ & $w_2$ &  & &  & \\
 \end{tabular}
 \end{center}
 
 By adding the first and last equation to the equation in the middle the term $w_1$ can be isolated and all three coefficients solved for.  The simplicity
 of this system of equations has made Karatsuba fairly popular.  In fact the cutoff point is often fairly low\footnote{With LibTomMath 0.18 it is 70 and 109 digits for the Intel P4 and AMD Athlon respectively.}
-making it an ideal algorithm to speed up certain public key cryptosystems such as RSA and Diffie-Hellman.  It is worth noting that the point 
-$\zeta_1$ could be substituted for $-\zeta_{-1}$.  In this case the first and third row are subtracted instead of added to the second row.  
+making it an ideal algorithm to speed up certain public key cryptosystems such as RSA and Diffie-Hellman.  
 
 \newpage\begin{figure}[!here]
 \begin{small}
@@ -4137,13 +4161,13 @@
 Calculate the three products. \\
 8.  $x0y0 \leftarrow x0 \cdot y0$ (\textit{mp\_mul}) \\
 9.  $x1y1 \leftarrow x1 \cdot y1$ \\
-10.  $t1 \leftarrow x1 - x0$ (\textit{mp\_sub}) \\
-11.  $x0 \leftarrow y1 - y0$ \\
+10.  $t1 \leftarrow x1 + x0$ (\textit{mp\_add}) \\
+11.  $x0 \leftarrow y1 + y0$ \\
 12.  $t1 \leftarrow t1 \cdot x0$ \\
 \\
 Calculate the middle term. \\
 13.  $x0 \leftarrow x0y0 + x1y1$ \\
-14.  $t1 \leftarrow x0 - t1$ \\
+14.  $t1 \leftarrow t1 - x0$ (\textit{s\_mp\_sub}) \\
 \\
 Calculate the final product. \\
 15.  $t1 \leftarrow t1 \cdot \beta^B$ (\textit{mp\_lshd}) \\
@@ -4170,7 +4194,7 @@
 compute the lower halves.  Step 6 and 7 computer the upper halves.  
 
 After the halves have been computed the three intermediate half-size products must be computed.  Step 8 and 9 compute the trivial products
-$x0 \cdot y0$ and $x1 \cdot y1$.  The mp\_int $x0$ is used as a temporary variable after $x1 - x0$ has been computed.  By using $x0$ instead
+$x0 \cdot y0$ and $x1 \cdot y1$.  The mp\_int $x0$ is used as a temporary variable after $x1 + x0$ has been computed.  By using $x0$ instead
 of an additional temporary variable, the algorithm can avoid an addition memory allocation operation.
 
 The remaining steps 13 through 18 compute the Karatsuba polynomial through a variety of digit shifting and addition operations.
@@ -4191,12 +4215,12 @@
 025    * b = b1 * B**n + b0
 026    *
 027    * Then, a * b => 
-028      a1b1 * B**2n + ((a1 - a0)(b1 - b0) + a0b0 + a1b1) * B + a0b0
+028      a1b1 * B**2n + ((a1 + a0)(b1 + b0) - (a0b0 + a1b1)) * B + a0b0
 029    *
 030    * Note that a1b1 and a0b0 are used twice and only need to be 
 031    * computed once.  So in total three half size (half # of 
 032    * digit) multiplications are performed, a0b0, a1b1 and 
-033    * (a1-b1)(a0-b0)
+033    * (a1+b1)(a0+b0)
 034    *
 035    * Note that a multiplication of half the digits requires
 036    * 1/4th the number of single precision multiplications so in 
@@ -4287,19 +4311,19 @@
 121     if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
 122       goto X1Y1;          /* x1y1 = x1*y1 */
 123   
-124     /* now calc x1-x0 and y1-y0 */
-125     if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+124     /* now calc x1+x0 and y1+y0 */
+125     if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
 126       goto X1Y1;          /* t1 = x1 - x0 */
-127     if (mp_sub (&y1, &y0, &x0) != MP_OKAY)
+127     if (s_mp_add (&y1, &y0, &x0) != MP_OKAY)
 128       goto X1Y1;          /* t2 = y1 - y0 */
 129     if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
-130       goto X1Y1;          /* t1 = (x1 - x0) * (y1 - y0) */
+130       goto X1Y1;          /* t1 = (x1 + x0) * (y1 + y0) */
 131   
 132     /* add x0y0 */
 133     if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
 134       goto X1Y1;          /* t2 = x0y0 + x1y1 */
-135     if (mp_sub (&x0, &t1, &t1) != MP_OKAY)
-136       goto X1Y1;          /* t1 = x0y0 + x1y1 - (x1-x0)*(y1-y0) */
+135     if (s_mp_sub (&t1, &x0, &t1) != MP_OKAY)
+136       goto X1Y1;          /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
 137   
 138     /* shift by B */
 139     if (mp_lshd (&t1, B) != MP_OKAY)
@@ -4326,6 +4350,7 @@
 160     return err;
 161   \}
 162   #endif
+163   
 \end{alltt}
 \end{small}
 
@@ -4729,6 +4754,7 @@
 277   \}     
 278        
 279   #endif
+280   
 \end{alltt}
 \end{small}
 
@@ -4837,6 +4863,7 @@
 059     return res;
 060   \}
 061   #endif
+062   
 \end{alltt}
 \end{small}
 
@@ -5006,6 +5033,7 @@
 077     return MP_OKAY;
 078   \}
 079   #endif
+080   
 \end{alltt}
 \end{small}
 
@@ -5188,6 +5216,7 @@
 107     return MP_OKAY;
 108   \}
 109   #endif
+110   
 \end{alltt}
 \end{small}
 
@@ -5205,10 +5234,10 @@
 number with the following equation.
 
 \begin{equation}
-h(x) = a^2x^2 + \left (a^2 + b^2 - (a - b)^2 \right )x + b^2
+h(x) = a^2x^2 + \left ((a + b)^2 - (a^2 + b^2) \right )x + b^2
 \end{equation}
 
-Upon closer inspection this equation only requires the calculation of three half-sized squares: $a^2$, $b^2$ and $(a - b)^2$.  As in 
+Upon closer inspection this equation only requires the calculation of three half-sized squares: $a^2$, $b^2$ and $(a + b)^2$.  As in 
 Karatsuba multiplication, this algorithm can be applied recursively on the input and will achieve an asymptotic running time of 
 $O \left ( n^{lg(3)} \right )$.
 
@@ -5240,12 +5269,12 @@
 Calculate the three squares. \\
 6.  $x0x0 \leftarrow x0^2$ (\textit{mp\_sqr}) \\
 7.  $x1x1 \leftarrow x1^2$ \\
-8.  $t1 \leftarrow x1 - x0$ (\textit{mp\_sub}) \\
+8.  $t1 \leftarrow x1 + x0$ (\textit{s\_mp\_add}) \\
 9.  $t1 \leftarrow t1^2$ \\
 \\
 Compute the middle term. \\
 10.  $t2 \leftarrow x0x0 + x1x1$ (\textit{s\_mp\_add}) \\
-11.  $t1 \leftarrow t2 - t1$ \\
+11.  $t1 \leftarrow t1 - t2$ \\
 \\
 Compute final product. \\
 12.  $t1 \leftarrow t1\beta^B$ (\textit{mp\_lshd}) \\
@@ -5268,7 +5297,7 @@
 placed just below the middle.  Step 3, 4 and 5 compute the two halves required using $B$
 as the radix point.  The first two squares in steps 6 and 7 are rather straightforward while the last square is of a more compact form.
 
-By expanding $\left (x1 - x0 \right )^2$, the $x1^2$ and $x0^2$ terms in the middle disappear, that is $x1^2 + x0^2 - (x1 - x0)^2 = 2 \cdot x0 \cdot x1$.
+By expanding $\left (x1 + x0 \right )^2$, the $x1^2$ and $x0^2$ terms in the middle disappear, that is $(x0 - x1)^2 - (x1^2 + x0^2)  = 2 \cdot x0 \cdot x1$.
 Now if $5n$ single precision additions and a squaring of $n$-digits is faster than multiplying two $n$-digit numbers and doubling then
 this method is faster.  Assuming no further recursions occur, the difference can be estimated with the following inequality.
 
@@ -5363,8 +5392,8 @@
 079     if (mp_sqr (&x1, &x1x1) != MP_OKAY)
 080       goto X1X1;           /* x1x1 = x1*x1 */
 081   
-082     /* now calc (x1-x0)**2 */
-083     if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
+082     /* now calc (x1+x0)**2 */
+083     if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
 084       goto X1X1;           /* t1 = x1 - x0 */
 085     if (mp_sqr (&t1, &t1) != MP_OKAY)
 086       goto X1X1;           /* t1 = (x1 - x0) * (x1 - x0) */
@@ -5372,8 +5401,8 @@
 088     /* add x0y0 */
 089     if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
 090       goto X1X1;           /* t2 = x0x0 + x1x1 */
-091     if (mp_sub (&t2, &t1, &t1) != MP_OKAY)
-092       goto X1X1;           /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */
+091     if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
+092       goto X1X1;           /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
 093   
 094     /* shift by B */
 095     if (mp_lshd (&t1, B) != MP_OKAY)
@@ -5398,6 +5427,7 @@
 114     return err;
 115   \}
 116   #endif
+117   
 \end{alltt}
 \end{small}
 
@@ -5494,6 +5524,7 @@
 051     return res;
 052   \}
 053   #endif
+054   
 \end{alltt}
 \end{small}
 
@@ -5827,6 +5858,7 @@
 093     return res;
 094   \}
 095   #endif
+096   
 \end{alltt}
 \end{small}
 
@@ -5879,6 +5911,7 @@
 027     return mp_div (a, b, a, NULL);
 028   \}
 029   #endif
+030   
 \end{alltt}
 \end{small}
 
@@ -5943,6 +5976,7 @@
 \hline $6$ & $x/2 = 139$ \\
 \hline $7$ & $x + n = 396$, $x/2 = 198$ \\
 \hline $8$ & $x/2 = 99$ \\
+\hline $9$ & $x + n = 356$, $x/2 = 178$ \\
 \hline
 \end{tabular}
 \end{center}
@@ -5951,8 +5985,8 @@
 \label{fig:MONT1}
 \end{figure}
 
-Consider the example in figure~\ref{fig:MONT1} which reduces $x = 5555$ modulo $n = 257$ when $k = 8$.  The result of the algorithm $r = 99$ is
-congruent to the value of $2^{-8} \cdot 5555 \mbox{ (mod }257\mbox{)}$.  When $r$ is multiplied by $2^8$ modulo $257$ the correct residue 
+Consider the example in figure~\ref{fig:MONT1} which reduces $x = 5555$ modulo $n = 257$ when $k = 9$ (note $\beta^k = 512$ which is larger than $n$).  The result of 
+the algorithm $r = 178$ is congruent to the value of $2^{-9} \cdot 5555 \mbox{ (mod }257\mbox{)}$.  When $r$ is multiplied by $2^9$ modulo $257$ the correct residue 
 $r \equiv 158$ is produced.  
 
 Let $k = \lfloor lg(n) \rfloor + 1$ represent the number of bits in $n$.  The current algorithm requires $2k^2$ single precision shifts
@@ -5964,10 +5998,10 @@
 \begin{center}
 \begin{tabular}{l}
 \hline Algorithm \textbf{Montgomery Reduction} (modified I). \\
-\textbf{Input}.   Integer $x$, $n$ and $k$ \\
+\textbf{Input}.   Integer $x$, $n$ and $k$ ($2^k > n$) \\
 \textbf{Output}.  $2^{-k}x \mbox{ (mod }n\mbox{)}$ \\
 \hline \\
-1.  for $t$ from $0$ to $k - 1$ do \\
+1.  for $t$ from $1$ to $k$ do \\
 \hspace{3mm}1.1  If the $t$'th bit of $x$ is one then \\
 \hspace{6mm}1.1.1  $x \leftarrow x + 2^tn$ \\
 2.  Return $x/2^k$. \\
@@ -5995,7 +6029,8 @@
 \hline $6$ & $8896$ & $10001011000000$ \\
 \hline $7$ & $x + 2^{6}n = 25344$ & $110001100000000$ \\
 \hline $8$ & $25344$ & $110001100000000$ \\
-\hline -- & $x/2^k = 99$ & \\
+\hline $9$ & $x + 2^{7}n = 91136$ & $10110010000000000$ \\
+\hline -- & $x/2^k = 178$ & \\
 \hline
 \end{tabular}
 \end{center}
@@ -6004,7 +6039,7 @@
 \label{fig:MONT2}
 \end{figure}
 
-Figure~\ref{fig:MONT2} demonstrates the modified algorithm reducing $x = 5555$ modulo $n = 257$ with $k = 8$. 
+Figure~\ref{fig:MONT2} demonstrates the modified algorithm reducing $x = 5555$ modulo $n = 257$ with $k = 9$. 
 With this algorithm a single shift right at the end is the only right shift required to reduce the input instead of $k$ right shifts inside the 
 loop.  Note that for the iterations $t = 2, 5, 6$ and $8$ where the result $x$ is not changed.  In those iterations the $t$'th bit of $x$ is 
 zero and the appropriate multiple of $n$ does not need to be added to force the $t$'th bit of the result to zero.  
@@ -6018,7 +6053,7 @@
 \begin{center}
 \begin{tabular}{l}
 \hline Algorithm \textbf{Montgomery Reduction} (modified II). \\
-\textbf{Input}.   Integer $x$, $n$ and $k$ \\
+\textbf{Input}.   Integer $x$, $n$ and $k$ ($\beta^k > n$) \\
 \textbf{Output}.  $\beta^{-k}x \mbox{ (mod }n\mbox{)}$ \\
 \hline \\
 1.  for $t$ from $0$ to $k - 1$ do \\
@@ -6234,6 +6269,7 @@
 111     return MP_OKAY;
 112   \}
 113   #endif
+114   
 \end{alltt}
 \end{small}
 
@@ -6478,6 +6514,7 @@
 165     return MP_OKAY;
 166   \}
 167   #endif
+168   
 \end{alltt}
 \end{small}
 
@@ -6505,7 +6542,7 @@
 \hline \\
 1.  $b \leftarrow n_0$ \\
 2.  If $b$ is even return(\textit{MP\_VAL}) \\
-3.  $x \leftarrow ((b + 2) \mbox{ AND } 4) << 1) + b$ \\
+3.  $x \leftarrow (((b + 2) \mbox{ AND } 4) << 1) + b$ \\
 4.  for $k$ from 0 to $\lceil lg(lg(\beta)) \rceil - 2$ do \\
 \hspace{3mm}4.1  $x \leftarrow x \cdot (2 - bx)$ \\
 5.  $\rho \leftarrow \beta - x \mbox{ (mod }\beta\mbox{)}$ \\
@@ -6559,11 +6596,13 @@
 047   #endif
 048   
 049     /* rho = -1/m mod b */
-050     *rho = (((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
+050     *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MAS
+      K;
 051   
 052     return MP_OKAY;
 053   \}
 054   #endif
+055   
 \end{alltt}
 \end{small}
 
@@ -6830,6 +6869,7 @@
 087     return MP_OKAY;
 088   \}
 089   #endif
+090   
 \end{alltt}
 \end{small}
 
@@ -6885,6 +6925,7 @@
 025   \}
 026   
 027   #endif
+028   
 \end{alltt}
 \end{small}
 
@@ -6943,6 +6984,7 @@
 036   \}
 037   
 038   #endif
+039   
 \end{alltt}
 \end{small}
 
@@ -7027,6 +7069,7 @@
 054   \}
 055   
 056   #endif
+057   
 \end{alltt}
 \end{small}
 
@@ -7096,6 +7139,7 @@
 040      return MP_OKAY;
 041   \}
 042   #endif
+043   
 \end{alltt}
 \end{small}
 
@@ -7172,6 +7216,7 @@
 045   \}
 046   
 047   #endif
+048   
 \end{alltt}
 \end{small}
 
@@ -7381,6 +7426,7 @@
 050     return MP_OKAY;
 051   \}
 052   #endif
+053   
 \end{alltt}
 \end{small}
 
@@ -7620,7 +7666,8 @@
 065     \}
 066   
 067   /* modified diminished radix reduction */
-068   #if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C)
+068   #if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defin
+      ed(BN_S_MP_EXPTMOD_C)
 069     if (mp_reduce_is_2k_l(P) == MP_YES) \{
 070        return s_mp_exptmod(G, X, P, Y, 1);
 071     \}
@@ -7660,6 +7707,7 @@
 105   \}
 106   
 107   #endif
+108   
 \end{alltt}
 \end{small}
 
@@ -7839,252 +7887,252 @@
 \hspace{-5.1mm}{\bf File}: bn\_s\_mp\_exptmod.c
 \vspace{-3mm}
 \begin{alltt}
-016   
-017   #ifdef MP_LOW_MEM
-018      #define TAB_SIZE 32
-019   #else
-020      #define TAB_SIZE 256
-021   #endif
-022   
-023   int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmod
+016   #ifdef MP_LOW_MEM
+017      #define TAB_SIZE 32
+018   #else
+019      #define TAB_SIZE 256
+020   #endif
+021   
+022   int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmod
       e)
-024   \{
-025     mp_int  M[TAB_SIZE], res, mu;
-026     mp_digit buf;
-027     int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
-028     int (*redux)(mp_int*,mp_int*,mp_int*);
-029   
-030     /* find window size */
-031     x = mp_count_bits (X);
-032     if (x <= 7) \{
-033       winsize = 2;
-034     \} else if (x <= 36) \{
-035       winsize = 3;
-036     \} else if (x <= 140) \{
-037       winsize = 4;
-038     \} else if (x <= 450) \{
-039       winsize = 5;
-040     \} else if (x <= 1303) \{
-041       winsize = 6;
-042     \} else if (x <= 3529) \{
-043       winsize = 7;
-044     \} else \{
-045       winsize = 8;
-046     \}
-047   
-048   #ifdef MP_LOW_MEM
-049       if (winsize > 5) \{
-050          winsize = 5;
-051       \}
-052   #endif
-053   
-054     /* init M array */
-055     /* init first cell */
-056     if ((err = mp_init(&M[1])) != MP_OKAY) \{
-057        return err; 
-058     \}
-059   
-060     /* now init the second half of the array */
-061     for (x = 1<<(winsize-1); x < (1 << winsize); x++) \{
-062       if ((err = mp_init(&M[x])) != MP_OKAY) \{
-063         for (y = 1<<(winsize-1); y < x; y++) \{
-064           mp_clear (&M[y]);
-065         \}
-066         mp_clear(&M[1]);
-067         return err;
-068       \}
-069     \}
-070   
-071     /* create mu, used for Barrett reduction */
-072     if ((err = mp_init (&mu)) != MP_OKAY) \{
-073       goto LBL_M;
-074     \}
-075     
-076     if (redmode == 0) \{
-077        if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) \{
-078           goto LBL_MU;
-079        \}
-080        redux = mp_reduce;
-081     \} else \{
-082        if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) \{
-083           goto LBL_MU;
-084        \}
-085        redux = mp_reduce_2k_l;
-086     \}    
-087   
-088     /* create M table
-089      *
-090      * The M table contains powers of the base, 
-091      * e.g. M[x] = G**x mod P
-092      *
-093      * The first half of the table is not 
-094      * computed though accept for M[0] and M[1]
-095      */
-096     if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) \{
-097       goto LBL_MU;
-098     \}
-099   
-100     /* compute the value at M[1<<(winsize-1)] by squaring 
-101      * M[1] (winsize-1) times 
-102      */
-103     if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) \{
-104       goto LBL_MU;
-105     \}
-106   
-107     for (x = 0; x < (winsize - 1); x++) \{
-108       /* square it */
-109       if ((err = mp_sqr (&M[1 << (winsize - 1)], 
-110                          &M[1 << (winsize - 1)])) != MP_OKAY) \{
-111         goto LBL_MU;
-112       \}
-113   
-114       /* reduce modulo P */
-115       if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) \{
-116         goto LBL_MU;
-117       \}
-118     \}
-119   
-120     /* create upper table, that is M[x] = M[x-1] * M[1] (mod P)
-121      * for x = (2**(winsize - 1) + 1) to (2**winsize - 1)
-122      */
-123     for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) \{
-124       if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) \{
-125         goto LBL_MU;
-126       \}
-127       if ((err = redux (&M[x], P, &mu)) != MP_OKAY) \{
-128         goto LBL_MU;
-129       \}
-130     \}
-131   
-132     /* setup result */
-133     if ((err = mp_init (&res)) != MP_OKAY) \{
-134       goto LBL_MU;
-135     \}
-136     mp_set (&res, 1);
-137   
-138     /* set initial mode and bit cnt */
-139     mode   = 0;
-140     bitcnt = 1;
-141     buf    = 0;
-142     digidx = X->used - 1;
-143     bitcpy = 0;
-144     bitbuf = 0;
-145   
-146     for (;;) \{
-147       /* grab next digit as required */
-148       if (--bitcnt == 0) \{
-149         /* if digidx == -1 we are out of digits */
-150         if (digidx == -1) \{
-151           break;
-152         \}
-153         /* read next digit and reset the bitcnt */
-154         buf    = X->dp[digidx--];
-155         bitcnt = (int) DIGIT_BIT;
-156       \}
-157   
-158       /* grab the next msb from the exponent */
-159       y     = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1;
-160       buf <<= (mp_digit)1;
-161   
-162       /* if the bit is zero and mode == 0 then we ignore it
-163        * These represent the leading zero bits before the first 1 bit
-164        * in the exponent.  Technically this opt is not required but it
-165        * does lower the # of trivial squaring/reductions used
-166        */
-167       if (mode == 0 && y == 0) \{
-168         continue;
-169       \}
-170   
-171       /* if the bit is zero and mode == 1 then we square */
-172       if (mode == 1 && y == 0) \{
-173         if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-174           goto LBL_RES;
-175         \}
-176         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
-177           goto LBL_RES;
-178         \}
-179         continue;
-180       \}
-181   
-182       /* else we add it to the window */
-183       bitbuf |= (y << (winsize - ++bitcpy));
-184       mode    = 2;
-185   
-186       if (bitcpy == winsize) \{
-187         /* ok window is filled so square as required and multiply  */
-188         /* square first */
-189         for (x = 0; x < winsize; x++) \{
-190           if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-191             goto LBL_RES;
-192           \}
-193           if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
-194             goto LBL_RES;
-195           \}
-196         \}
-197   
-198         /* then multiply */
-199         if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) \{
-200           goto LBL_RES;
-201         \}
-202         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
-203           goto LBL_RES;
-204         \}
-205   
-206         /* empty window and reset */
-207         bitcpy = 0;
-208         bitbuf = 0;
-209         mode   = 1;
-210       \}
-211     \}
-212   
-213     /* if bits remain then square/multiply */
-214     if (mode == 2 && bitcpy > 0) \{
-215       /* square then multiply if the bit is set */
-216       for (x = 0; x < bitcpy; x++) \{
-217         if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
-218           goto LBL_RES;
-219         \}
-220         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
-221           goto LBL_RES;
-222         \}
-223   
-224         bitbuf <<= 1;
-225         if ((bitbuf & (1 << winsize)) != 0) \{
-226           /* then multiply */
-227           if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) \{
-228             goto LBL_RES;
-229           \}
-230           if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
-231             goto LBL_RES;
-232           \}
-233         \}
-234       \}
-235     \}
-236   
-237     mp_exch (&res, Y);
-238     err = MP_OKAY;
-239   LBL_RES:mp_clear (&res);
-240   LBL_MU:mp_clear (&mu);
-241   LBL_M:
-242     mp_clear(&M[1]);
-243     for (x = 1<<(winsize-1); x < (1 << winsize); x++) \{
-244       mp_clear (&M[x]);
-245     \}
-246     return err;
-247   \}
-248   #endif
+023   \{
+024     mp_int  M[TAB_SIZE], res, mu;
+025     mp_digit buf;
+026     int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
+027     int (*redux)(mp_int*,mp_int*,mp_int*);
+028   
+029     /* find window size */
+030     x = mp_count_bits (X);
+031     if (x <= 7) \{
+032       winsize = 2;
+033     \} else if (x <= 36) \{
+034       winsize = 3;
+035     \} else if (x <= 140) \{
+036       winsize = 4;
+037     \} else if (x <= 450) \{
+038       winsize = 5;
+039     \} else if (x <= 1303) \{
+040       winsize = 6;
+041     \} else if (x <= 3529) \{
+042       winsize = 7;
+043     \} else \{
+044       winsize = 8;
+045     \}
+046   
+047   #ifdef MP_LOW_MEM
+048       if (winsize > 5) \{
+049          winsize = 5;
+050       \}
+051   #endif
+052   
+053     /* init M array */
+054     /* init first cell */
+055     if ((err = mp_init(&M[1])) != MP_OKAY) \{
+056        return err; 
+057     \}
+058   
+059     /* now init the second half of the array */
+060     for (x = 1<<(winsize-1); x < (1 << winsize); x++) \{
+061       if ((err = mp_init(&M[x])) != MP_OKAY) \{
+062         for (y = 1<<(winsize-1); y < x; y++) \{
+063           mp_clear (&M[y]);
+064         \}
+065         mp_clear(&M[1]);
+066         return err;
+067       \}
+068     \}
+069   
+070     /* create mu, used for Barrett reduction */
+071     if ((err = mp_init (&mu)) != MP_OKAY) \{
+072       goto LBL_M;
+073     \}
+074     
+075     if (redmode == 0) \{
+076        if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) \{
+077           goto LBL_MU;
+078        \}
+079        redux = mp_reduce;
+080     \} else \{
+081        if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) \{
+082           goto LBL_MU;
+083        \}
+084        redux = mp_reduce_2k_l;
+085     \}    
+086   
+087     /* create M table
+088      *
+089      * The M table contains powers of the base, 
+090      * e.g. M[x] = G**x mod P
+091      *
+092      * The first half of the table is not 
+093      * computed though accept for M[0] and M[1]
+094      */
+095     if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) \{
+096       goto LBL_MU;
+097     \}
+098   
+099     /* compute the value at M[1<<(winsize-1)] by squaring 
+100      * M[1] (winsize-1) times 
+101      */
+102     if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) \{
+103       goto LBL_MU;
+104     \}
+105   
+106     for (x = 0; x < (winsize - 1); x++) \{
+107       /* square it */
+108       if ((err = mp_sqr (&M[1 << (winsize - 1)], 
+109                          &M[1 << (winsize - 1)])) != MP_OKAY) \{
+110         goto LBL_MU;
+111       \}
+112   
+113       /* reduce modulo P */
+114       if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) \{
+115         goto LBL_MU;
+116       \}
+117     \}
+118   
+119     /* create upper table, that is M[x] = M[x-1] * M[1] (mod P)
+120      * for x = (2**(winsize - 1) + 1) to (2**winsize - 1)
+121      */
+122     for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) \{
+123       if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) \{
+124         goto LBL_MU;
+125       \}
+126       if ((err = redux (&M[x], P, &mu)) != MP_OKAY) \{
+127         goto LBL_MU;
+128       \}
+129     \}
+130   
+131     /* setup result */
+132     if ((err = mp_init (&res)) != MP_OKAY) \{
+133       goto LBL_MU;
+134     \}
+135     mp_set (&res, 1);
+136   
+137     /* set initial mode and bit cnt */
+138     mode   = 0;
+139     bitcnt = 1;
+140     buf    = 0;
+141     digidx = X->used - 1;
+142     bitcpy = 0;
+143     bitbuf = 0;
+144   
+145     for (;;) \{
+146       /* grab next digit as required */
+147       if (--bitcnt == 0) \{
+148         /* if digidx == -1 we are out of digits */
+149         if (digidx == -1) \{
+150           break;
+151         \}
+152         /* read next digit and reset the bitcnt */
+153         buf    = X->dp[digidx--];
+154         bitcnt = (int) DIGIT_BIT;
+155       \}
+156   
+157       /* grab the next msb from the exponent */
+158       y     = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1;
+159       buf <<= (mp_digit)1;
+160   
+161       /* if the bit is zero and mode == 0 then we ignore it
+162        * These represent the leading zero bits before the first 1 bit
+163        * in the exponent.  Technically this opt is not required but it
+164        * does lower the # of trivial squaring/reductions used
+165        */
+166       if (mode == 0 && y == 0) \{
+167         continue;
+168       \}
+169   
+170       /* if the bit is zero and mode == 1 then we square */
+171       if (mode == 1 && y == 0) \{
+172         if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
+173           goto LBL_RES;
+174         \}
+175         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
+176           goto LBL_RES;
+177         \}
+178         continue;
+179       \}
+180   
+181       /* else we add it to the window */
+182       bitbuf |= (y << (winsize - ++bitcpy));
+183       mode    = 2;
+184   
+185       if (bitcpy == winsize) \{
+186         /* ok window is filled so square as required and multiply  */
+187         /* square first */
+188         for (x = 0; x < winsize; x++) \{
+189           if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
+190             goto LBL_RES;
+191           \}
+192           if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
+193             goto LBL_RES;
+194           \}
+195         \}
+196   
+197         /* then multiply */
+198         if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) \{
+199           goto LBL_RES;
+200         \}
+201         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
+202           goto LBL_RES;
+203         \}
+204   
+205         /* empty window and reset */
+206         bitcpy = 0;
+207         bitbuf = 0;
+208         mode   = 1;
+209       \}
+210     \}
+211   
+212     /* if bits remain then square/multiply */
+213     if (mode == 2 && bitcpy > 0) \{
+214       /* square then multiply if the bit is set */
+215       for (x = 0; x < bitcpy; x++) \{
+216         if ((err = mp_sqr (&res, &res)) != MP_OKAY) \{
+217           goto LBL_RES;
+218         \}
+219         if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
+220           goto LBL_RES;
+221         \}
+222   
+223         bitbuf <<= 1;
+224         if ((bitbuf & (1 << winsize)) != 0) \{
+225           /* then multiply */
+226           if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) \{
+227             goto LBL_RES;
+228           \}
+229           if ((err = redux (&res, P, &mu)) != MP_OKAY) \{
+230             goto LBL_RES;
+231           \}
+232         \}
+233       \}
+234     \}
+235   
+236     mp_exch (&res, Y);
+237     err = MP_OKAY;
+238   LBL_RES:mp_clear (&res);
+239   LBL_MU:mp_clear (&mu);
+240   LBL_M:
+241     mp_clear(&M[1]);
+242     for (x = 1<<(winsize-1); x < (1 << winsize); x++) \{
+243       mp_clear (&M[x]);
+244     \}
+245     return err;
+246   \}
+247   #endif
+248   
 \end{alltt}
 \end{small}
 
-Lines 21 through 40 determine the optimal window size based on the length of the exponent in bits.  The window divisions are sorted
+Lines 31 through 45 determine the optimal window size based on the length of the exponent in bits.  The window divisions are sorted
 from smallest to greatest so that in each \textbf{if} statement only one condition must be tested.  For example, by the \textbf{if} statement 
-on line 32 the value of $x$ is already known to be greater than $140$.  
-
-The conditional piece of code beginning on line 48 allows the window size to be restricted to five bits.  This logic is used to ensure
+on line 37 the value of $x$ is already known to be greater than $140$.  
+
+The conditional piece of code beginning on line 47 allows the window size to be restricted to five bits.  This logic is used to ensure
 the table of precomputed powers of $G$ remains relatively small.  
 
-The for loop on line 61 initializes the $M$ array while lines 62 and 77 compute the value of $\mu$ required for
-Barrett reduction.  
+The for loop on line 60 initializes the $M$ array while lines 71 and 76 through 85 initialize the reduction
+function that will be used for this modulus.
 
 -- More later.
 
@@ -8146,6 +8194,7 @@
 041     return MP_OKAY;
 042   \}
 043   #endif
+044   
 \end{alltt}
 \end{small}
 
@@ -8666,6 +8715,7 @@
 285   #endif
 286   
 287   #endif
+288   
 \end{alltt}
 \end{small}
 
@@ -8677,23 +8727,23 @@
 mp_div(&a, &b, &c, NULL);  /* c = [a/b] */
 \end{verbatim}
 
-Lines 37 and 44 handle the two trivial cases of inputs which are division by zero and dividend smaller than the divisor 
-respectively.  After the two trivial cases all of the temporary variables are initialized.  Line 105 determines the sign of 
-the quotient and line 76 ensures that both $x$ and $y$ are positive.  
-
-The number of bits in the leading digit is calculated on line 105.  Implictly an mp\_int with $r$ digits will require $lg(\beta)(r-1) + k$ bits
+Lines 108 and 113 handle the two trivial cases of inputs which are division by zero and dividend smaller than the divisor 
+respectively.  After the two trivial cases all of the temporary variables are initialized.  Line 147 determines the sign of 
+the quotient and line 148 ensures that both $x$ and $y$ are positive.  
+
+The number of bits in the leading digit is calculated on line 151.  Implictly an mp\_int with $r$ digits will require $lg(\beta)(r-1) + k$ bits
 of precision which when reduced modulo $lg(\beta)$ produces the value of $k$.  In this case $k$ is the number of bits in the leading digit which is
 exactly what is required.  For the algorithm to operate $k$ must equal $lg(\beta) - 1$ and when it does not the inputs must be normalized by shifting
 them to the left by $lg(\beta) - 1 - k$ bits.
 
 Throughout the variables $n$ and $t$ will represent the highest digit of $x$ and $y$ respectively.  These are first used to produce the 
-leading digit of the quotient.  The loop beginning on line 183 will produce the remainder of the quotient digits.
-
-The conditional ``continue'' on line 114 is used to prevent the algorithm from reading past the leading edge of $x$ which can occur when the
+leading digit of the quotient.  The loop beginning on line 184 will produce the remainder of the quotient digits.
+
+The conditional ``continue'' on line 186 is used to prevent the algorithm from reading past the leading edge of $x$ which can occur when the
 algorithm eliminates multiple non-zero digits in a single iteration.  This ensures that $x_i$ is always non-zero since by definition the digits
 above the $i$'th position $x$ must be zero in order for the quotient to be precise\footnote{Precise as far as integer division is concerned.}.  
 
-Lines 130, 130 and 134 through 134 manually construct the high accuracy estimations by setting the digits of the two mp\_int 
+Lines 214, 216 and 222 through 225 manually construct the high accuracy estimations by setting the digits of the two mp\_int 
 variables directly.  
 
 \section{Single Digit Helpers}
@@ -8757,69 +8807,73 @@
 039        /* fix sign  */
 040        a->sign = c->sign = MP_NEG;
 041   
-042        return res;
-043     \}
+042        /* clamp */
+043        mp_clamp(c);
 044   
-045     /* old number of used digits in c */
-046     oldused = c->used;
+045        return res;
+046     \}
 047   
-048     /* sign always positive */
-049     c->sign = MP_ZPOS;
+048     /* old number of used digits in c */
+049     oldused = c->used;
 050   
-051     /* source alias */
-052     tmpa    = a->dp;
+051     /* sign always positive */
+052     c->sign = MP_ZPOS;
 053   
-054     /* destination alias */
-055     tmpc    = c->dp;
+054     /* source alias */
+055     tmpa    = a->dp;
 056   
-057     /* if a is positive */
-058     if (a->sign == MP_ZPOS) \{
-059        /* add digit, after this we're propagating
-060         * the carry.
-061         */
-062        *tmpc   = *tmpa++ + b;
-063        mu      = *tmpc >> DIGIT_BIT;
-064        *tmpc++ &= MP_MASK;
-065   
-066        /* now handle rest of the digits */
-067        for (ix = 1; ix < a->used; ix++) \{
-068           *tmpc   = *tmpa++ + mu;
-069           mu      = *tmpc >> DIGIT_BIT;
-070           *tmpc++ &= MP_MASK;
-071        \}
-072        /* set final carry */
-073        ix++;
-074        *tmpc++  = mu;
-075   
-076        /* setup size */
-077        c->used = a->used + 1;
-078     \} else \{
-079        /* a was negative and |a| < b */
-080        c->used  = 1;
-081   
-082        /* the result is a single digit */
-083        if (a->used == 1) \{
-084           *tmpc++  =  b - a->dp[0];
-085        \} else \{
-086           *tmpc++  =  b;
-087        \}
-088   
-089        /* setup count so the clearing of oldused
-090         * can fall through correctly
-091         */
-092        ix       = 1;
-093     \}
-094   
-095     /* now zero to oldused */
-096     while (ix++ < oldused) \{
-097        *tmpc++ = 0;
-098     \}
-099     mp_clamp(c);
-100   
-101     return MP_OKAY;
-102   \}
+057     /* destination alias */
+058     tmpc    = c->dp;
+059   
+060     /* if a is positive */
+061     if (a->sign == MP_ZPOS) \{
+062        /* add digit, after this we're propagating
+063         * the carry.
+064         */
+065        *tmpc   = *tmpa++ + b;
+066        mu      = *tmpc >> DIGIT_BIT;
+067        *tmpc++ &= MP_MASK;
+068   
+069        /* now handle rest of the digits */
+070        for (ix = 1; ix < a->used; ix++) \{
+071           *tmpc   = *tmpa++ + mu;
+072           mu      = *tmpc >> DIGIT_BIT;
+073           *tmpc++ &= MP_MASK;
+074        \}
+075        /* set final carry */
+076        ix++;
+077        *tmpc++  = mu;
+078   
+079        /* setup size */
+080        c->used = a->used + 1;
+081     \} else \{
+082        /* a was negative and |a| < b */
+083        c->used  = 1;
+084   
+085        /* the result is a single digit */
+086        if (a->used == 1) \{
+087           *tmpc++  =  b - a->dp[0];
+088        \} else \{
+089           *tmpc++  =  b;
+090        \}
+091   
+092        /* setup count so the clearing of oldused
+093         * can fall through correctly
+094         */
+095        ix       = 1;
+096     \}
+097   
+098     /* now zero to oldused */
+099     while (ix++ < oldused) \{
+100        *tmpc++ = 0;
+101     \}
+102     mp_clamp(c);
 103   
-104   #endif
+104     return MP_OKAY;
+105   \}
+106   
+107   #endif
+108   
 \end{alltt}
 \end{small}
 
@@ -8929,6 +8983,7 @@
 072     return MP_OKAY;
 073   \}
 074   #endif
+075   
 \end{alltt}
 \end{small}
 
@@ -9074,6 +9129,7 @@
 103   \}
 104   
 105   #endif
+106   
 \end{alltt}
 \end{small}
 
@@ -9260,6 +9316,7 @@
 125     return res;
 126   \}
 127   #endif
+128   
 \end{alltt}
 \end{small}
 
@@ -9336,6 +9393,7 @@
 048     return MP_OKAY;
 049   \}
 050   #endif
+051   
 \end{alltt}
 \end{small}
 
@@ -9425,61 +9483,65 @@
 020     int     y, res, neg;
 021     char    ch;
 022   
-023     /* make sure the radix is ok */
-024     if (radix < 2 || radix > 64) \{
-025       return MP_VAL;
-026     \}
-027   
-028     /* if the leading digit is a 
-029      * minus set the sign to negative. 
-030      */
-031     if (*str == '-') \{
-032       ++str;
-033       neg = MP_NEG;
-034     \} else \{
-035       neg = MP_ZPOS;
-036     \}
-037   
-038     /* set the integer to the default of zero */
-039     mp_zero (a);
-040     
-041     /* process each digit of the string */
-042     while (*str) \{
-043       /* if the radix < 36 the conversion is case insensitive
-044        * this allows numbers like 1AB and 1ab to represent the same  value
-045        * [e.g. in hex]
-046        */
-047       ch = (char) ((radix < 36) ? toupper (*str) : *str);
-048       for (y = 0; y < 64; y++) \{
-049         if (ch == mp_s_rmap[y]) \{
-050            break;
-051         \}
-052       \}
-053   
-054       /* if the char was found in the map 
-055        * and is less than the given radix add it
-056        * to the number, otherwise exit the loop. 
-057        */
-058       if (y < radix) \{
-059         if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) \{
-060            return res;
-061         \}
-062         if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) \{
+023     /* zero the digit bignum */
+024     mp_zero(a);
+025   
+026     /* make sure the radix is ok */
+027     if (radix < 2 || radix > 64) \{
+028       return MP_VAL;
+029     \}
+030   
+031     /* if the leading digit is a 
+032      * minus set the sign to negative. 
+033      */
+034     if (*str == '-') \{
+035       ++str;
+036       neg = MP_NEG;
+037     \} else \{
+038       neg = MP_ZPOS;
+039     \}
+040   
+041     /* set the integer to the default of zero */
+042     mp_zero (a);
+043     
+044     /* process each digit of the string */
+045     while (*str) \{
+046       /* if the radix < 36 the conversion is case insensitive
+047        * this allows numbers like 1AB and 1ab to represent the same  value
+048        * [e.g. in hex]
+049        */
+050       ch = (char) ((radix < 36) ? toupper (*str) : *str);
+051       for (y = 0; y < 64; y++) \{
+052         if (ch == mp_s_rmap[y]) \{
+053            break;
+054         \}
+055       \}
+056   
+057       /* if the char was found in the map 
+058        * and is less than the given radix add it
+059        * to the number, otherwise exit the loop. 
+060        */
+061       if (y < radix) \{
+062         if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) \{
 063            return res;
 064         \}
-065       \} else \{
-066         break;
-067       \}
-068       ++str;
-069     \}
-070     
-071     /* set the sign only if a != 0 */
-072     if (mp_iszero(a) != 1) \{
-073        a->sign = neg;
-074     \}
-075     return MP_OKAY;
-076   \}
-077   #endif
+065         if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) \{
+066            return res;
+067         \}
+068       \} else \{
+069         break;
+070       \}
+071       ++str;
+072     \}
+073     
+074     /* set the sign only if a != 0 */
+075     if (mp_iszero(a) != 1) \{
+076        a->sign = neg;
+077     \}
+078     return MP_OKAY;
+079   \}
+080   #endif
+081   
 \end{alltt}
 \end{small}
 
@@ -9599,6 +9661,7 @@
 068   \}
 069   
 070   #endif
+071   
 \end{alltt}
 \end{small}
 
@@ -9728,33 +9791,30 @@
 \textbf{Input}.   mp\_int $a$ and $b$ \\
 \textbf{Output}.  The greatest common divisor $c = (a, b)$.  \\
 \hline \\
-1.  If $a = 0$ and $b \ne 0$ then \\
-\hspace{3mm}1.1  $c \leftarrow b$ \\
+1.  If $a = 0$ then \\
+\hspace{3mm}1.1  $c \leftarrow \vert b \vert $ \\
 \hspace{3mm}1.2  Return(\textit{MP\_OKAY}). \\
-2.  If $a \ne 0$ and $b = 0$ then \\
-\hspace{3mm}2.1  $c \leftarrow a$ \\
+2.  If $b = 0$ then \\
+\hspace{3mm}2.1  $c \leftarrow \vert a \vert $ \\
 \hspace{3mm}2.2  Return(\textit{MP\_OKAY}). \\
-3.  If $a = b = 0$ then \\
-\hspace{3mm}3.1  $c \leftarrow 1$ \\
-\hspace{3mm}3.2  Return(\textit{MP\_OKAY}). \\
-4.  $u \leftarrow \vert a \vert, v \leftarrow \vert b \vert$ \\
-5.  $k \leftarrow 0$ \\
-6.  While $u.used > 0$ and $v.used > 0$ and $u_0 \equiv v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}6.1  $k \leftarrow k + 1$ \\
-\hspace{3mm}6.2  $u \leftarrow \lfloor u / 2 \rfloor$ \\
-\hspace{3mm}6.3  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-7.  While $u.used > 0$ and $u_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}7.1  $u \leftarrow \lfloor u / 2 \rfloor$ \\
-8.  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{3mm}8.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-9.  While $v.used > 0$ \\
-\hspace{3mm}9.1  If $\vert u \vert > \vert v \vert$ then \\
-\hspace{6mm}9.1.1  Swap $u$ and $v$. \\
-\hspace{3mm}9.2  $v \leftarrow \vert v \vert - \vert u \vert$ \\
-\hspace{3mm}9.3  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
-\hspace{6mm}9.3.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
-10.  $c \leftarrow u \cdot 2^k$ \\
-11.  Return(\textit{MP\_OKAY}). \\
+3.  $u \leftarrow \vert a \vert, v \leftarrow \vert b \vert$ \\
+4.  $k \leftarrow 0$ \\
+5.  While $u.used > 0$ and $v.used > 0$ and $u_0 \equiv v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}5.1  $k \leftarrow k + 1$ \\
+\hspace{3mm}5.2  $u \leftarrow \lfloor u / 2 \rfloor$ \\
+\hspace{3mm}5.3  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+6.  While $u.used > 0$ and $u_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}6.1  $u \leftarrow \lfloor u / 2 \rfloor$ \\
+7.  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{3mm}7.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+8.  While $v.used > 0$ \\
+\hspace{3mm}8.1  If $\vert u \vert > \vert v \vert$ then \\
+\hspace{6mm}8.1.1  Swap $u$ and $v$. \\
+\hspace{3mm}8.2  $v \leftarrow \vert v \vert - \vert u \vert$ \\
+\hspace{3mm}8.3  While $v.used > 0$ and $v_0 \equiv 0 \mbox{ (mod }2\mbox{)}$ \\
+\hspace{6mm}8.3.1  $v \leftarrow \lfloor v / 2 \rfloor$ \\
+9.  $c \leftarrow u \cdot 2^k$ \\
+10.  Return(\textit{MP\_OKAY}). \\
 \hline
 \end{tabular}
 \end{center}
@@ -9766,17 +9826,17 @@
 Knuth \cite[pp. 338]{TAOCPV2} but has been modified to be simpler to explain.  In theory it achieves the same asymptotic working time as
 Algorithm B and in practice this appears to be true.  
 
-The first three steps handle the cases where either one of or both inputs are zero.  If either input is zero the greatest common divisor is the 
+The first two steps handle the cases where either one of or both inputs are zero.  If either input is zero the greatest common divisor is the 
 largest input or zero if they are both zero.  If the inputs are not trivial than $u$ and $v$ are assigned the absolute values of 
 $a$ and $b$ respectively and the algorithm will proceed to reduce the pair.
 
-Step six will divide out any common factors of two and keep track of the count in the variable $k$.  After this step two is no longer a
+Step five will divide out any common factors of two and keep track of the count in the variable $k$.  After this step, two is no longer a
 factor of the remaining greatest common divisor between $u$ and $v$ and can be safely evenly divided out of either whenever they are even.  Step 
-seven and eight ensure that the $u$ and $v$ respectively have no more factors of two.  At most only one of the while loops will iterate since 
+six and seven ensure that the $u$ and $v$ respectively have no more factors of two.  At most only one of the while--loops will iterate since 
 they cannot both be even.
 
-By step nine both of $u$ and $v$ are odd which is required for the inner logic.  First the pair are swapped such that $v$ is equal to
-or greater than $u$.  This ensures that the subtraction on step 9.2 will always produce a positive and even result.  Step 9.3 removes any
+By step eight both of $u$ and $v$ are odd which is required for the inner logic.  First the pair are swapped such that $v$ is equal to
+or greater than $u$.  This ensures that the subtraction on step 8.2 will always produce a positive and even result.  Step 8.3 removes any
 factors of two from the difference $u$ to ensure that in the next iteration of the loop both are once again odd.
 
 After $v = 0$ occurs the variable $u$ has the greatest common divisor of the pair $\left < u, v \right >$ just after step six.  The result
@@ -9794,108 +9854,101 @@
 021     int     k, u_lsb, v_lsb, res;
 022   
 023     /* either zero than gcd is the largest */
-024     if (mp_iszero (a) == 1 && mp_iszero (b) == 0) \{
+024     if (mp_iszero (a) == MP_YES) \{
 025       return mp_abs (b, c);
 026     \}
-027     if (mp_iszero (a) == 0 && mp_iszero (b) == 1) \{
+027     if (mp_iszero (b) == MP_YES) \{
 028       return mp_abs (a, c);
 029     \}
 030   
-031     /* optimized.  At this point if a == 0 then
-032      * b must equal zero too
-033      */
-034     if (mp_iszero (a) == 1) \{
-035       mp_zero(c);
-036       return MP_OKAY;
-037     \}
-038   
-039     /* get copies of a and b we can modify */
-040     if ((res = mp_init_copy (&u, a)) != MP_OKAY) \{
-041       return res;
-042     \}
-043   
-044     if ((res = mp_init_copy (&v, b)) != MP_OKAY) \{
-045       goto LBL_U;
-046     \}
+031     /* get copies of a and b we can modify */
+032     if ((res = mp_init_copy (&u, a)) != MP_OKAY) \{
+033       return res;
+034     \}
+035   
+036     if ((res = mp_init_copy (&v, b)) != MP_OKAY) \{
+037       goto LBL_U;
+038     \}
+039   
+040     /* must be positive for the remainder of the algorithm */
+041     u.sign = v.sign = MP_ZPOS;
+042   
+043     /* B1.  Find the common power of two for u and v */
+044     u_lsb = mp_cnt_lsb(&u);
+045     v_lsb = mp_cnt_lsb(&v);
+046     k     = MIN(u_lsb, v_lsb);
 047   
-048     /* must be positive for the remainder of the algorithm */
-049     u.sign = v.sign = MP_ZPOS;
-050   
-051     /* B1.  Find the common power of two for u and v */
-052     u_lsb = mp_cnt_lsb(&u);
-053     v_lsb = mp_cnt_lsb(&v);
-054     k     = MIN(u_lsb, v_lsb);
-055   
-056     if (k > 0) \{
-057        /* divide the power of two out */
-058        if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) \{
-059           goto LBL_V;
-060        \}
-061   
-062        if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) \{
-063           goto LBL_V;
-064        \}
-065     \}
-066   
-067     /* divide any remaining factors of two out */
-068     if (u_lsb != k) \{
-069        if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) \{
-070           goto LBL_V;
-071        \}
-072     \}
-073   
-074     if (v_lsb != k) \{
-075        if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) \{
-076           goto LBL_V;
+048     if (k > 0) \{
+049        /* divide the power of two out */
+050        if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) \{
+051           goto LBL_V;
+052        \}
+053   
+054        if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) \{
+055           goto LBL_V;
+056        \}
+057     \}
+058   
+059     /* divide any remaining factors of two out */
+060     if (u_lsb != k) \{
+061        if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) \{
+062           goto LBL_V;
+063        \}
+064     \}
+065   
+066     if (v_lsb != k) \{
+067        if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) \{
+068           goto LBL_V;
+069        \}
+070     \}
+071   
+072     while (mp_iszero(&v) == 0) \{
+073        /* make sure v is the largest */
+074        if (mp_cmp_mag(&u, &v) == MP_GT) \{
+075           /* swap u and v to make sure v is >= u */
+076           mp_exch(&u, &v);
 077        \}
-078     \}
-079   
-080     while (mp_iszero(&v) == 0) \{
-081        /* make sure v is the largest */
-082        if (mp_cmp_mag(&u, &v) == MP_GT) \{
-083           /* swap u and v to make sure v is >= u */
-084           mp_exch(&u, &v);
-085        \}
-086        
-087        /* subtract smallest from largest */
-088        if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) \{
-089           goto LBL_V;
-090        \}
-091        
-092        /* Divide out all factors of two */
-093        if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) \{
-094           goto LBL_V;
-095        \} 
-096     \} 
-097   
-098     /* multiply by 2**k which we divided out at the beginning */
-099     if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) \{
-100        goto LBL_V;
-101     \}
-102     c->sign = MP_ZPOS;
-103     res = MP_OKAY;
-104   LBL_V:mp_clear (&u);
-105   LBL_U:mp_clear (&v);
-106     return res;
-107   \}
-108   #endif
+078        
+079        /* subtract smallest from largest */
+080        if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) \{
+081           goto LBL_V;
+082        \}
+083        
+084        /* Divide out all factors of two */
+085        if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) \{
+086           goto LBL_V;
+087        \} 
+088     \} 
+089   
+090     /* multiply by 2**k which we divided out at the beginning */
+091     if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) \{
+092        goto LBL_V;
+093     \}
+094     c->sign = MP_ZPOS;
+095     res = MP_OKAY;
+096   LBL_V:mp_clear (&u);
+097   LBL_U:mp_clear (&v);
+098     return res;
+099   \}
+100   #endif
+101   
 \end{alltt}
 \end{small}
 
 This function makes use of the macros mp\_iszero and mp\_iseven.  The former evaluates to $1$ if the input mp\_int is equivalent to the 
 integer zero otherwise it evaluates to $0$.  The latter evaluates to $1$ if the input mp\_int represents a non-zero even integer otherwise
 it evaluates to $0$.  Note that just because mp\_iseven may evaluate to $0$ does not mean the input is odd, it could also be zero.  The three 
-trivial cases of inputs are handled on lines 24 through 37.  After those lines the inputs are assumed to be non-zero.
-
-Lines 34 and 40 make local copies $u$ and $v$ of the inputs $a$ and $b$ respectively.  At this point the common factors of two 
-must be divided out of the two inputs.  The while loop on line 80 iterates so long as both are even.  The local integer $k$ is used to
-keep track of how many factors of $2$ are pulled out of both values.  It is assumed that the number of factors will not exceed the maximum 
-value of a C ``int'' data type\footnote{Strictly speaking no array in C may have more than entries than are accessible by an ``int'' so this is not 
-a limitation.}.  
-
-At this point there are no more common factors of two in the two values.  The while loops on lines 80 and 80 remove any independent
-factors of two such that both $u$ and $v$ are guaranteed to be an odd integer before hitting the main body of the algorithm.  The while loop
-on line 80 performs the reduction of the pair until $v$ is equal to zero.  The unsigned comparison and subtraction algorithms are used in
+trivial cases of inputs are handled on lines 23 through 29.  After those lines the inputs are assumed to be non-zero.
+
+Lines 32 and 36 make local copies $u$ and $v$ of the inputs $a$ and $b$ respectively.  At this point the common factors of two 
+must be divided out of the two inputs.  The block starting at line 43 removes common factors of two by first counting the number of trailing
+zero bits in both.  The local integer $k$ is used to keep track of how many factors of $2$ are pulled out of both values.  It is assumed that 
+the number of factors will not exceed the maximum value of a C ``int'' data type\footnote{Strictly speaking no array in C may have more than 
+entries than are accessible by an ``int'' so this is not a limitation.}.  
+
+At this point there are no more common factors of two in the two values.  The divisions by a power of two on lines 61 and 67 remove 
+any independent factors of two such that both $u$ and $v$ are guaranteed to be an odd integer before hitting the main body of the algorithm.  The while loop
+on line 72 performs the reduction of the pair until $v$ is equal to zero.  The unsigned comparison and subtraction algorithms are used in
 place of the full signed routines since both values are guaranteed to be positive and the result of the subtraction is guaranteed to be non-negative.
 
 \section{Least Common Multiple}
@@ -9974,6 +10027,7 @@
 053     return res;
 054   \}
 055   #endif
+056   
 \end{alltt}
 \end{small}
 
@@ -10218,6 +10272,7 @@
 098     return res;
 099   \}
 100   #endif
+101   
 \end{alltt}
 \end{small}
 
@@ -10366,6 +10421,7 @@
 036     return MP_VAL;
 037   \}
 038   #endif
+039   
 \end{alltt}
 \end{small}
 
@@ -10467,6 +10523,7 @@
 043     return MP_OKAY;
 044   \}
 045   #endif
+046   
 \end{alltt}
 \end{small}
 
@@ -10518,6 +10575,7 @@
 054   #endif
 055   \};
 056   #endif
+057   
 \end{alltt}
 \end{small}
 
@@ -10606,6 +10664,7 @@
 055     return err;
 056   \}
 057   #endif
+058   
 \end{alltt}
 \end{small}
 
@@ -10741,6 +10800,7 @@
 096     return err;
 097   \}
 098   #endif
+099   
 \end{alltt}
 \end{small}
 
--- a/tommath_class.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/tommath_class.h	Thu Jan 11 03:11:15 2007 +0000
@@ -687,6 +687,7 @@
 #if defined(BN_MP_READ_RADIX_C)
    #define BN_MP_ZERO_C
    #define BN_MP_S_RMAP_C
+   #define BN_MP_RADIX_SMAP_C
    #define BN_MP_MUL_D_C
    #define BN_MP_ADD_D_C
    #define BN_MP_ISZERO_C
@@ -992,3 +993,7 @@
 #else
 #define LTM_LAST
 #endif
+
+/* $Source: /cvs/libtom/libtommath/tommath_class.h,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/07/28 11:59:32 $ */
--- a/tommath_superclass.h	Wed Mar 08 13:16:18 2006 +0000
+++ b/tommath_superclass.h	Thu Jan 11 03:11:15 2007 +0000
@@ -4,7 +4,7 @@
 #define LTM_ALL
 
 /* RSA only (does not support DH/DSA/ECC) */
-// #define SC_RSA_1
+/* #define SC_RSA_1 */
 
 /* For reference.... On an Athlon64 optimizing for speed...
 
@@ -70,3 +70,7 @@
 #endif
 
 #endif
+
+/* $Source: /cvs/libtom/libtommath/tommath_superclass.h,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/14 13:29:17 $ */