changeset 1436:60fc6476e044

Update to libtommath v1.0
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:37:14 +0800
parents f849a5ca2efc
children 871b18fd7065 4f8eb331174f
files libtommath/LICENSE libtommath/Makefile.in libtommath/README.md libtommath/bn.tex libtommath/bn_error.c libtommath/bn_fast_mp_invmod.c libtommath/bn_fast_mp_montgomery_reduce.c libtommath/bn_fast_s_mp_mul_digs.c libtommath/bn_fast_s_mp_mul_high_digs.c libtommath/bn_fast_s_mp_sqr.c libtommath/bn_mp_2expt.c libtommath/bn_mp_abs.c libtommath/bn_mp_add.c libtommath/bn_mp_add_d.c libtommath/bn_mp_addmod.c libtommath/bn_mp_and.c libtommath/bn_mp_clamp.c libtommath/bn_mp_clear.c libtommath/bn_mp_clear_multi.c libtommath/bn_mp_cmp.c libtommath/bn_mp_cmp_d.c libtommath/bn_mp_cmp_mag.c libtommath/bn_mp_cnt_lsb.c libtommath/bn_mp_copy.c libtommath/bn_mp_count_bits.c libtommath/bn_mp_div.c libtommath/bn_mp_div_2.c libtommath/bn_mp_div_2d.c libtommath/bn_mp_div_3.c libtommath/bn_mp_div_d.c libtommath/bn_mp_dr_is_modulus.c libtommath/bn_mp_dr_reduce.c libtommath/bn_mp_dr_setup.c libtommath/bn_mp_exch.c libtommath/bn_mp_export.c libtommath/bn_mp_expt_d.c libtommath/bn_mp_expt_d_ex.c libtommath/bn_mp_exptmod.c libtommath/bn_mp_exptmod_fast.c libtommath/bn_mp_exteuclid.c libtommath/bn_mp_fread.c libtommath/bn_mp_fwrite.c libtommath/bn_mp_gcd.c libtommath/bn_mp_get_int.c libtommath/bn_mp_get_long.c libtommath/bn_mp_get_long_long.c libtommath/bn_mp_grow.c libtommath/bn_mp_import.c libtommath/bn_mp_init.c libtommath/bn_mp_init_copy.c libtommath/bn_mp_init_multi.c libtommath/bn_mp_init_set.c libtommath/bn_mp_init_set_int.c libtommath/bn_mp_init_size.c libtommath/bn_mp_invmod.c libtommath/bn_mp_invmod_slow.c libtommath/bn_mp_is_square.c libtommath/bn_mp_jacobi.c libtommath/bn_mp_karatsuba_mul.c libtommath/bn_mp_karatsuba_sqr.c libtommath/bn_mp_lcm.c libtommath/bn_mp_lshd.c libtommath/bn_mp_mod.c libtommath/bn_mp_mod_2d.c libtommath/bn_mp_mod_d.c libtommath/bn_mp_montgomery_calc_normalization.c libtommath/bn_mp_montgomery_reduce.c libtommath/bn_mp_montgomery_setup.c libtommath/bn_mp_mul.c libtommath/bn_mp_mul_2.c libtommath/bn_mp_mul_2d.c libtommath/bn_mp_mul_d.c libtommath/bn_mp_mulmod.c libtommath/bn_mp_n_root.c libtommath/bn_mp_n_root_ex.c libtommath/bn_mp_neg.c libtommath/bn_mp_or.c libtommath/bn_mp_prime_fermat.c libtommath/bn_mp_prime_is_divisible.c libtommath/bn_mp_prime_is_prime.c libtommath/bn_mp_prime_miller_rabin.c libtommath/bn_mp_prime_next_prime.c libtommath/bn_mp_prime_rabin_miller_trials.c libtommath/bn_mp_prime_random_ex.c libtommath/bn_mp_radix_size.c libtommath/bn_mp_radix_smap.c libtommath/bn_mp_rand.c libtommath/bn_mp_read_radix.c libtommath/bn_mp_read_signed_bin.c libtommath/bn_mp_read_unsigned_bin.c libtommath/bn_mp_reduce.c libtommath/bn_mp_reduce_2k.c libtommath/bn_mp_reduce_2k_l.c libtommath/bn_mp_reduce_2k_setup.c libtommath/bn_mp_reduce_2k_setup_l.c libtommath/bn_mp_reduce_is_2k.c libtommath/bn_mp_reduce_is_2k_l.c libtommath/bn_mp_reduce_setup.c libtommath/bn_mp_rshd.c libtommath/bn_mp_set.c libtommath/bn_mp_set_int.c libtommath/bn_mp_set_long.c libtommath/bn_mp_set_long_long.c libtommath/bn_mp_shrink.c libtommath/bn_mp_signed_bin_size.c libtommath/bn_mp_sqr.c libtommath/bn_mp_sqrmod.c libtommath/bn_mp_sqrt.c libtommath/bn_mp_sqrtmod_prime.c libtommath/bn_mp_sub.c libtommath/bn_mp_sub_d.c libtommath/bn_mp_submod.c libtommath/bn_mp_to_signed_bin.c libtommath/bn_mp_to_signed_bin_n.c libtommath/bn_mp_to_unsigned_bin.c libtommath/bn_mp_to_unsigned_bin_n.c libtommath/bn_mp_toom_mul.c libtommath/bn_mp_toom_sqr.c libtommath/bn_mp_toradix.c libtommath/bn_mp_toradix_n.c libtommath/bn_mp_unsigned_bin_size.c libtommath/bn_mp_xor.c libtommath/bn_mp_zero.c libtommath/bn_prime_tab.c libtommath/bn_reverse.c libtommath/bn_s_mp_add.c libtommath/bn_s_mp_exptmod.c libtommath/bn_s_mp_mul_digs.c libtommath/bn_s_mp_mul_high_digs.c libtommath/bn_s_mp_sqr.c libtommath/bn_s_mp_sub.c libtommath/bncore.c libtommath/booker.pl libtommath/callgraph.txt libtommath/changes.txt libtommath/demo/demo.c libtommath/demo/timing.c libtommath/dep.pl libtommath/etc/2kprime.c libtommath/etc/drprime.c libtommath/etc/mersenne.c libtommath/etc/mont.c libtommath/etc/pprime.c libtommath/etc/tune.c libtommath/filter.pl libtommath/gen.pl libtommath/genlist.sh libtommath/makefile.bcc libtommath/makefile.cygwin_dll libtommath/makefile.icc libtommath/makefile.include libtommath/makefile.msvc libtommath/makefile.shared libtommath/mtest/logtab.h libtommath/mtest/mpi-config.h libtommath/mtest/mpi-types.h libtommath/mtest/mpi.c libtommath/mtest/mpi.h libtommath/mtest/mtest.c libtommath/parsenames.pl libtommath/pre_gen/mpi.c libtommath/testme.sh libtommath/tommath.h libtommath/tommath_class.h libtommath/tommath_private.h libtommath/tommath_superclass.h libtommath/updatemakes.sh
diffstat 167 files changed, 18100 insertions(+), 3182 deletions(-) [+]
line wrap: on
line diff
--- a/libtommath/LICENSE	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/LICENSE	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,29 @@
-LibTomMath is hereby released into the Public Domain.  
+LibTomMath is licensed under DUAL licensing terms.
+
+Choose and use the license of your needs.
+
+[LICENSE #1]
+
+LibTomMath is public domain.  As should all quality software be.
+
+Tom St Denis
+
+[/LICENSE #1]
+
+[LICENSE #2]
 
--- Tom St Denis
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+                    Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <[email protected]>
 
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. You just DO WHAT THE FUCK YOU WANT TO. 
+
+[/LICENSE #2]
--- a/libtommath/Makefile.in	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/Makefile.in	Sat Jun 24 22:37:14 2017 +0800
@@ -2,88 +2,61 @@
 #
 #Tom St Denis
 
-#version of library 
-VERSION=0.40
-
[email protected]@
[email protected]@
+srcdir=.
 
 # So that libtommath can include Dropbear headers for options and m_burn()
-CFLAGS += -I. -I$(srcdir) -I../libtomcrypt/src/headers/ -I$(srcdir)/../libtomcrypt/src/headers/ -I../ -I$(srcdir)/../
-
-ifndef IGNORE_SPEED
-
-#for speed 
-#CFLAGS += -O3 -funroll-all-loops
+CFLAGS += -I$(srcdir) -I../libtomcrypt/src/headers/ -I$(srcdir)/../libtomcrypt/src/headers/ -I../ -I$(srcdir)/../
 
-#for size 
-#CFLAGS += -Os
-
-#x86 optimizations [should be valid for any GCC install though]
-#CFLAGS  += -fomit-frame-pointer
-
-#debug
-#CFLAGS += -g3
-
+ifeq ($V,1)
+silent=
+else
[email protected]
 endif
 
-#install as this user
-ifndef INSTALL_GROUP
-   GROUP=wheel
-else
-   GROUP=$(INSTALL_GROUP)
+%.o: %.c
+ifneq ($V,1)
+	@echo "   * ${CC} [email protected]"
 endif
-
-ifndef INSTALL_USER
-   USER=root
-else
-   USER=$(INSTALL_USER)
-endif
+	${silent} ${CC} -c ${CFLAGS} $^ -o [email protected]
 
 #default files to install
 ifndef LIBNAME
    LIBNAME=libtommath.a
 endif
 
-default: ${LIBNAME}
-
-HEADERS=tommath.h tommath_class.h tommath_superclass.h
+coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME)  -Wl,--no-whole-archive
 
-#LIBPATH-The directory for libtommath to be installed to.
-#INCPATH-The directory to install the header files for libtommath.
-#DATAPATH-The directory to install the pdf docs.
-DESTDIR=
-LIBPATH=/usr/lib
-INCPATH=/usr/include
-DATAPATH=/usr/share/doc/libtommath/pdf
+include makefile.include
+
+LCOV_ARGS=--directory .
 
-OBJECTS=bncore.o bn_mp_init.o bn_mp_clear.o bn_mp_exch.o bn_mp_grow.o bn_mp_shrink.o \
-bn_mp_clamp.o bn_mp_zero.o  bn_mp_set.o bn_mp_set_int.o bn_mp_init_size.o bn_mp_copy.o \
-bn_mp_init_copy.o bn_mp_abs.o bn_mp_neg.o bn_mp_cmp_mag.o bn_mp_cmp.o bn_mp_cmp_d.o \
-bn_mp_rshd.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_div_2d.o bn_mp_mul_2d.o bn_mp_div_2.o \
-bn_mp_mul_2.o bn_s_mp_add.o bn_s_mp_sub.o bn_fast_s_mp_mul_digs.o bn_s_mp_mul_digs.o \
-bn_fast_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_s_mp_sqr.o \
-bn_mp_add.o bn_mp_sub.o bn_mp_karatsuba_mul.o bn_mp_mul.o bn_mp_karatsuba_sqr.o \
-bn_mp_sqr.o bn_mp_div.o bn_mp_mod.o bn_mp_add_d.o bn_mp_sub_d.o bn_mp_mul_d.o \
-bn_mp_div_d.o bn_mp_mod_d.o bn_mp_expt_d.o bn_mp_addmod.o bn_mp_submod.o \
-bn_mp_mulmod.o bn_mp_sqrmod.o bn_mp_gcd.o bn_mp_lcm.o bn_fast_mp_invmod.o bn_mp_invmod.o \
-bn_mp_reduce.o bn_mp_montgomery_setup.o bn_fast_mp_montgomery_reduce.o bn_mp_montgomery_reduce.o \
-bn_mp_exptmod_fast.o bn_mp_exptmod.o bn_mp_2expt.o bn_mp_n_root.o bn_mp_jacobi.o bn_reverse.o \
-bn_mp_count_bits.o bn_mp_read_unsigned_bin.o bn_mp_read_signed_bin.o bn_mp_to_unsigned_bin.o \
-bn_mp_to_signed_bin.o bn_mp_unsigned_bin_size.o bn_mp_signed_bin_size.o  \
-bn_mp_xor.o bn_mp_and.o bn_mp_or.o bn_mp_rand.o bn_mp_montgomery_calc_normalization.o \
-bn_mp_prime_is_divisible.o bn_prime_tab.o bn_mp_prime_fermat.o bn_mp_prime_miller_rabin.o \
-bn_mp_prime_is_prime.o bn_mp_prime_next_prime.o bn_mp_dr_reduce.o \
-bn_mp_dr_is_modulus.o bn_mp_dr_setup.o bn_mp_reduce_setup.o \
-bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_div_3.o bn_s_mp_exptmod.o \
-bn_mp_reduce_2k.o bn_mp_reduce_is_2k.o bn_mp_reduce_2k_setup.o \
-bn_mp_reduce_2k_l.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_2k_setup_l.o \
-bn_mp_radix_smap.o bn_mp_read_radix.o bn_mp_toradix.o bn_mp_radix_size.o \
-bn_mp_fread.o bn_mp_fwrite.o bn_mp_cnt_lsb.o bn_error.o \
-bn_mp_init_multi.o bn_mp_clear_multi.o bn_mp_exteuclid.o bn_mp_toradix_n.o \
-bn_mp_prime_random_ex.o bn_mp_get_int.o bn_mp_sqrt.o bn_mp_is_square.o bn_mp_init_set.o \
-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
+#START_INS
+OBJECTS=bncore.o bn_error.o bn_fast_mp_invmod.o bn_fast_mp_montgomery_reduce.o bn_fast_s_mp_mul_digs.o \
+bn_fast_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_mp_2expt.o bn_mp_abs.o bn_mp_add.o bn_mp_add_d.o \
+bn_mp_addmod.o bn_mp_and.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o bn_mp_cmp.o bn_mp_cmp_d.o \
+bn_mp_cmp_mag.o bn_mp_cnt_lsb.o bn_mp_copy.o bn_mp_count_bits.o bn_mp_div_2.o bn_mp_div_2d.o bn_mp_div_3.o \
+bn_mp_div.o bn_mp_div_d.o bn_mp_dr_is_modulus.o bn_mp_dr_reduce.o bn_mp_dr_setup.o bn_mp_exch.o \
+bn_mp_export.o bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_exptmod.o bn_mp_exptmod_fast.o bn_mp_exteuclid.o \
+bn_mp_fread.o bn_mp_fwrite.o bn_mp_gcd.o bn_mp_get_int.o bn_mp_get_long.o bn_mp_get_long_long.o \
+bn_mp_grow.o bn_mp_import.o bn_mp_init.o bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \
+bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_invmod.o bn_mp_invmod_slow.o bn_mp_is_square.o \
+bn_mp_jacobi.o bn_mp_karatsuba_mul.o bn_mp_karatsuba_sqr.o bn_mp_lcm.o bn_mp_lshd.o bn_mp_mod_2d.o \
+bn_mp_mod.o bn_mp_mod_d.o bn_mp_montgomery_calc_normalization.o bn_mp_montgomery_reduce.o \
+bn_mp_montgomery_setup.o bn_mp_mul_2.o bn_mp_mul_2d.o bn_mp_mul.o bn_mp_mul_d.o bn_mp_mulmod.o bn_mp_neg.o \
+bn_mp_n_root.o bn_mp_n_root_ex.o bn_mp_or.o bn_mp_prime_fermat.o bn_mp_prime_is_divisible.o \
+bn_mp_prime_is_prime.o bn_mp_prime_miller_rabin.o bn_mp_prime_next_prime.o \
+bn_mp_prime_rabin_miller_trials.o bn_mp_prime_random_ex.o bn_mp_radix_size.o bn_mp_radix_smap.o \
+bn_mp_rand.o bn_mp_read_radix.o bn_mp_read_signed_bin.o bn_mp_read_unsigned_bin.o bn_mp_reduce_2k.o \
+bn_mp_reduce_2k_l.o bn_mp_reduce_2k_setup.o bn_mp_reduce_2k_setup_l.o bn_mp_reduce.o \
+bn_mp_reduce_is_2k.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_setup.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \
+bn_mp_set_long.o bn_mp_set_long_long.o bn_mp_shrink.o bn_mp_signed_bin_size.o bn_mp_sqr.o bn_mp_sqrmod.o \
+bn_mp_sqrt.o bn_mp_sqrtmod_prime.o bn_mp_sub.o bn_mp_sub_d.o bn_mp_submod.o bn_mp_toom_mul.o \
+bn_mp_toom_sqr.o bn_mp_toradix.o bn_mp_toradix_n.o bn_mp_to_signed_bin.o bn_mp_to_signed_bin_n.o \
+bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o bn_mp_unsigned_bin_size.o bn_mp_xor.o bn_mp_zero.o \
+bn_prime_tab.o bn_reverse.o bn_s_mp_add.o bn_s_mp_exptmod.o bn_s_mp_mul_digs.o bn_s_mp_mul_high_digs.o \
+bn_s_mp_sqr.o bn_s_mp_sub.o
+
+#END_INS
 
 $(LIBNAME):  $(OBJECTS)
 	$(AR) $(ARFLAGS) [email protected] $(OBJECTS)
@@ -93,7 +66,7 @@
 #
 # This will build the library with profile generation
 # then run the test demo and rebuild the library.
-# 
+#
 # So far I've seen improvements in the MP math
 profiled:
 	make CFLAGS="$(CFLAGS) -fprofile-arcs -DTESTING" timing
@@ -101,11 +74,11 @@
 	rm -f *.a *.o ltmtest
 	make CFLAGS="$(CFLAGS) -fbranch-probabilities"
 
-#make a single object profiled library 
+#make a single object profiled library
 profiled_single:
 	perl gen.pl
 	$(CC) $(CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
-	$(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -o ltmtest
+	$(CC) $(CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o ltmtest
 	./ltmtest
 	rm -f *.o ltmtest
 	$(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
@@ -113,23 +86,30 @@
 	$(RANLIB) $(LIBNAME)	
 
 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)
+	install -d $(DESTDIR)$(LIBPATH)
+	install -d $(DESTDIR)$(INCPATH)
+	install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)
+	install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
 
 test: $(LIBNAME) demo/demo.o
-	$(CC) $(CFLAGS) demo/demo.o $(LIBNAME) -o test
-	
-mtest: test	
-	cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest
-        
+	$(CC) $(CFLAGS) demo/demo.o $(LIBNAME) $(LFLAGS) -o test
+
+test_standalone: $(LIBNAME) demo/demo.o
+	$(CC) $(CFLAGS) demo/demo.o $(LIBNAME) $(LFLAGS) -o test
+
+.PHONY: mtest
+mtest:
+	cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest
+
 timing: $(LIBNAME)
-	$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o ltmtest
+	$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o ltmtest
+
+coveralls: coverage
+	cpp-coveralls
 
 # makes the LTM book DVI file, requires tetex, perl and makeindex [part of tetex I think]
 docdvi: tommath.src
-	cd pics ; MAKE=${MAKE} ${MAKE} 
+	cd pics ; MAKE=${MAKE} ${MAKE}
 	echo "hello" > tommath.ind
 	perl booker.pl
 	latex tommath > /dev/null
@@ -139,17 +119,37 @@
 
 # poster, makes the single page PDF poster
 poster: poster.tex
+	cp poster.tex poster.bak
+	touch --reference=poster.tex poster.bak
+	(printf "%s" "\def\fixedpdfdate{"; date +'D:%Y%m%d%H%M%S%:z' -d @$$(stat --format=%Y poster.tex) | sed "s/:\([0-9][0-9]\)$$/'\1'}/g") > poster-deterministic.tex
+	printf "%s\n" "\pdfinfo{" >> poster-deterministic.tex
+	printf "%s\n" "  /CreationDate (\fixedpdfdate)" >> poster-deterministic.tex
+	printf "%s\n}\n" "  /ModDate (\fixedpdfdate)" >> poster-deterministic.tex
+	cat poster.tex >> poster-deterministic.tex
+	mv poster-deterministic.tex poster.tex
+	touch --reference=poster.bak poster.tex
 	pdflatex poster
-	rm -f poster.aux poster.log 
+	sed -b -i 's,^/ID \[.*\]$$,/ID [<0> <0>],g' poster.pdf
+	mv poster.bak poster.tex
+	rm -f poster.aux poster.log poster.out
 
 # makes the LTM book PDF file, requires tetex, cleans up the LaTeX temp files
 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=${MAKE} ${MAKE} clean
-	
+
 #LTM user manual
 mandvi: bn.tex
+	cp bn.tex bn.bak
+	touch --reference=bn.tex bn.bak
+	(printf "%s" "\def\fixedpdfdate{"; date +'D:%Y%m%d%H%M%S%:z' -d @$$(stat --format=%Y bn.tex) | sed "s/:\([0-9][0-9]\)$$/'\1'}/g") > bn-deterministic.tex
+	printf "%s\n" "\pdfinfo{" >> bn-deterministic.tex
+	printf "%s\n" "  /CreationDate (\fixedpdfdate)" >> bn-deterministic.tex
+	printf "%s\n}\n" "  /ModDate (\fixedpdfdate)" >> bn-deterministic.tex
+	cat bn.tex >> bn-deterministic.tex
+	mv bn-deterministic.tex bn.tex
+	touch --reference=bn.bak bn.tex
 	echo "hello" > bn.ind
 	latex bn > /dev/null
 	latex bn > /dev/null
@@ -159,9 +159,11 @@
 #LTM user manual [pdf]
 manual:	mandvi
 	pdflatex bn >/dev/null
+	sed -b -i 's,^/ID \[.*\]$$,/ID [<0> <0>],g' bn.pdf
+	mv bn.bak bn.tex
 	rm -f bn.aux bn.dvi bn.log bn.idx bn.lof bn.out bn.toc
 
-pretty: 
+pretty:
 	perl pretty.build
 
 clean:
@@ -171,16 +173,29 @@
 	-cd etc && MAKE=${MAKE} ${MAKE} clean
 	-cd pics && MAKE=${MAKE} ${MAKE} clean
 
-#zipup the project (take that!)
+#\zipup the project (take that!)
 no_oops: clean
-	cd .. ; cvs commit 
+	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)/* ; \
-	mv -f ltm* ~ ; rm -rf libtommath-$(VERSION)
+.PHONY: pre_gen
+pre_gen:
+	perl gen.pl
+	sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c
+	rm mpi.c
+
+zipup:
+	rm -rf ../libtommath-$(VERSION) \
+		&& rm -f ../ltm-$(VERSION).zip ../ltm-$(VERSION).zip.asc ../ltm-$(VERSION).tar.xz ../ltm-$(VERSION).tar.xz.asc
+	git archive HEAD --prefix=libtommath-$(VERSION)/ > ../libtommath-$(VERSION).tar
+	cd .. ; tar xf libtommath-$(VERSION).tar
+	MAKE=${MAKE} ${MAKE} -C ../libtommath-$(VERSION) clean manual poster docs
+	tar -c ../libtommath-$(VERSION)/* | xz -9 > ../ltm-$(VERSION).tar.xz
+	find ../libtommath-$(VERSION)/ -type f -exec unix2dos -q {} \;
+	cd .. ; zip -9r ltm-$(VERSION).zip libtommath-$(VERSION)
+	gpg -b -a ../ltm-$(VERSION).tar.xz && gpg -b -a ../ltm-$(VERSION).zip
+
+new_file:
+	bash updatemakes.sh
+	perl dep.pl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/README.md	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,13 @@
+[![Build Status](https://travis-ci.org/libtom/libtommath.png?branch=develop)](https://travis-ci.org/libtom/libtommath)
+
+This is the git repository for [LibTomMath](http://www.libtom.org/), a free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C.
+
+The `develop` branch contains the in-development version. Stable releases are tagged.
+
+Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`. There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used.
+
+The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`, there are several other build targets, see the makefile for details. There are also makefiles for certain specific platforms.
+
+Tests are located in `demo/` and can be built in two flavors.
+* `make test` creates a test binary that is intended to be run against `mtest`. `mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./test`. `mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm
+* `make test_standalone` creates a stand-alone test binary that executes several test routines.
--- a/libtommath/bn.tex	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn.tex	Sat Jun 24 22:37:14 2017 +0800
@@ -49,10 +49,10 @@
 \begin{document}
 \frontmatter
 \pagestyle{empty}
-\title{LibTomMath User Manual \\ v0.40}
-\author{Tom St Denis \\ [email protected]}
+\title{LibTomMath User Manual \\ v1.0}
+\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 
+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.
 
 \vspace{10cm}
@@ -74,12 +74,12 @@
 \section{What is LibTomMath?}
 LibTomMath is a library of source code which provides a series of efficient and carefully written functions for manipulating
 large integer numbers.  It was written in portable ISO C source code so that it will build on any platform with a conforming
-C compiler.  
+C compiler.
 
 In a nutshell the library was written from scratch with verbose comments to help instruct computer science students how
-to implement ``bignum'' math.  However, the resulting code has proven to be very useful.  It has been used by numerous 
+to implement ``bignum'' math.  However, the resulting code has proven to be very useful.  It has been used by numerous
 universities, commercial and open source software developers.  It has been used on a variety of platforms ranging from
-Linux and Windows based x86 to ARM based Gameboys and PPC based MacOS machines.  
+Linux and Windows based x86 to ARM based Gameboys and PPC based MacOS machines.
 
 \section{License}
 As of the v0.25 the library source code has been placed in the public domain with every new release.  As of the v0.28
@@ -87,14 +87,14 @@
 release as well.  This textbook is meant to compliment the project by providing a more solid walkthrough of the development
 algorithms used in the library.
 
-Since both\footnote{Note that the MPI files under mtest/ are copyrighted by Michael Fromberger.  They are not required to use LibTomMath.} are in the 
+Since both\footnote{Note that the MPI files under mtest/ are copyrighted by Michael Fromberger.  They are not required to use LibTomMath.} are in the
 public domain everyone is entitled to do with them as they see fit.
 
 \section{Building LibTomMath}
 
 LibTomMath is meant to be very ``GCC friendly'' as it comes with a makefile well suited for GCC.  However, the library will
 also build in MSVC, Borland C out of the box.  For any other ISO C compiler a makefile will have to be made by the end
-developer.  
+developer.
 
 \subsection{Static Libraries}
 To build as a static library for GCC issue the following
@@ -102,14 +102,14 @@
 make
 \end{alltt}
 
-command.  This will build the library and archive the object files in ``libtommath.a''.  Now you link against 
+command.  This will build the library and archive the object files in ``libtommath.a''.  Now you link against
 that and include ``tommath.h'' within your programs.  Alternatively to build with MSVC issue the following
 \begin{alltt}
 nmake -f makefile.msvc
 \end{alltt}
 
-This will build the library and archive the object files in ``tommath.lib''.  This has been tested with MSVC 
-version 6.00 with service pack 5.  
+This will build the library and archive the object files in ``tommath.lib''.  This has been tested with MSVC
+version 6.00 with service pack 5.
 
 \subsection{Shared Libraries}
 To build as a shared library for GCC issue the following
@@ -117,12 +117,12 @@
 make -f makefile.shared
 \end{alltt}
 This requires the ``libtool'' package (common on most Linux/BSD systems).  It will build LibTomMath as both shared
-and static then install (by default) into /usr/lib as well as install the header files in /usr/include.  The shared 
-library (resource) will be called ``libtommath.la'' while the static library called ``libtommath.a''.  Generally 
-you use libtool to link your application against the shared object.  
+and static then install (by default) into /usr/lib as well as install the header files in /usr/include.  The shared
+library (resource) will be called ``libtommath.la'' while the static library called ``libtommath.a''.  Generally
+you use libtool to link your application against the shared object.
 
-There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile.  It requires 
-Cygwin to work with since it requires the auto-export/import functionality.  The resulting DLL and import library 
+There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile.  It requires
+Cygwin to work with since it requires the auto-export/import functionality.  The resulting DLL and import library
 ``libtommath.dll.a'' can be used to link LibTomMath dynamically to any Windows program using Cygwin.
 
 \subsection{Testing}
@@ -140,7 +140,7 @@
 mtest/mtest | test
 \end{alltt}
 
-If you do not have a ``/dev/urandom'' style RNG source you will have to write your own PRNG and simply pipe that into 
+If you do not have a ``/dev/urandom'' style RNG source you will have to write your own PRNG and simply pipe that into
 mtest.  For example, if your PRNG program is called ``myprng'' simply invoke
 
 \begin{alltt}
@@ -152,17 +152,17 @@
 will exit with a dump of the relevent numbers it was working with.
 
 \section{Build Configuration}
-LibTomMath can configured at build time in three phases we shall call ``depends'', ``tweaks'' and ``trims''.  
-Each phase changes how the library is built and they are applied one after another respectively.  
+LibTomMath can configured at build time in three phases we shall call ``depends'', ``tweaks'' and ``trims''.
+Each phase changes how the library is built and they are applied one after another respectively.
 
 To make the system more powerful you can tweak the build process.  Classes are defined in the file
-``tommath\_superclass.h''.  By default, the symbol ``LTM\_ALL'' shall be defined which simply 
-instructs the system to build all of the functions.  This is how LibTomMath used to be packaged.  This will give you 
+``tommath\_superclass.h''.  By default, the symbol ``LTM\_ALL'' shall be defined which simply
+instructs the system to build all of the functions.  This is how LibTomMath used to be packaged.  This will give you
 access to every function LibTomMath offers.
 
-However, there are cases where such a build is not optional.  For instance, you want to perform RSA operations.  You 
-don't need the vast majority of the library to perform these operations.  Aside from LTM\_ALL there is 
-another pre--defined class ``SC\_RSA\_1'' which works in conjunction with the RSA from LibTomCrypt.  Additional 
+However, there are cases where such a build is not optional.  For instance, you want to perform RSA operations.  You
+don't need the vast majority of the library to perform these operations.  Aside from LTM\_ALL there is
+another pre--defined class ``SC\_RSA\_1'' which works in conjunction with the RSA from LibTomCrypt.  Additional
 classes can be defined base on the need of the user.
 
 \subsection{Build Depends}
@@ -172,8 +172,8 @@
 function in the respective file will be compiled and linked into the library.  Accordingly when the define
 is absent the file will not be compiled and not contribute any size to the library.
 
-You will also note that the header tommath\_class.h is actually recursively included (it includes itself twice).  
-This is to help resolve as many dependencies as possible.  In the last pass the symbol LTM\_LAST will be defined.  
+You will also note that the header tommath\_class.h is actually recursively included (it includes itself twice).
+This is to help resolve as many dependencies as possible.  In the last pass the symbol LTM\_LAST will be defined.
 This is useful for ``trims''.
 
 \subsection{Build Tweaks}
@@ -193,7 +193,7 @@
 
 \subsection{Build Trims}
 A trim is a manner of removing functionality from a function that is not required.  For instance, to perform
-RSA cryptography you only require exponentiation with odd moduli so even moduli support can be safely removed.  
+RSA cryptography you only require exponentiation with odd moduli so even moduli support can be safely removed.
 Build trims are meant to be defined on the last pass of the configuration which means they are to be defined
 only if LTM\_LAST has been defined.
 
@@ -232,7 +232,7 @@
                                            & BN\_S\_MP\_SQR\_C \\
 \hline Polynomial Schmolynomial            & BN\_MP\_KARATSUBA\_MUL\_C \\
                                            & BN\_MP\_KARATSUBA\_SQR\_C \\
-                                           & BN\_MP\_TOOM\_MUL\_C \\ 
+                                           & BN\_MP\_TOOM\_MUL\_C \\
                                            & BN\_MP\_TOOM\_SQR\_C \\
 
 \hline
@@ -242,11 +242,11 @@
 
 
 \section{Purpose of LibTomMath}
-Unlike  GNU MP (GMP) Library, LIP, OpenSSL or various other commercial kits (Miracl), LibTomMath was not written with 
-bleeding edge performance in mind.  First and foremost LibTomMath was written to be entirely open.  Not only is the 
+Unlike  GNU MP (GMP) Library, LIP, OpenSSL or various other commercial kits (Miracl), LibTomMath was not written with
+bleeding edge performance in mind.  First and foremost LibTomMath was written to be entirely open.  Not only is the
 source code public domain (unlike various other GPL/etc licensed code), not only is the code freely downloadable but the
 source code is also accessible for computer science students attempting to learn ``BigNum'' or multiple precision
-arithmetic techniques. 
+arithmetic techniques.
 
 LibTomMath was written to be an instructive collection of source code.  This is why there are many comments, only one
 function per source file and often I use a ``middle-road'' approach where I don't cut corners for an extra 2\% speed
@@ -277,9 +277,9 @@
 \caption{LibTomMath Valuation}
 \end{figure}
 
-It may seem odd to compare LibTomMath to GnuPG since the math in GnuPG is only a small portion of the entire application. 
+It may seem odd to compare LibTomMath to GnuPG since the math in GnuPG is only a small portion of the entire application.
 However, LibTomMath was written with cryptography in mind.  It provides essentially all of the functions a cryptosystem
-would require when working with large integers.  
+would require when working with large integers.
 
 So it may feel tempting to just rip the math code out of GnuPG (or GnuMP where it was taken from originally) in your
 own application but I think there are reasons not to.  While LibTomMath is slower than libraries such as GnuMP it is
@@ -289,11 +289,11 @@
 Essentially the only time you wouldn't use LibTomMath is when blazing speed is the primary concern.  However,
 on the other side of the coin LibTomMath offers you a totally free (public domain) well structured math library
 that is very flexible, complete and performs well in resource contrained environments.  Fast RSA for example can
-be performed with as little as 8KB of ram for data (again depending on build options).  
+be performed with as little as 8KB of ram for data (again depending on build options).
 
 \chapter{Getting Started with LibTomMath}
 \section{Building Programs}
-In order to use LibTomMath you must include ``tommath.h'' and link against the appropriate library file (typically 
+In order to use LibTomMath you must include ``tommath.h'' and link against the appropriate library file (typically
 libtommath.a).  There is no library initialization required and the entire library is thread safe.
 
 \section{Return Codes}
@@ -327,8 +327,8 @@
 char *mp_error_to_string(int code);
 \end{alltt}
 
-This will return a pointer to a string which describes the given error code.  It will not work for the return codes 
-MP\_YES and MP\_NO.  
+This will return a pointer to a string which describes the given error code.  It will not work for the return codes
+MP\_YES and MP\_NO.
 
 \section{Data Types}
 The basic ``multiple precision integer'' type is known as the ``mp\_int'' within LibTomMath.  This data type is used to
@@ -345,7 +345,7 @@
 
 Where ``mp\_digit'' is a data type that represents individual digits of the integer.  By default, an mp\_digit is the
 ISO C ``unsigned long'' data type and each digit is $28-$bits long.  The mp\_digit type can be configured to suit other
-platforms by defining the appropriate macros.  
+platforms by defining the appropriate macros.
 
 All LTM functions that use the mp\_int type will expect a pointer to mp\_int structure.  You must allocate memory to
 hold the structure itself by yourself (whether off stack or heap it doesn't matter).  The very first thing that must be
@@ -374,7 +374,7 @@
 
 \section{Initialization}
 \subsection{Single Initialization}
-A single mp\_int can be initialized with the ``mp\_init'' function. 
+A single mp\_int can be initialized with the ``mp\_init'' function.
 
 \index{mp\_init}
 \begin{alltt}
@@ -392,11 +392,11 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the number */
 
    return EXIT_SUCCESS;
@@ -404,7 +404,7 @@
 \end{alltt} \end{small}
 
 \subsection{Single Free}
-When you are finished with an mp\_int it is ideal to return the heap it used back to the system.  The following function 
+When you are finished with an mp\_int it is ideal to return the heap it used back to the system.  The following function
 provides this functionality.
 
 \index{mp\_clear}
@@ -412,9 +412,9 @@
 void mp_clear (mp_int * a);
 \end{alltt}
 
-The function expects a pointer to a previously initialized mp\_int structure and frees the heap it uses.  It sets the 
-pointer\footnote{The ``dp'' member.} within the mp\_int to \textbf{NULL} which is used to prevent double free situations. 
-Is is legal to call mp\_clear() twice on the same mp\_int in a row.  
+The function expects a pointer to a previously initialized mp\_int structure and frees the heap it uses.  It sets the
+pointer\footnote{The ``dp'' member.} within the mp\_int to \textbf{NULL} which is used to prevent double free situations.
+Is is legal to call mp\_clear() twice on the same mp\_int in a row.
 
 \begin{small} \begin{alltt}
 int main(void)
@@ -423,11 +423,11 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the number */
 
    /* We're done with it. */
@@ -451,8 +451,8 @@
 
 It accepts a \textbf{NULL} terminated list of pointers to mp\_int structures.  It will attempt to initialize them all
 at once.  If the function returns MP\_OKAY then all of the mp\_int variables are ready to use, otherwise none of them
-are available for use.  A complementary mp\_clear\_multi() function allows multiple mp\_int variables to be free'd 
-from the heap at the same time.  
+are available for use.  A complementary mp\_clear\_multi() function allows multiple mp\_int variables to be free'd
+from the heap at the same time.
 
 \begin{small} \begin{alltt}
 int main(void)
@@ -460,14 +460,14 @@
    mp_int num1, num2, num3;
    int result;
 
-   if ((result = mp_init_multi(&num1, 
+   if ((result = mp_init_multi(&num1,
                                &num2,
-                               &num3, NULL)) != MP\_OKAY) \{      
-      printf("Error initializing the numbers.  \%s", 
+                               &num3, NULL)) != MP\_OKAY) \{
+      printf("Error initializing the numbers.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the numbers */
 
    /* We're done with them. */
@@ -478,7 +478,7 @@
 \end{alltt} \end{small}
 
 \subsection{Other Initializers}
-To initialized and make a copy of an mp\_int the mp\_init\_copy() function has been provided.  
+To initialized and make a copy of an mp\_int the mp\_init\_copy() function has been provided.
 
 \index{mp\_init\_copy}
 \begin{alltt}
@@ -497,11 +497,11 @@
 
    /* We want a copy of num1 in num2 now */
    if ((result = mp_init_copy(&num2, &num1)) != MP_OKAY) \{
-     printf("Error initializing the copy.  \%s", 
+     printf("Error initializing the copy.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* now num2 is ready and contains a copy of num1 */
 
    /* We're done with them. */
@@ -521,7 +521,7 @@
 \end{alltt}
 
 The $size$ parameter must be greater than zero.  If the function succeeds the mp\_int $a$ will be initialized
-to have $size$ digits (which are all initially zero).  
+to have $size$ digits (which are all initially zero).
 
 \begin{small} \begin{alltt}
 int main(void)
@@ -531,11 +531,11 @@
 
    /* we need a 60-digit number */
    if ((result = mp_init_size(&number, 60)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the number */
 
    return EXIT_SUCCESS;
@@ -556,7 +556,7 @@
 This will remove excess digits of the mp\_int $a$.  If the operation fails the mp\_int should be intact without the
 excess digits being removed.  Note that you can use a shrunk mp\_int in further computations, however, such operations
 will require heap operations which can be slow.  It is not ideal to shrink mp\_int variables that you will further
-modify in the system (unless you are seriously low on memory).  
+modify in the system (unless you are seriously low on memory).
 
 \begin{small} \begin{alltt}
 int main(void)
@@ -565,16 +565,16 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the number [e.g. pre-computation]  */
 
    /* We're done with it for now. */
    if ((result = mp_shrink(&number)) != MP_OKAY) \{
-      printf("Error shrinking the number.  \%s", 
+      printf("Error shrinking the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -582,7 +582,7 @@
    /* use it .... */
 
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -595,7 +595,7 @@
 the integer the mp\_int is meant to equal.   The \textit{used} parameter dictates how many digits are significant, that is,
 contribute to the value of the mp\_int.  The \textit{alloc} parameter dictates how many digits are currently available in
 the array.  If you need to perform an operation that requires more digits you will have to mp\_grow() the mp\_int to
-your desired size.  
+your desired size.
 
 \index{mp\_grow}
 \begin{alltt}
@@ -612,16 +612,16 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* use the number */
 
    /* We need to add 20 digits to the number  */
    if ((result = mp_grow(&number, number.alloc + 20)) != MP_OKAY) \{
-      printf("Error growing the number.  \%s", 
+      printf("Error growing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -629,7 +629,7 @@
 
    /* use the number */
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -641,7 +641,7 @@
 Setting mp\_ints to small constants is a relatively common operation.  To accomodate these instances there are two
 small constant assignment functions.  The first function is used to set a single digit constant while the second sets
 an ISO C style ``unsigned long'' constant.  The reason for both functions is efficiency.  Setting a single digit is quick but the
-domain of a digit can change (it's always at least $0 \ldots 127$).  
+domain of a digit can change (it's always at least $0 \ldots 127$).
 
 \subsection{Single Digit}
 
@@ -663,15 +663,15 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number to 5 */
    mp_set(&number, 5);
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -680,7 +680,7 @@
 
 \subsection{Long Constants}
 
-To set a constant that is the size of an ISO C ``unsigned long'' and larger than a single digit the following function 
+To set a constant that is the size of an ISO C ``unsigned long'' and larger than a single digit the following function
 can be used.
 
 \index{mp\_set\_int}
@@ -689,7 +689,7 @@
 \end{alltt}
 
 This will assign the value of the 32-bit variable $b$ to the mp\_int $a$.  Unlike mp\_set() this function will always
-accept a 32-bit input regardless of the size of a single digit.  However, since the value may span several digits 
+accept a 32-bit input regardless of the size of a single digit.  However, since the value may span several digits
 this function can fail if it runs out of heap memory.
 
 To get the ``unsigned long'' copy of an mp\_int the following function can be used.
@@ -699,7 +699,7 @@
 unsigned long mp_get_int (mp_int * a);
 \end{alltt}
 
-This will return the 32 least significant bits of the mp\_int $a$.  
+This will return the 32 least significant bits of the mp\_int $a$.
 
 \begin{small} \begin{alltt}
 int main(void)
@@ -708,21 +708,21 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number to 654321 (note this is bigger than 127) */
    if ((result = mp_set_int(&number, 654321)) != MP_OKAY) \{
-      printf("Error setting the value of the number.  \%s", 
+      printf("Error setting the value of the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    printf("number == \%lu", mp_get_int(&number));
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -735,6 +735,42 @@
 number == 654321
 \end{alltt}
 
+\subsection{Long Constants - platform dependant}
+
+\index{mp\_set\_long}
+\begin{alltt}
+int mp_set_long (mp_int * a, unsigned long b);
+\end{alltt}
+
+This will assign the value of the platform-dependant sized variable $b$ to the mp\_int $a$.
+
+To get the ``unsigned long'' copy of an mp\_int the following function can be used.
+
+\index{mp\_get\_long}
+\begin{alltt}
+unsigned long mp_get_long (mp_int * a);
+\end{alltt}
+
+This will return the least significant bits of the mp\_int $a$ that fit into an ``unsigned long''.
+
+\subsection{Long Long Constants}
+
+\index{mp\_set\_long\_long}
+\begin{alltt}
+int mp_set_long_long (mp_int * a, unsigned long long b);
+\end{alltt}
+
+This will assign the value of the 64-bit variable $b$ to the mp\_int $a$.
+
+To get the ``unsigned long long'' copy of an mp\_int the following function can be used.
+
+\index{mp\_get\_long\_long}
+\begin{alltt}
+unsigned long long mp_get_long_long (mp_int * a);
+\end{alltt}
+
+This will return the 64 least significant bits of the mp\_int $a$.
+
 \subsection{Initialize and Setting Constants}
 To both initialize and set small constants the following two functions are available.
 \index{mp\_init\_set} \index{mp\_init\_set\_int}
@@ -743,7 +779,7 @@
 int mp_init_set_int (mp_int * a, unsigned long b);
 \end{alltt}
 
-Both functions work like the previous counterparts except they first mp\_init $a$ before setting the values.  
+Both functions work like the previous counterparts except they first mp\_init $a$ before setting the values.
 
 \begin{alltt}
 int main(void)
@@ -753,14 +789,14 @@
 
    /* initialize and set a single digit */
    if ((result = mp_init_set(&number1, 100)) != MP_OKAY) \{
-      printf("Error setting number1: \%s", 
+      printf("Error setting number1: \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
-   \}             
+   \}
 
    /* initialize and set a long */
    if ((result = mp_init_set_int(&number2, 1023)) != MP_OKAY) \{
-      printf("Error setting number2: \%s", 
+      printf("Error setting number2: \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -801,14 +837,14 @@
 \label{fig:CMP}
 \end{figure}
 
-In figure \ref{fig:CMP} two integers $a$ and $b$ are being compared.  In this case $a$ is said to be ``to the left'' of 
-$b$.  
+In figure \ref{fig:CMP} two integers $a$ and $b$ are being compared.  In this case $a$ is said to be ``to the left'' of
+$b$.
 
 \subsection{Unsigned comparison}
 
-An unsigned comparison considers only the digits themselves and not the associated \textit{sign} flag of the 
+An unsigned comparison considers only the digits themselves and not the associated \textit{sign} flag of the
 mp\_int structures.  This is analogous to an absolute comparison.  The function mp\_cmp\_mag() will compare two
-mp\_int variables based on their digits only. 
+mp\_int variables based on their digits only.
 
 \index{mp\_cmp\_mag}
 \begin{alltt}
@@ -824,18 +860,18 @@
    int result;
 
    if ((result = mp_init_multi(&number1, &number2, NULL)) != MP_OKAY) \{
-      printf("Error initializing the numbers.  \%s", 
+      printf("Error initializing the numbers.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number1 to 5 */
    mp_set(&number1, 5);
-  
+
    /* set the number2 to -6 */
    mp_set(&number2, 6);
    if ((result = mp_neg(&number2, &number2)) != MP_OKAY) \{
-      printf("Error negating number2.  \%s", 
+      printf("Error negating number2.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -846,14 +882,14 @@
        case MP_LT:  printf("|number1| < |number2|"); break;
    \}
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear_multi(&number1, &number2, NULL);
 
    return EXIT_SUCCESS;
 \}
 \end{alltt} \end{small}
 
-If this program\footnote{This function uses the mp\_neg() function which is discussed in section \ref{sec:NEG}.} completes 
+If this program\footnote{This function uses the mp\_neg() function which is discussed in section \ref{sec:NEG}.} completes
 successfully it should print the following.
 
 \begin{alltt}
@@ -882,18 +918,18 @@
    int result;
 
    if ((result = mp_init_multi(&number1, &number2, NULL)) != MP_OKAY) \{
-      printf("Error initializing the numbers.  \%s", 
+      printf("Error initializing the numbers.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number1 to 5 */
    mp_set(&number1, 5);
-  
+
    /* set the number2 to -6 */
    mp_set(&number2, 6);
    if ((result = mp_neg(&number2, &number2)) != MP_OKAY) \{
-      printf("Error negating number2.  \%s", 
+      printf("Error negating number2.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -904,14 +940,14 @@
        case MP_LT:  printf("number1 < number2"); break;
    \}
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear_multi(&number1, &number2, NULL);
 
    return EXIT_SUCCESS;
 \}
 \end{alltt} \end{small}
 
-If this program\footnote{This function uses the mp\_neg() function which is discussed in section \ref{sec:NEG}.} completes 
+If this program\footnote{This function uses the mp\_neg() function which is discussed in section \ref{sec:NEG}.} completes
 successfully it should print the following.
 
 \begin{alltt}
@@ -927,7 +963,7 @@
 int mp_cmp_d(mp_int * a, mp_digit b);
 \end{alltt}
 
-This will compare $a$ to the left of $b$ using a signed comparison.  Note that it will always treat $b$ as 
+This will compare $a$ to the left of $b$ using a signed comparison.  Note that it will always treat $b$ as
 positive.  This function is rather handy when you have to compare against small values such as $1$ (which often
 comes up in cryptography).  The function cannot fail and will return one of the tree compare condition codes
 listed in figure \ref{fig:CMP}.
@@ -940,11 +976,11 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number to 5 */
    mp_set(&number, 5);
 
@@ -954,7 +990,7 @@
        case MP_LT:  printf("number < 7"); break;
    \}
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -975,7 +1011,7 @@
 \subsection{Multiplication by two}
 
 Multiplications and divisions by any power of two can be performed with quick logical shifts either left or
-right depending on the operation.  
+right depending on the operation.
 
 When multiplying or dividing by two a special case routine can be used which are as follows.
 \index{mp\_mul\_2} \index{mp\_div\_2}
@@ -994,17 +1030,17 @@
    int result;
 
    if ((result = mp_init(&number)) != MP_OKAY) \{
-      printf("Error initializing the number.  \%s", 
+      printf("Error initializing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    /* set the number to 5 */
    mp_set(&number, 5);
 
    /* multiply by two */
    if ((result = mp\_mul\_2(&number, &number)) != MP_OKAY) \{
-      printf("Error multiplying the number.  \%s", 
+      printf("Error multiplying the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -1016,7 +1052,7 @@
 
    /* now divide by two */
    if ((result = mp\_div\_2(&number, &number)) != MP_OKAY) \{
-      printf("Error dividing the number.  \%s", 
+      printf("Error dividing the number.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -1026,7 +1062,7 @@
        case MP_LT:  printf("2*number/2 < 7"); break;
    \}
 
-   /* we're done with it. */ 
+   /* we're done with it. */
    mp_clear(&number);
 
    return EXIT_SUCCESS;
@@ -1040,15 +1076,18 @@
 2*number/2 < 7
 \end{alltt}
 
-Since $10 > 7$ and $5 < 7$.  To multiply by a power of two the following function can be used.
+Since $10 > 7$ and $5 < 7$.
+
+To multiply by a power of two the following function can be used.
 
 \index{mp\_mul\_2d}
 \begin{alltt}
 int mp_mul_2d(mp_int * a, int b, mp_int * c);
 \end{alltt}
 
-This will multiply $a$ by $2^b$ and store the result in ``c''.  If the value of $b$ is less than or equal to 
-zero the function will copy $a$ to ``c'' without performing any further actions.  
+This will multiply $a$ by $2^b$ and store the result in ``c''.  If the value of $b$ is less than or equal to
+zero the function will copy $a$ to ``c'' without performing any further actions.  The multiplication itself
+is implemented as a right-shift operation of $a$ by $b$ bits.
 
 To divide by a power of two use the following.
 
@@ -1058,14 +1097,15 @@
 \end{alltt}
 Which will divide $a$ by $2^b$, store the quotient in ``c'' and the remainder in ``d'.  If $b \le 0$ then the
 function simply copies $a$ over to ``c'' and zeroes $d$.  The variable $d$ may be passed as a \textbf{NULL}
-value to signal that the remainder is not desired.
+value to signal that the remainder is not desired.  The division itself is implemented as a left-shift
+operation of $a$ by $b$ bits.
 
 \subsection{Polynomial Basis Operations}
 
-Strictly speaking the organization of the integers within the mp\_int structures is what is known as a 
+Strictly speaking the organization of the integers within the mp\_int structures is what is known as a
 ``polynomial basis''.  This simply means a field element is stored by divisions of a radix.  For example, if
-$f(x) = \sum_{i=0}^{k} y_ix^k$ for any vector $\vec y$ then the array of digits in $\vec y$ are said to be 
-the polynomial basis representation of $z$ if $f(\beta) = z$ for a given radix $\beta$.  
+$f(x) = \sum_{i=0}^{k} y_ix^k$ for any vector $\vec y$ then the array of digits in $\vec y$ are said to be
+the polynomial basis representation of $z$ if $f(\beta) = z$ for a given radix $\beta$.
 
 To multiply by the polynomial $g(x) = x$ all you have todo is shift the digits of the basis left one place.  The
 following function provides this operation.
@@ -1097,7 +1137,7 @@
 int mp_xor (mp_int * a, mp_int * b, mp_int * c);
 \end{alltt}
 
-Which compute $c = a \odot b$ where $\odot$ is one of OR, AND or XOR.  
+Which compute $c = a \odot b$ where $\odot$ is one of OR, AND or XOR.
 
 \section{Addition and Subtraction}
 
@@ -1122,7 +1162,7 @@
 int mp_neg (mp_int * a, mp_int * b);
 \end{alltt}
 
-Which assigns $-a$ to $b$.  
+Which assigns $-a$ to $b$.
 
 \subsection{Absolute}
 Simple integer absolutes can be performed with the following.
@@ -1132,7 +1172,7 @@
 int mp_abs (mp_int * a, mp_int * b);
 \end{alltt}
 
-Which assigns $\vert a \vert$ to $b$.  
+Which assigns $\vert a \vert$ to $b$.
 
 \section{Integer Division and Remainder}
 To perform a complete and general integer division with remainder use the following function.
@@ -1141,10 +1181,10 @@
 \begin{alltt}
 int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
 \end{alltt}
-                                                        
-This divides $a$ by $b$ and stores the quotient in $c$ and $d$.  The signed quotient is computed such that 
-$bc + d = a$.  Note that either of $c$ or $d$ can be set to \textbf{NULL} if their value is not required.  If 
-$b$ is zero the function returns \textbf{MP\_VAL}.  
+
+This divides $a$ by $b$ and stores the quotient in $c$ and $d$.  The signed quotient is computed such that
+$bc + d = a$.  Note that either of $c$ or $d$ can be set to \textbf{NULL} if their value is not required.  If
+$b$ is zero the function returns \textbf{MP\_VAL}.
 
 
 \chapter{Multiplication and Squaring}
@@ -1154,7 +1194,7 @@
 \begin{alltt}
 int mp_mul (mp_int * a, mp_int * b, mp_int * c);
 \end{alltt}
-Which assigns the full signed product $ab$ to $c$.  This function actually breaks into one of four cases which are 
+Which assigns the full signed product $ab$ to $c$.  This function actually breaks into one of four cases which are
 specific multiplication routines optimized for given parameters.  First there are the Toom-Cook multiplications which
 should only be used with very large inputs.  This is followed by the Karatsuba multiplications which are for moderate
 sized inputs.  Then followed by the Comba and baseline multipliers.
@@ -1169,22 +1209,22 @@
    int result;
 
    /* Initialize the numbers */
-   if ((result = mp_init_multi(&number1, 
+   if ((result = mp_init_multi(&number1,
                                &number2, NULL)) != MP_OKAY) \{
-      printf("Error initializing the numbers.  \%s", 
+      printf("Error initializing the numbers.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* set the terms */
    if ((result = mp_set_int(&number, 257)) != MP_OKAY) \{
-      printf("Error setting number1.  \%s", 
+      printf("Error setting number1.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
- 
+
    if ((result = mp_set_int(&number2, 1023)) != MP_OKAY) \{
-      printf("Error setting number2.  \%s", 
+      printf("Error setting number2.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -1192,7 +1232,7 @@
    /* multiply them */
    if ((result = mp_mul(&number1, &number2,
                         &number1)) != MP_OKAY) \{
-      printf("Error multiplying terms.  \%s", 
+      printf("Error multiplying terms.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -1205,7 +1245,7 @@
 
    return EXIT_SUCCESS;
 \}
-\end{alltt}   
+\end{alltt}
 
 If this program succeeds it shall output the following.
 
@@ -1224,22 +1264,22 @@
 
 Will square $a$ and store it in $b$.  Like the case of multiplication there are four different squaring
 algorithms all which can be called from mp\_sqr().  It is ideal to use mp\_sqr over mp\_mul when squaring terms because
-of the speed difference.  
+of the speed difference.
 
 \section{Tuning Polynomial Basis Routines}
 
 Both of the Toom-Cook and Karatsuba multiplication algorithms are faster than the traditional $O(n^2)$ approach that
-the Comba and baseline algorithms use.  At $O(n^{1.464973})$ and $O(n^{1.584962})$ running times respectively they require 
+the Comba and baseline algorithms use.  At $O(n^{1.464973})$ and $O(n^{1.584962})$ running times respectively they require
 considerably less work.  For example, a 10000-digit multiplication would take roughly 724,000 single precision
 multiplications with Toom-Cook or 100,000,000 single precision multiplications with the standard Comba (a factor
 of 138).
 
 So why not always use Karatsuba or Toom-Cook?   The simple answer is that they have so much overhead that they're not
-actually faster than Comba until you hit distinct  ``cutoff'' points.  For Karatsuba with the default configuration, 
-GCC 3.3.1 and an Athlon XP processor the cutoff point is roughly 110 digits (about 70 for the Intel P4).  That is, at 
+actually faster than Comba until you hit distinct  ``cutoff'' points.  For Karatsuba with the default configuration,
+GCC 3.3.1 and an Athlon XP processor the cutoff point is roughly 110 digits (about 70 for the Intel P4).  That is, at
 110 digits Karatsuba and Comba multiplications just about break even and for 110+ digits Karatsuba is faster.
 
-Toom-Cook has incredible overhead and is probably only useful for very large inputs.  So far no known cutoff points 
+Toom-Cook has incredible overhead and is probably only useful for very large inputs.  So far no known cutoff points
 exist and for the most part I just set the cutoff points very high to make sure they're not called.
 
 A demo program in the ``etc/'' directory of the project called ``tune.c'' can be used to find the cutoff points.  This
@@ -1273,19 +1313,19 @@
 
 \chapter{Modular Reduction}
 
-Modular reduction is process of taking the remainder of one quantity divided by another.  Expressed 
-as (\ref{eqn:mod}) the modular reduction is equivalent to the remainder of $b$ divided by $c$.  
+Modular reduction is process of taking the remainder of one quantity divided by another.  Expressed
+as (\ref{eqn:mod}) the modular reduction is equivalent to the remainder of $b$ divided by $c$.
 
 \begin{equation}
 a \equiv b \mbox{ (mod }c\mbox{)}
 \label{eqn:mod}
 \end{equation}
 
-Of particular interest to cryptography are reductions where $b$ is limited to the range $0 \le b < c^2$ since particularly 
-fast reduction algorithms can be written for the limited range.  
+Of particular interest to cryptography are reductions where $b$ is limited to the range $0 \le b < c^2$ since particularly
+fast reduction algorithms can be written for the limited range.
 
 Note that one of the four optimized reduction algorithms are automatically chosen in the modular exponentiation
-algorithm mp\_exptmod when an appropriate modulus is detected.  
+algorithm mp\_exptmod when an appropriate modulus is detected.
 
 \section{Straight Division}
 In order to effect an arbitrary modular reduction the following algorithm is provided.
@@ -1295,7 +1335,7 @@
 int mp_mod(mp_int *a, mp_int *b, mp_int *c);
 \end{alltt}
 
-This reduces $a$ modulo $b$ and stores the result in $c$.  The sign of $c$ shall agree with the sign 
+This reduces $a$ modulo $b$ and stores the result in $c$.  The sign of $c$ shall agree with the sign
 of $b$.  This algorithm accepts an input $a$ of any range and is not limited by $0 \le a < b^2$.
 
 \section{Barrett Reduction}
@@ -1325,52 +1365,52 @@
    mp_int   a, b, c, mu;
    int      result;
 
-   /* initialize a,b to desired values, mp_init mu, 
-    * c and set c to 1...we want to compute a^3 mod b 
+   /* initialize a,b to desired values, mp_init mu,
+    * c and set c to 1...we want to compute a^3 mod b
     */
 
    /* get mu value */
    if ((result = mp_reduce_setup(&mu, b)) != MP_OKAY) \{
-      printf("Error getting mu.  \%s", 
+      printf("Error getting mu.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* square a to get c = a^2 */
    if ((result = mp_sqr(&a, &c)) != MP_OKAY) \{
-      printf("Error squaring.  \%s", 
+      printf("Error squaring.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* now reduce `c' modulo b */
    if ((result = mp_reduce(&c, &b, &mu)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
-   
+
    /* multiply a to get c = a^3 */
    if ((result = mp_mul(&a, &c, &c)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* now reduce `c' modulo b  */
    if ((result = mp_reduce(&c, &b, &mu)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
-  
+
    /* c now equals a^3 mod b */
 
    return EXIT_SUCCESS;
 \}
-\end{alltt} 
+\end{alltt}
 
-This program will calculate $a^3 \mbox{ mod }b$ if all the functions succeed.  
+This program will calculate $a^3 \mbox{ mod }b$ if all the functions succeed.
 
 \section{Montgomery Reduction}
 
@@ -1382,7 +1422,7 @@
 int mp_montgomery_setup(mp_int *a, mp_digit *mp);
 \end{alltt}
 
-For the given odd moduli $a$ the precomputation value is placed in $mp$.  The reduction is computed with the 
+For the given odd moduli $a$ the precomputation value is placed in $mp$.  The reduction is computed with the
 following.
 
 \index{mp\_montgomery\_reduce}
@@ -1394,10 +1434,10 @@
 
 Montgomery reduction is faster than Barrett reduction for moduli smaller than the ``comba'' limit.  With the default
 setup for instance, the limit is $127$ digits ($3556$--bits).   Note that this function is not limited to
-$127$ digits just that it falls back to a baseline algorithm after that point.  
+$127$ digits just that it falls back to a baseline algorithm after that point.
 
-An important observation is that this reduction does not return $a \mbox{ mod }m$ but $aR^{-1} \mbox{ mod }m$ 
-where $R = \beta^n$, $n$ is the n number of digits in $m$ and $\beta$ is radix used (default is $2^{28}$).  
+An important observation is that this reduction does not return $a \mbox{ mod }m$ but $aR^{-1} \mbox{ mod }m$
+where $R = \beta^n$, $n$ is the n number of digits in $m$ and $\beta$ is radix used (default is $2^{28}$).
 
 To quickly calculate $R$ the following function was provided.
 
@@ -1405,7 +1445,7 @@
 \begin{alltt}
 int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
 \end{alltt}
-Which calculates $a = R$ for the odd moduli $b$ without using multiplication or division.  
+Which calculates $a = R$ for the odd moduli $b$ without using multiplication or division.
 
 The normal modus operandi for Montgomery reductions is to normalize the integers before entering the system.  For
 example, to calculate $a^3 \mbox { mod }b$ using Montgomery reduction the value of $a$ can be normalized by
@@ -1418,62 +1458,62 @@
    mp_digit mp;
    int      result;
 
-   /* initialize a,b to desired values, 
-    * mp_init R, c and set c to 1.... 
+   /* initialize a,b to desired values,
+    * mp_init R, c and set c to 1....
     */
 
    /* get normalization */
    if ((result = mp_montgomery_calc_normalization(&R, b)) != MP_OKAY) \{
-      printf("Error getting norm.  \%s", 
+      printf("Error getting norm.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* get mp value */
    if ((result = mp_montgomery_setup(&c, &mp)) != MP_OKAY) \{
-      printf("Error setting up montgomery.  \%s", 
+      printf("Error setting up montgomery.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* normalize `a' so now a is equal to aR */
    if ((result = mp_mulmod(&a, &R, &b, &a)) != MP_OKAY) \{
-      printf("Error computing aR.  \%s", 
+      printf("Error computing aR.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* square a to get c = a^2R^2 */
    if ((result = mp_sqr(&a, &c)) != MP_OKAY) \{
-      printf("Error squaring.  \%s", 
+      printf("Error squaring.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* now reduce `c' back down to c = a^2R^2 * R^-1 == a^2R */
    if ((result = mp_montgomery_reduce(&c, &b, mp)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
-   
+
    /* multiply a to get c = a^3R^2 */
    if ((result = mp_mul(&a, &c, &c)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
 
    /* now reduce `c' back down to c = a^3R^2 * R^-1 == a^3R */
    if ((result = mp_montgomery_reduce(&c, &b, mp)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
-   
+
    /* now reduce (again) `c' back down to c = a^3R * R^-1 == a^3 */
    if ((result = mp_montgomery_reduce(&c, &b, mp)) != MP_OKAY) \{
-      printf("Error reducing.  \%s", 
+      printf("Error reducing.  \%s",
              mp_error_to_string(result));
       return EXIT_FAILURE;
    \}
@@ -1482,9 +1522,9 @@
 
    return EXIT_SUCCESS;
 \}
-\end{alltt} 
+\end{alltt}
 
-This particular example does not look too efficient but it demonstrates the point of the algorithm.  By 
+This particular example does not look too efficient but it demonstrates the point of the algorithm.  By
 normalizing the inputs the reduced results are always of the form $aR$ for some variable $a$.  This allows
 a single final reduction to correct for the normalization and the fast reduction used within the algorithm.
 
@@ -1494,7 +1534,7 @@
 
 ``Dimminished Radix'' reduction refers to reduction with respect to moduli that are ameniable to simple
 digit shifting and small multiplications.  In this case the ``restricted'' variant refers to moduli of the
-form $\beta^k - p$ for some $k \ge 0$ and $0 < p < \beta$ where $\beta$ is the radix (default to $2^{28}$).  
+form $\beta^k - p$ for some $k \ge 0$ and $0 < p < \beta$ where $\beta$ is the radix (default to $2^{28}$).
 
 As in the case of Montgomery reduction there is a pre--computation phase required for a given modulus.
 
@@ -1513,45 +1553,62 @@
 \end{alltt}
 
 This reduces $a$ in place modulo $b$ with the pre--computed value $mp$.  $b$ must be of a restricted
-dimminished radix form and $a$ must be in the range $0 \le a < b^2$.  Dimminished radix reductions are 
-much faster than both Barrett and Montgomery reductions as they have a much lower asymtotic running time.  
+dimminished radix form and $a$ must be in the range $0 \le a < b^2$.  Dimminished radix reductions are
+much faster than both Barrett and Montgomery reductions as they have a much lower asymtotic running time.
 
 Since the moduli are restricted this algorithm is not particularly useful for something like Rabin, RSA or
 BBS cryptographic purposes.  This reduction algorithm is useful for Diffie-Hellman and ECC where fixed
-primes are acceptable.  
+primes are acceptable.
 
 Note that unlike Montgomery reduction there is no normalization process.  The result of this function is
 equal to the correct residue.
 
 \section{Unrestricted Dimminshed Radix}
 
-Unrestricted reductions work much like the restricted counterparts except in this case the moduli is of the 
-form $2^k - p$ for $0 < p < \beta$.  In this sense the unrestricted reductions are more flexible as they 
-can be applied to a wider range of numbers.  
+Unrestricted reductions work much like the restricted counterparts except in this case the moduli is of the
+form $2^k - p$ for $0 < p < \beta$.  In this sense the unrestricted reductions are more flexible as they
+can be applied to a wider range of numbers.
 
 \index{mp\_reduce\_2k\_setup}
 \begin{alltt}
 int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
 \end{alltt}
 
-This will compute the required $d$ value for the given moduli $a$.  
+This will compute the required $d$ value for the given moduli $a$.
 
 \index{mp\_reduce\_2k}
 \begin{alltt}
 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
 \end{alltt}
 
-This will reduce $a$ in place modulo $n$ with the pre--computed value $d$.  From my experience this routine is 
-slower than mp\_dr\_reduce but faster for most moduli sizes than the Montgomery reduction.  
+This will reduce $a$ in place modulo $n$ with the pre--computed value $d$.  From my experience this routine is
+slower than mp\_dr\_reduce but faster for most moduli sizes than the Montgomery reduction.
 
 \chapter{Exponentiation}
 \section{Single Digit Exponentiation}
+\index{mp\_expt\_d\_ex}
+\begin{alltt}
+int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
+\end{alltt}
+This function computes $c = a^b$.
+
+With parameter \textit{fast} set to $0$ the old version of the algorithm is used,
+when \textit{fast} is $1$, a faster but not statically timed version of the algorithm is used.
+
+The old version uses a simple binary left-to-right algorithm.
+It is faster than repeated multiplications by $a$ for all values of $b$ greater than three.
+
+The new version uses a binary right-to-left algorithm.
+
+The difference between the old and the new version is that the old version always
+executes $DIGIT\_BIT$ iterations. The new algorithm executes only $n$ iterations
+where $n$ is equal to the position of the highest bit that is set in $b$.
+
 \index{mp\_expt\_d}
 \begin{alltt}
 int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
 \end{alltt}
-This computes $c = a^b$ using a simple binary left-to-right algorithm.  It is faster than repeated multiplications by 
-$a$ for all values of $b$ greater than three.  
+mp\_expt\_d(a, b, c) is a wrapper function to mp\_expt\_d\_ex(a, b, c, 0).
 
 \section{Modular Exponentiation}
 \index{mp\_exptmod}
@@ -1559,8 +1616,8 @@
 int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
 \end{alltt}
 This computes $Y \equiv G^X \mbox{ (mod }P\mbox{)}$ using a variable width sliding window algorithm.  This function
-will automatically detect the fastest modular reduction technique to use during the operation.  For negative values of 
-$X$ the operation is performed as $Y \equiv (G^{-1} \mbox{ mod }P)^{\vert X \vert} \mbox{ (mod }P\mbox{)}$ provided that 
+will automatically detect the fastest modular reduction technique to use during the operation.  For negative values of
+$X$ the operation is performed as $Y \equiv (G^{-1} \mbox{ mod }P)^{\vert X \vert} \mbox{ (mod }P\mbox{)}$ provided that
 $gcd(G, P) = 1$.
 
 This function is actually a shell around the two internal exponentiation functions.  This routine will automatically
@@ -1573,16 +1630,16 @@
 \begin{alltt}
 int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
 \end{alltt}
-This computes $c = a^{1/b}$ such that $c^b \le a$ and $(c+1)^b > a$.  The implementation of this function is not 
+This computes $c = a^{1/b}$ such that $c^b \le a$ and $(c+1)^b > a$.  The implementation of this function is not
 ideal for values of $b$ greater than three.  It will work but become very slow.  So unless you are working with very small
 numbers (less than 1000 bits) I'd avoid $b > 3$ situations.  Will return a positive root only for even roots and return
-a root with the sign of the input for odd roots.  For example, performing $4^{1/2}$ will return $2$ whereas $(-8)^{1/3}$ 
-will return $-2$.  
+a root with the sign of the input for odd roots.  For example, performing $4^{1/2}$ will return $2$ whereas $(-8)^{1/3}$
+will return $-2$.
 
 This algorithm uses the ``Newton Approximation'' method and will converge on the correct root fairly quickly.  Since
 the algorithm requires raising $a$ to the power of $b$ it is not ideal to attempt to find roots for large
 values of $b$.  If particularly large roots are required then a factor method could be used instead.  For example,
-$a^{1/16}$ is equivalent to $\left (a^{1/4} \right)^{1/4}$ or simply 
+$a^{1/16}$ is equivalent to $\left (a^{1/4} \right)^{1/4}$ or simply
 $\left ( \left ( \left ( a^{1/2} \right )^{1/2} \right )^{1/2} \right )^{1/2}$
 
 \chapter{Prime Numbers}
@@ -1591,8 +1648,8 @@
 \begin{alltt}
 int mp_prime_is_divisible (mp_int * a, int *result)
 \end{alltt}
-This will attempt to evenly divide $a$ by a list of primes\footnote{Default is the first 256 primes.} and store the 
-outcome in ``result''.  That is if $result = 0$ then $a$ is not divisible by the primes, otherwise it is.  Note that 
+This will attempt to evenly divide $a$ by a list of primes\footnote{Default is the first 256 primes.} and store the
+outcome in ``result''.  That is if $result = 0$ then $a$ is not divisible by the primes, otherwise it is.  Note that
 if the function does not return \textbf{MP\_OKAY} the value in ``result'' should be considered undefined\footnote{Currently
 the default is to set it to zero first.}.
 
@@ -1611,10 +1668,10 @@
 int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
 \end{alltt}
 Performs a Miller-Rabin test to the base $b$ of $a$.  This test is much stronger than the Fermat test and is very hard to
-fool (besides with Carmichael numbers).  If $a$ passes the test (therefore is probably prime) $result$ is set to one.  
-Otherwise $result$ is set to zero.  
+fool (besides with Carmichael numbers).  If $a$ passes the test (therefore is probably prime) $result$ is set to one.
+Otherwise $result$ is set to zero.
 
-Note that is suggested that you use the Miller-Rabin test instead of the Fermat test since all of the failures of 
+Note that is suggested that you use the Miller-Rabin test instead of the Fermat test since all of the failures of
 Miller-Rabin are a subset of the failures of the Fermat test.
 
 \subsection{Required Number of Tests}
@@ -1628,7 +1685,7 @@
 \end{alltt}
 This returns the number of trials required for a $2^{-96}$ (or lower) probability of failure for a given ``size'' expressed
 in bits.  This comes in handy specially since larger numbers are slower to test.  For example, a 512-bit number would
-require ten tests whereas a 1024-bit number would only require four tests. 
+require ten tests whereas a 1024-bit number would only require four tests.
 
 You should always still perform a trial division before a Miller-Rabin test though.
 
@@ -1637,8 +1694,8 @@
 \begin{alltt}
 int mp_prime_is_prime (mp_int * a, int t, int *result)
 \end{alltt}
-This will perform a trial division followed by $t$ rounds of Miller-Rabin tests on $a$ and store the result in $result$.  
-If $a$ passes all of the tests $result$ is set to one, otherwise it is set to zero.  Note that $t$ is bounded by 
+This will perform a trial division followed by $t$ rounds of Miller-Rabin tests on $a$ and store the result in $result$.
+If $a$ passes all of the tests $result$ is set to one, otherwise it is set to zero.  Note that $t$ is bounded by
 $1 \le t < PRIME\_SIZE$ where $PRIME\_SIZE$ is the number of primes in the prime number table (by default this is $256$).
 
 \section{Next Prime}
@@ -1646,25 +1703,25 @@
 \begin{alltt}
 int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
 \end{alltt}
-This finds the next prime after $a$ that passes mp\_prime\_is\_prime() with $t$ tests.  Set $bbs\_style$ to one if you 
-want only the next prime congruent to $3 \mbox{ mod } 4$, otherwise set it to zero to find any next prime.  
+This finds the next prime after $a$ that passes mp\_prime\_is\_prime() with $t$ tests.  Set $bbs\_style$ to one if you
+want only the next prime congruent to $3 \mbox{ mod } 4$, otherwise set it to zero to find any next prime.
 
 \section{Random Primes}
 \index{mp\_prime\_random}
 \begin{alltt}
-int mp_prime_random(mp_int *a, int t, int size, int bbs, 
+int mp_prime_random(mp_int *a, int t, int size, int bbs,
                     ltm_prime_callback cb, void *dat)
 \end{alltt}
 This will find a prime greater than $256^{size}$ which can be ``bbs\_style'' or not depending on $bbs$ and must pass
-$t$ rounds of tests.  The ``ltm\_prime\_callback'' is a typedef for 
+$t$ rounds of tests.  The ``ltm\_prime\_callback'' is a typedef for
 
 \begin{alltt}
 typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
 \end{alltt}
 
 Which is a function that must read $len$ bytes (and return the amount stored) into $dst$.  The $dat$ variable is simply
-copied from the original input.  It can be used to pass RNG context data to the callback.  The function 
-mp\_prime\_random() is more suitable for generating primes which must be secret (as in the case of RSA) since there 
+copied from the original input.  It can be used to pass RNG context data to the callback.  The function
+mp\_prime\_random() is more suitable for generating primes which must be secret (as in the case of RSA) since there
 is no skew on the least significant bits.
 
 \textit{Note:}  As of v0.30 of the LibTomMath library this function has been deprecated.  It is still available
@@ -1673,13 +1730,13 @@
 \subsection{Extended Generation}
 \index{mp\_prime\_random\_ex}
 \begin{alltt}
-int mp_prime_random_ex(mp_int *a,    int t, 
-                       int     size, int flags, 
+int mp_prime_random_ex(mp_int *a,    int t,
+                       int     size, int flags,
                        ltm_prime_callback cb, void *dat);
 \end{alltt}
 This will generate a prime in $a$ using $t$ tests of the primality testing algorithms.  The variable $size$
 specifies the bit length of the prime desired.  The variable $flags$ specifies one of several options available
-(see fig. \ref{fig:primeopts}) which can be OR'ed together.  The callback parameters are used as in 
+(see fig. \ref{fig:primeopts}) which can be OR'ed together.  The callback parameters are used as in
 mp\_prime\_random().
 
 \begin{figure}[here]
@@ -1717,8 +1774,8 @@
 \begin{alltt}
 int mp_radix_size (mp_int * a, int radix, int *size)
 \end{alltt}
-This stores in ``size'' the number of characters (including space for the NUL terminator) required.  Upon error this 
-function returns an error code and ``size'' will be zero.  
+This stores in ``size'' the number of characters (including space for the NUL terminator) required.  Upon error this
+function returns an error code and ``size'' will be zero.
 
 \subsection{From ASCII}
 \index{mp\_read\_radix}
@@ -1764,13 +1821,13 @@
 \end{alltt}
 They operate essentially the same as the unsigned copies except they prefix the data with zero or non--zero
 byte depending on the sign.  If the sign is zpos (e.g. not negative) the prefix is zero, otherwise the prefix
-is non--zero.  
+is non--zero.
 
 \chapter{Algebraic Functions}
 \section{Extended Euclidean Algorithm}
 \index{mp\_exteuclid}
 \begin{alltt}
-int mp_exteuclid(mp_int *a, mp_int *b, 
+int mp_exteuclid(mp_int *a, mp_int *b,
                  mp_int *U1, mp_int *U2, mp_int *U3);
 \end{alltt}
 
@@ -1780,7 +1837,7 @@
 a \cdot U1 + b \cdot U2 = U3
 \end{equation}
 
-Any of the U1/U2/U3 paramters can be set to \textbf{NULL} if they are not desired.  
+Any of the U1/U2/U3 paramters can be set to \textbf{NULL} if they are not desired.
 
 \section{Greatest Common Divisor}
 \index{mp\_gcd}
@@ -1804,7 +1861,28 @@
 This will compute the Jacobi symbol for $a$ with respect to $p$.  If $p$ is prime this essentially computes the Legendre
 symbol.  The result is stored in $c$ and can take on one of three values $\lbrace -1, 0, 1 \rbrace$.  If $p$ is prime
 then the result will be $-1$ when $a$ is not a quadratic residue modulo $p$.  The result will be $0$ if $a$ divides $p$
-and the result will be $1$ if $a$ is a quadratic residue modulo $p$.  
+and the result will be $1$ if $a$ is a quadratic residue modulo $p$.
+
+\section{Modular square root}
+\index{mp\_sqrtmod\_prime}
+\begin{alltt}
+int mp_sqrtmod_prime(mp_int *n, mp_int *p, mp_int *r)
+\end{alltt}
+
+This will solve the modular equatioon $r^2 = n \mod p$ where $p$ is a prime number greater than 2 (odd prime).
+The result is returned in the third argument $r$, the function returns \textbf{MP\_OKAY} on success,
+other return values indicate failure.
+
+The implementation is split for two different cases:
+
+1. if $p \mod 4 == 3$ we apply \href{http://cacr.uwaterloo.ca/hac/}{Handbook of Applied Cryptography algorithm 3.36} and compute $r$ directly as
+$r = n^{(p+1)/4} \mod p$
+
+2. otherwise we use \href{https://en.wikipedia.org/wiki/Tonelli-Shanks_algorithm}{Tonelli-Shanks algorithm}
+
+The function does not check the primality of parameter $p$ thus it is up to the caller to assure that this parameter
+is a prime number. When $p$ is a composite the function behaviour is undefined, it may even return a false-positive
+\textbf{MP\_OKAY}.
 
 \section{Modular Inverse}
 \index{mp\_invmod}
--- a/libtommath/bn_error.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_error.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_ERROR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,12 +12,12 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 static const struct {
      int code;
-     char *msg;
+     const char *msg;
 } msgs[] = {
      { MP_OKAY, "Successful" },
      { MP_MEM,  "Out of heap" },
@@ -25,7 +25,7 @@
 };
 
 /* return a char * string for a given code */
-char *mp_error_to_string(int code)
+const char *mp_error_to_string(int code)
 {
    int x;
 
@@ -42,6 +42,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_fast_mp_invmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_fast_mp_invmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_FAST_MP_INVMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes the modular inverse via binary extended euclidean algorithm, 
@@ -27,7 +27,7 @@
   int     res, neg;
 
   /* 2. [modified] b must be odd   */
-  if (mp_iseven (b) == 1) {
+  if (mp_iseven (b) == MP_YES) {
     return MP_VAL;
   }
 
@@ -57,13 +57,13 @@
 
 top:
   /* 4.  while u is even do */
-  while (mp_iseven (&u) == 1) {
+  while (mp_iseven (&u) == MP_YES) {
     /* 4.1 u = u/2 */
     if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
       goto LBL_ERR;
     }
     /* 4.2 if B is odd then */
-    if (mp_isodd (&B) == 1) {
+    if (mp_isodd (&B) == MP_YES) {
       if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
         goto LBL_ERR;
       }
@@ -75,13 +75,13 @@
   }
 
   /* 5.  while v is even do */
-  while (mp_iseven (&v) == 1) {
+  while (mp_iseven (&v) == MP_YES) {
     /* 5.1 v = v/2 */
     if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
       goto LBL_ERR;
     }
     /* 5.2 if D is odd then */
-    if (mp_isodd (&D) == 1) {
+    if (mp_isodd (&D) == MP_YES) {
       /* D = (D-x)/2 */
       if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
         goto LBL_ERR;
@@ -115,7 +115,7 @@
   }
 
   /* if not zero goto step 4 */
-  if (mp_iszero (&u) == 0) {
+  if (mp_iszero (&u) == MP_NO) {
     goto top;
   }
 
@@ -143,6 +143,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_fast_mp_montgomery_reduce.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_fast_mp_montgomery_reduce.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction
@@ -32,7 +32,7 @@
   olduse = x->used;
 
   /* grow a as required */
-  if (x->alloc < n->used + 1) {
+  if (x->alloc < (n->used + 1)) {
     if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) {
       return res;
     }
@@ -42,8 +42,8 @@
    * an array of double precision words W[...]
    */
   {
-    register mp_word *_W;
-    register mp_digit *tmpx;
+    mp_word *_W;
+    mp_digit *tmpx;
 
     /* alias for the W[] array */
     _W   = W;
@@ -57,7 +57,7 @@
     }
 
     /* zero the high words of W[a->used..m->used*2] */
-    for (; ix < n->used * 2 + 1; ix++) {
+    for (; ix < ((n->used * 2) + 1); ix++) {
       *_W++ = 0;
     }
   }
@@ -72,7 +72,7 @@
      * by casting the value down to a mp_digit.  Note this requires
      * that W[ix-1] have  the carry cleared (see after the inner loop)
      */
-    register mp_digit mu;
+    mp_digit mu;
     mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK);
 
     /* a = a + mu * m * b**i
@@ -90,9 +90,9 @@
      * first m->used words of W[] have the carries fixed
      */
     {
-      register int iy;
-      register mp_digit *tmpn;
-      register mp_word *_W;
+      int iy;
+      mp_digit *tmpn;
+      mp_word *_W;
 
       /* alias for the digits of the modulus */
       tmpn = n->dp;
@@ -115,8 +115,8 @@
    * significant digits we zeroed].
    */
   {
-    register mp_digit *tmpx;
-    register mp_word *_W, *_W1;
+    mp_digit *tmpx;
+    mp_word *_W, *_W1;
 
     /* nox fix rest of carries */
 
@@ -126,7 +126,7 @@
     /* alias for next word, where the carry goes */
     _W = W + ++ix;
 
-    for (; ix <= n->used * 2 + 1; ix++) {
+    for (; ix <= ((n->used * 2) + 1); ix++) {
       *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
     }
 
@@ -143,7 +143,7 @@
     /* alias for shifted double precision result */
     _W = W + n->used;
 
-    for (ix = 0; ix < n->used + 1; ix++) {
+    for (ix = 0; ix < (n->used + 1); ix++) {
       *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
     }
 
@@ -167,6 +167,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_fast_mp_montgomery_reduce.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_fast_s_mp_mul_digs.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_fast_s_mp_mul_digs.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_FAST_S_MP_MUL_DIGS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Fast (comba) multiplier
@@ -35,7 +35,7 @@
 {
   int     olduse, res, pa, ix, iz;
   mp_digit W[MP_WARRAY];
-  register mp_word  _W;
+  mp_word  _W;
 
   /* grow the destination as required */
   if (c->alloc < digs) {
@@ -78,16 +78,16 @@
 
       /* make next carry */
       _W = _W >> ((mp_word)DIGIT_BIT);
- }
+  }
 
   /* setup dest */
   olduse  = c->used;
   c->used = pa;
 
   {
-    register mp_digit *tmpc;
+    mp_digit *tmpc;
     tmpc = c->dp;
-    for (ix = 0; ix < pa+1; ix++) {
+    for (ix = 0; ix < (pa + 1); ix++) {
       /* now extract the previous digit [below the carry] */
       *tmpc++ = W[ix];
     }
@@ -102,6 +102,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
-/* $Revision: 1.7 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_fast_s_mp_mul_high_digs.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_fast_s_mp_mul_high_digs.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* this is a modified version of fast_s_mul_digs that only produces
@@ -75,7 +75,7 @@
   c->used = pa;
 
   {
-    register mp_digit *tmpc;
+    mp_digit *tmpc;
 
     tmpc = c->dp + digs;
     for (ix = digs; ix < pa; ix++) {
@@ -93,6 +93,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_high_digs.c,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2006/11/14 03:46:25 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_fast_s_mp_sqr.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_fast_s_mp_sqr.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_FAST_S_MP_SQR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* the jist of squaring...
@@ -66,7 +66,7 @@
        * we halve the distance since they approach at a rate of 2x
        * and we have to round because odd cases need to be executed
        */
-      iy = MIN(iy, (ty-tx+1)>>1);
+      iy = MIN(iy, ((ty-tx)+1)>>1);
 
       /* execute loop */
       for (iz = 0; iz < iy; iz++) {
@@ -109,6 +109,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_sqr.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_2expt.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_2expt.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_2EXPT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes a = 2**b 
@@ -29,12 +29,12 @@
   mp_zero (a);
 
   /* grow a to accomodate the single bit */
-  if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) {
+  if ((res = mp_grow (a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
     return res;
   }
 
   /* set the used count of where the bit will go */
-  a->used = b / DIGIT_BIT + 1;
+  a->used = (b / DIGIT_BIT) + 1;
 
   /* put the single bit in its place */
   a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);
@@ -43,6 +43,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_abs.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_abs.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_ABS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* b = |a| 
@@ -38,6 +38,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_add.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_add.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_ADD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* high level addition (handles signs) */
@@ -48,6 +48,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_add_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_add_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_ADD_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* single digit addition */
@@ -23,14 +23,14 @@
   mp_digit *tmpa, *tmpc, mu;
 
   /* grow c as required */
-  if (c->alloc < a->used + 1) {
+  if (c->alloc < (a->used + 1)) {
      if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
         return res;
      }
   }
 
   /* if a is negative and |a| >= b, call c = |a| - b */
-  if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) {
+  if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) {
      /* temporarily fix sign of a */
      a->sign = MP_ZPOS;
 
@@ -107,6 +107,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_addmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_addmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_ADDMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* d = a + b (mod c) */
@@ -36,6 +36,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_and.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_and.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_AND_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected]mail.com, http://libtom.org
  */
 
 /* AND two ints together */
@@ -52,6 +52,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_clamp.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_clamp.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CLAMP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* trim unused digits 
@@ -28,7 +28,7 @@
   /* decrease used while the most significant digit is
    * zero.
    */
-  while (a->used > 0 && a->dp[a->used - 1] == 0) {
+  while ((a->used > 0) && (a->dp[a->used - 1] == 0)) {
     --(a->used);
   }
 
@@ -39,6 +39,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_clear.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_clear.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #include "dbhelpers.h"
 #ifdef BN_MP_CLEAR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* clear one (frees)  */
@@ -36,6 +36,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_clear_multi.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_clear_multi.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CLEAR_MULTI_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 #include <stdarg.h>
 
@@ -29,6 +29,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_cmp.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_cmp.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CMP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* compare two ints (signed)*/
@@ -38,6 +38,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_cmp_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_cmp_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CMP_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* compare a digit */
@@ -39,6 +39,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_cmp_mag.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_cmp_mag.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CMP_MAG_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* compare maginitude of two ints (unsigned) */
@@ -50,6 +50,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_cnt_lsb.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_cnt_lsb.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_CNT_LSB_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 static const int lnz[16] = { 
@@ -26,12 +26,12 @@
    mp_digit q, qq;
 
    /* easy out */
-   if (mp_iszero(a) == 1) {
+   if (mp_iszero(a) == MP_YES) {
       return 0;
    }
 
    /* scan lower digits until non-zero */
-   for (x = 0; x < a->used && a->dp[x] == 0; x++);
+   for (x = 0; (x < a->used) && (a->dp[x] == 0); x++) {}
    q = a->dp[x];
    x *= DIGIT_BIT;
 
@@ -48,6 +48,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_copy.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_copy.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_COPY_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* copy, b = a */
@@ -35,7 +35,7 @@
 
   /* zero b and copy the parameters over */
   {
-    register mp_digit *tmpa, *tmpb;
+    mp_digit *tmpa, *tmpb;
 
     /* pointer aliases */
 
@@ -63,6 +63,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_copy.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_count_bits.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_count_bits.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_COUNT_BITS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* returns the number of bits in an int */
@@ -40,6 +40,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_div.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_div.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DIV_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 #ifdef BN_MP_DIV_SMALL
@@ -24,7 +24,7 @@
    int    res, n, n2;
 
   /* is divisor zero ? */
-  if (mp_iszero (b) == 1) {
+  if (mp_iszero (b) == MP_YES) {
     return MP_VAL;
   }
 
@@ -40,9 +40,9 @@
     }
     return res;
   }
-	
+
   /* init our temps */
-  if ((res = mp_init_multi(&ta, &tb, &tq, &q, NULL) != MP_OKAY)) {
+  if ((res = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) {
      return res;
   }
 
@@ -50,7 +50,7 @@
   mp_set(&tq, 1);
   n = mp_count_bits(a) - mp_count_bits(b);
   if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
-      ((res = mp_abs(b, &tb)) != MP_OKAY) || 
+      ((res = mp_abs(b, &tb)) != MP_OKAY) ||
       ((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
       ((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
       goto LBL_ERR;
@@ -71,7 +71,7 @@
 
   /* now q == quotient and ta == remainder */
   n  = a->sign;
-  n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
+  n2 = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
   if (c != NULL) {
      mp_exch(c, &q);
      c->sign  = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
@@ -87,17 +87,17 @@
 
 #else
 
-/* integer signed division. 
+/* integer signed division.
  * c*b + d == a [e.g. a/b, c=quotient, d=remainder]
  * HAC pp.598 Algorithm 14.20
  *
- * Note that the description in HAC is horribly 
- * incomplete.  For example, it doesn't consider 
- * the case where digits are removed from 'x' in 
- * the inner loop.  It also doesn't consider the 
+ * Note that the description in HAC is horribly
+ * incomplete.  For example, it doesn't consider
+ * the case where digits are removed from 'x' in
+ * the inner loop.  It also doesn't consider the
  * case that y has fewer than three digits, etc..
  *
- * The overall algorithm is as described as 
+ * The overall algorithm is as described as
  * 14.20 from HAC but fixed to treat these cases.
 */
 int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
@@ -106,7 +106,7 @@
   int     res, n, t, i, norm, neg;
 
   /* is divisor zero ? */
-  if (mp_iszero (b) == 1) {
+  if (mp_iszero (b) == MP_YES) {
     return MP_VAL;
   }
 
@@ -187,51 +187,52 @@
       continue;
     }
 
-    /* step 3.1 if xi == yt then set q{i-t-1} to b-1, 
+    /* step 3.1 if xi == yt then set q{i-t-1} to b-1,
      * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
     if (x.dp[i] == y.dp[t]) {
-      q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
+      q.dp[(i - t) - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
     } else {
       mp_word tmp;
       tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
       tmp |= ((mp_word) x.dp[i - 1]);
       tmp /= ((mp_word) y.dp[t]);
-      if (tmp > (mp_word) MP_MASK)
+      if (tmp > (mp_word) MP_MASK) {
         tmp = MP_MASK;
-      q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
+      }
+      q.dp[(i - t) - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
     }
 
-    /* while (q{i-t-1} * (yt * b + y{t-1})) > 
-             xi * b**2 + xi-1 * b + xi-2 
-     
-       do q{i-t-1} -= 1; 
+    /* while (q{i-t-1} * (yt * b + y{t-1})) >
+             xi * b**2 + xi-1 * b + xi-2
+
+       do q{i-t-1} -= 1;
     */
-    q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK;
+    q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] + 1) & MP_MASK;
     do {
-      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK;
+      q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1) & MP_MASK;
 
       /* find left hand */
       mp_zero (&t1);
-      t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1];
+      t1.dp[0] = ((t - 1) < 0) ? 0 : y.dp[t - 1];
       t1.dp[1] = y.dp[t];
       t1.used = 2;
-      if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
+      if ((res = mp_mul_d (&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
         goto LBL_Y;
       }
 
       /* find right hand */
-      t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2];
-      t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1];
+      t2.dp[0] = ((i - 2) < 0) ? 0 : x.dp[i - 2];
+      t2.dp[1] = ((i - 1) < 0) ? 0 : x.dp[i - 1];
       t2.dp[2] = x.dp[i];
       t2.used = 3;
     } while (mp_cmp_mag(&t1, &t2) == MP_GT);
 
     /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
-    if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
+    if ((res = mp_mul_d (&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
       goto LBL_Y;
     }
 
-    if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
+    if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) {
       goto LBL_Y;
     }
 
@@ -244,23 +245,23 @@
       if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
         goto LBL_Y;
       }
-      if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
+      if ((res = mp_lshd (&t1, (i - t) - 1)) != MP_OKAY) {
         goto LBL_Y;
       }
       if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
         goto LBL_Y;
       }
 
-      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
+      q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1UL) & MP_MASK;
     }
   }
 
-  /* now q is the quotient and x is the remainder 
-   * [which we have to normalize] 
+  /* now q is the quotient and x is the remainder
+   * [which we have to normalize]
    */
-  
+
   /* get sign before writing to c */
-  x.sign = x.used == 0 ? MP_ZPOS : a->sign;
+  x.sign = (x.used == 0) ? MP_ZPOS : a->sign;
 
   if (c != NULL) {
     mp_clamp (&q);
@@ -270,8 +271,8 @@
 
   if (d != NULL) {
     if ((res = mp_div_2d (&x, norm, &x, NULL)) != MP_OKAY) {
-		goto LBL_Y;
-	}
+      goto LBL_Y;
+    }
     mp_exch (&x, d);
   }
 
@@ -289,6 +290,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_div.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_div_2.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_div_2.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DIV_2_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* b = a/2 */
@@ -30,7 +30,7 @@
   oldused = b->used;
   b->used = a->used;
   {
-    register mp_digit r, rr, *tmpa, *tmpb;
+    mp_digit r, rr, *tmpa, *tmpb;
 
     /* source alias */
     tmpa = a->dp + b->used - 1;
@@ -63,6 +63,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_div_2d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_div_2d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DIV_2D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
@@ -58,7 +58,7 @@
   /* shift any bit count < DIGIT_BIT */
   D = (mp_digit) (b % DIGIT_BIT);
   if (D != 0) {
-    register mp_digit *tmpc, mask, shift;
+    mp_digit *tmpc, mask, shift;
 
     /* mask */
     mask = (((mp_digit)1) << D) - 1;
@@ -92,6 +92,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_div_2d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_div_3.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_div_3.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DIV_3_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* divide by three (based on routine from MPI and the GMP manual) */
@@ -74,6 +74,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_div_3.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_div_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_div_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DIV_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,14 +12,19 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 static int s_is_power_of_two(mp_digit b, int *p)
 {
    int x;
 
-   for (x = 1; x < DIGIT_BIT; x++) {
+   /* fast return if no power of two */
+   if ((b == 0) || ((b & (b-1)) != 0)) {
+      return 0;
+   }
+
+   for (x = 0; x < DIGIT_BIT; x++) {
       if (b == (((mp_digit)1)<<x)) {
          *p = x;
          return 1;
@@ -42,7 +47,7 @@
   }
 
   /* quick outs */
-  if (b == 1 || mp_iszero(a) == 1) {
+  if ((b == 1) || (mp_iszero(a) == MP_YES)) {
      if (d != NULL) {
         *d = 0;
      }
@@ -105,6 +110,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_dr_is_modulus.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_dr_is_modulus.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DR_IS_MODULUS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines if a number is a valid DR modulus */
@@ -38,6 +38,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_dr_reduce.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_dr_reduce.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DR_REDUCE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
@@ -40,7 +40,7 @@
   m = n->used;
 
   /* ensure that "x" has at least 2m digits */
-  if (x->alloc < m + m) {
+  if (x->alloc < (m + m)) {
     if ((err = mp_grow (x, m + m)) != MP_OKAY) {
       return err;
     }
@@ -62,7 +62,7 @@
 
   /* compute (x mod B**m) + k * [x/B**m] inline and inplace */
   for (i = 0; i < m; i++) {
-      r         = ((mp_word)*tmpx2++) * ((mp_word)k) + *tmpx1 + mu;
+      r         = (((mp_word)*tmpx2++) * (mp_word)k) + *tmpx1 + mu;
       *tmpx1++  = (mp_digit)(r & MP_MASK);
       mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
   }
@@ -82,13 +82,15 @@
    * Each successive "recursion" makes the input smaller and smaller.
    */
   if (mp_cmp_mag (x, n) != MP_LT) {
-    s_mp_sub(x, n, x);
+    if ((err = s_mp_sub(x, n, x)) != MP_OKAY) {
+      return err;
+    }
     goto top;
   }
   return MP_OKAY;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_dr_reduce.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_dr_setup.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_dr_setup.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_DR_SETUP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines the setup value */
@@ -27,6 +27,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_exch.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_exch.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_EXCH_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* swap the elements of two integers, for cases where you can't simply swap the 
@@ -29,6 +29,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_export.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,88 @@
+#include <tommath_private.h>
+#ifdef BN_MP_EXPORT_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* based on gmp's mpz_export.
+ * see http://gmplib.org/manual/Integer-Import-and-Export.html
+ */
+int mp_export(void* rop, size_t* countp, int order, size_t size, 
+                                int endian, size_t nails, mp_int* op) {
+	int result;
+	size_t odd_nails, nail_bytes, i, j, bits, count;
+	unsigned char odd_nail_mask;
+
+	mp_int t;
+
+	if ((result = mp_init_copy(&t, op)) != MP_OKAY) {
+		return result;
+	}
+
+	if (endian == 0) {
+		union {
+			unsigned int i;
+			char c[4];
+		} lint;
+		lint.i = 0x01020304;
+
+		endian = (lint.c[0] == 4) ? -1 : 1;
+	}
+
+	odd_nails = (nails % 8);
+	odd_nail_mask = 0xff;
+	for (i = 0; i < odd_nails; ++i) {
+		odd_nail_mask ^= (1 << (7 - i));
+	}
+	nail_bytes = nails / 8;
+
+	bits = mp_count_bits(&t);
+	count = (bits / ((size * 8) - nails)) + (((bits % ((size * 8) - nails)) != 0) ? 1 : 0);
+
+	for (i = 0; i < count; ++i) {
+		for (j = 0; j < size; ++j) {
+			unsigned char* byte = (
+				(unsigned char*)rop + 
+				(((order == -1) ? i : ((count - 1) - i)) * size) +
+				((endian == -1) ? j : ((size - 1) - j))
+			);
+
+			if (j >= (size - nail_bytes)) {
+				*byte = 0;
+				continue;
+			}
+
+			*byte = (unsigned char)((j == ((size - nail_bytes) - 1)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFF));
+
+			if ((result = mp_div_2d(&t, ((j == ((size - nail_bytes) - 1)) ? (8 - odd_nails) : 8), &t, NULL)) != MP_OKAY) {
+				mp_clear(&t);
+				return result;
+			}
+		}
+	}
+
+	mp_clear(&t);
+
+	if (countp != NULL) {
+		*countp = count;
+	}
+
+	return MP_OKAY;
+}
+
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_expt_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_expt_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_EXPT_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,46 +12,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* calculate c = a**b  using a square-multiply algorithm */
+/* wrapper function for mp_expt_d_ex() */
 int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
 {
-  int     res, x;
-  mp_int  g;
-
-  if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
-    return res;
-  }
-
-  /* set initial result */
-  mp_set (c, 1);
+  return mp_expt_d_ex(a, b, c, 0);
+}
 
-  for (x = 0; x < (int) DIGIT_BIT; x++) {
-    /* square */
-    if ((res = mp_sqr (c, c)) != MP_OKAY) {
-      mp_clear (&g);
-      return res;
-    }
-
-    /* if the bit is set multiply */
-    if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) {
-      if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
-         mp_clear (&g);
-         return res;
-      }
-    }
-
-    /* shift to next bit */
-    b <<= 1;
-  }
-
-  mp_clear (&g);
-  return MP_OKAY;
-}
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_expt_d_ex.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,83 @@
+#include <tommath_private.h>
+#ifdef BN_MP_EXPT_D_EX_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* calculate c = a**b  using a square-multiply algorithm */
+int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
+{
+  int     res;
+  unsigned int x;
+
+  mp_int  g;
+
+  if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
+    return res;
+  }
+
+  /* set initial result */
+  mp_set (c, 1);
+
+  if (fast != 0) {
+    while (b > 0) {
+      /* if the bit is set multiply */
+      if ((b & 1) != 0) {
+        if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
+          mp_clear (&g);
+          return res;
+        }
+      }
+
+      /* square */
+      if (b > 1) {
+        if ((res = mp_sqr (&g, &g)) != MP_OKAY) {
+          mp_clear (&g);
+          return res;
+        }
+      }
+
+      /* shift to next bit */
+      b >>= 1;
+    }
+  }
+  else {
+    for (x = 0; x < DIGIT_BIT; x++) {
+      /* square */
+      if ((res = mp_sqr (c, c)) != MP_OKAY) {
+        mp_clear (&g);
+        return res;
+      }
+
+      /* if the bit is set multiply */
+      if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) {
+        if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
+           mp_clear (&g);
+           return res;
+        }
+      }
+
+      /* shift to next bit */
+      b <<= 1;
+    }
+  } /* if ... else */
+
+  mp_clear (&g);
+  return MP_OKAY;
+}
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_exptmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_exptmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_EXPTMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 
@@ -89,7 +89,7 @@
     
   /* if the modulus is odd or dr != 0 use the montgomery method */
 #ifdef BN_MP_EXPTMOD_FAST_C
-  if (mp_isodd (P) == 1 || dr !=  0) {
+  if ((mp_isodd (P) == MP_YES) || (dr !=  0)) {
     return mp_exptmod_fast (G, X, P, Y, dr);
   } else {
 #endif
@@ -107,6 +107,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_exptmod_fast.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_exptmod_fast.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_EXPTMOD_FAST_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
@@ -96,8 +96,8 @@
 
      /* automatically pick the comba one if available (saves quite a few calls/ifs) */
 #ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
-     if (((P->used * 2 + 1) < MP_WARRAY) &&
-          P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
+     if ((((P->used * 2) + 1) < MP_WARRAY) &&
+          (P->used < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
         redux = fast_mp_montgomery_reduce;
      } else 
 #endif
@@ -219,12 +219,12 @@
      * in the exponent.  Technically this opt is not required but it
      * does lower the # of trivial squaring/reductions used
      */
-    if (mode == 0 && y == 0) {
+    if ((mode == 0) && (y == 0)) {
       continue;
     }
 
     /* if the bit is zero and mode == 1 then we square */
-    if (mode == 1 && y == 0) {
+    if ((mode == 1) && (y == 0)) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
         goto LBL_RES;
       }
@@ -266,7 +266,7 @@
   }
 
   /* if bits remain then square/multiply */
-  if (mode == 2 && bitcpy > 0) {
+  if ((mode == 2) && (bitcpy > 0)) {
     /* square then multiply if the bit is set */
     for (x = 0; x < bitcpy; x++) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
@@ -316,6 +316,6 @@
 #endif
 
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod_fast.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_exteuclid.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_exteuclid.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_EXTEUCLID_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,10 +12,10 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* Extended euclidean algorithm of (a, b) produces 
+/* Extended euclidean algorithm of (a, b) produces
    a*u1 + b*u2 = u3
  */
 int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
@@ -29,41 +29,41 @@
 
    /* initialize, (u1,u2,u3) = (1,0,a) */
    mp_set(&u1, 1);
-   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto LBL_ERR; }
+   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto _ERR; }
 
    /* initialize, (v1,v2,v3) = (0,1,b) */
    mp_set(&v2, 1);
-   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto LBL_ERR; }
+   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto _ERR; }
 
    /* loop while v3 != 0 */
    while (mp_iszero(&v3) == MP_NO) {
        /* q = u3/v3 */
-       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto LBL_ERR; }
+       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto _ERR; }
 
        /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
-       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
-       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto LBL_ERR; }
-       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
-       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto LBL_ERR; }
-       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto LBL_ERR; }
-       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto LBL_ERR; }
+       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
+       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto _ERR; }
+       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
+       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto _ERR; }
+       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
+       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto _ERR; }
 
        /* (u1,u2,u3) = (v1,v2,v3) */
-       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto LBL_ERR; }
-       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto LBL_ERR; }
-       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto LBL_ERR; }
+       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto _ERR; }
+       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto _ERR; }
+       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto _ERR; }
 
        /* (v1,v2,v3) = (t1,t2,t3) */
-       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto LBL_ERR; }
-       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto LBL_ERR; }
-       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto LBL_ERR; }
+       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto _ERR; }
+       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto _ERR; }
+       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto _ERR; }
    }
 
    /* make sure U3 >= 0 */
    if (u3.sign == MP_NEG) {
-      mp_neg(&u1, &u1);
-      mp_neg(&u2, &u2);
-      mp_neg(&u3, &u3);
+       if ((err = mp_neg(&u1, &u1)) != MP_OKAY)                                   { goto _ERR; }
+       if ((err = mp_neg(&u2, &u2)) != MP_OKAY)                                   { goto _ERR; }
+       if ((err = mp_neg(&u3, &u3)) != MP_OKAY)                                   { goto _ERR; }
    }
 
    /* copy result out */
@@ -72,12 +72,11 @@
    if (U3 != NULL) { mp_exch(U3, &u3); }
 
    err = MP_OKAY;
-LBL_ERR:
-   mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
+_ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
    return err;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_exteuclid.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_fread.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_fread.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_FREAD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* read a bigint from a file stream in ASCII */
@@ -62,6 +62,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_fread.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_fwrite.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_fwrite.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_FWRITE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 int mp_fwrite(mp_int *a, int radix, FILE *stream)
@@ -47,6 +47,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_gcd.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_gcd.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_GCD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Greatest Common Divisor using the binary method */
@@ -70,7 +70,7 @@
      }
   }
 
-  while (mp_iszero(&v) == 0) {
+  while (mp_iszero(&v) == MP_NO) {
      /* make sure v is the largest */
      if (mp_cmp_mag(&u, &v) == MP_GT) {
         /* swap u and v to make sure v is >= u */
@@ -100,6 +100,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_get_int.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_get_int.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_GET_INT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,25 +12,25 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* get the lower 32-bits of an mp_int */
-unsigned long mp_get_int(mp_int * a) 
+unsigned long mp_get_int(mp_int * a)
 {
   int i;
-  unsigned long res;
+  mp_min_u32 res;
 
   if (a->used == 0) {
      return 0;
   }
 
   /* get number of digits of the lsb we have to read */
-  i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
+  i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
 
   /* get most significant digit of result */
   res = DIGIT(a,i);
-   
+
   while (--i >= 0) {
     res = (res << DIGIT_BIT) | DIGIT(a,i);
   }
@@ -40,6 +40,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_get_long.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,41 @@
+#include <tommath_private.h>
+#ifdef BN_MP_GET_LONG_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* get the lower unsigned long of an mp_int, platform dependent */
+unsigned long mp_get_long(mp_int * a)
+{
+  int i;
+  unsigned long res;
+
+  if (a->used == 0) {
+     return 0;
+  }
+
+  /* get number of digits of the lsb we have to read */
+  i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+
+  /* get most significant digit of result */
+  res = DIGIT(a,i);
+
+#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32)
+  while (--i >= 0) {
+    res = (res << DIGIT_BIT) | DIGIT(a,i);
+  }
+#endif
+  return res;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_get_long_long.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,41 @@
+#include <tommath_private.h>
+#ifdef BN_MP_GET_LONG_LONG_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* get the lower unsigned long long of an mp_int, platform dependent */
+unsigned long long mp_get_long_long (mp_int * a)
+{
+  int i;
+  unsigned long long res;
+
+  if (a->used == 0) {
+     return 0;
+  }
+
+  /* get number of digits of the lsb we have to read */
+  i = MIN(a->used,(int)(((sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
+
+  /* get most significant digit of result */
+  res = DIGIT(a,i);
+
+#if DIGIT_BIT < 64
+  while (--i >= 0) {
+    res = (res << DIGIT_BIT) | DIGIT(a,i);
+  }
+#endif
+  return res;
+}
+#endif
--- a/libtommath/bn_mp_grow.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_grow.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_GROW_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* grow as required */
@@ -52,6 +52,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_import.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,73 @@
+#include <tommath_private.h>
+#ifdef BN_MP_IMPORT_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* based on gmp's mpz_import.
+ * see http://gmplib.org/manual/Integer-Import-and-Export.html
+ */
+int mp_import(mp_int* rop, size_t count, int order, size_t size, 
+                            int endian, size_t nails, const void* op) {
+	int result;
+	size_t odd_nails, nail_bytes, i, j;
+	unsigned char odd_nail_mask;
+
+	mp_zero(rop);
+
+	if (endian == 0) {
+		union {
+			unsigned int i;
+			char c[4];
+		} lint;
+		lint.i = 0x01020304;
+
+		endian = (lint.c[0] == 4) ? -1 : 1;
+	}
+
+	odd_nails = (nails % 8);
+	odd_nail_mask = 0xff;
+	for (i = 0; i < odd_nails; ++i) {
+		odd_nail_mask ^= (1 << (7 - i));
+	}
+	nail_bytes = nails / 8;
+
+	for (i = 0; i < count; ++i) {
+		for (j = 0; j < (size - nail_bytes); ++j) {
+			unsigned char byte = *(
+					(unsigned char*)op + 
+					(((order == 1) ? i : ((count - 1) - i)) * size) +
+					((endian == 1) ? (j + nail_bytes) : (((size - 1) - j) - nail_bytes))
+				);
+
+			if (
+				(result = mp_mul_2d(rop, ((j == 0) ? (8 - odd_nails) : 8), rop)) != MP_OKAY) {
+				return result;
+			}
+
+			rop->dp[0] |= (j == 0) ? (byte & odd_nail_mask) : byte;
+			rop->used  += 1;
+		}
+	}
+
+	mp_clamp(rop);
+
+	return MP_OKAY;
+}
+
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* init a new mp_int */
@@ -41,6 +41,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init_copy.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init_copy.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_COPY_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* creates "a" then copies b into it */
@@ -27,6 +27,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init_multi.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init_multi.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_MULTI_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 #include <stdarg.h>
 
@@ -37,7 +37,7 @@
             /* now start cleaning up */            
             cur_arg = mp;
             va_start(clean_args, mp);
-            while (n--) {
+            while (n-- != 0) {
                 mp_clear(cur_arg);
                 cur_arg = va_arg(clean_args, mp_int*);
             }
@@ -54,6 +54,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init_set.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init_set.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_SET_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* initialize and set a digit */
@@ -27,6 +27,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init_set_int.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init_set_int.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_SET_INT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* initialize and set a digit */
@@ -26,6 +26,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_init_size.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_init_size.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INIT_SIZE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* init an mp_init for a given size */
@@ -43,6 +43,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_invmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_invmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INVMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,32 +12,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* hac 14.61, pp608 */
 int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 {
   /* b cannot be negative */
-  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
+  if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) {
     return MP_VAL;
   }
 
 #ifdef BN_FAST_MP_INVMOD_C
   /* if the modulus is odd we can use a faster routine instead */
-  if (mp_isodd (b) == 1) {
+  if (mp_isodd (b) == MP_YES) {
     return fast_mp_invmod (a, b, c);
   }
 #endif
 
 #ifdef BN_MP_INVMOD_SLOW_C
   return mp_invmod_slow(a, b, c);
+#else
+  return MP_VAL;
 #endif
-
-  return MP_VAL;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_invmod_slow.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_invmod_slow.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_INVMOD_SLOW_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* hac 14.61, pp608 */
@@ -22,7 +22,7 @@
   int     res;
 
   /* b cannot be negative */
-  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
+  if ((b->sign == MP_NEG) || (mp_iszero(b) == MP_YES)) {
     return MP_VAL;
   }
 
@@ -41,7 +41,7 @@
   }
 
   /* 2. [modified] if x,y are both even then return an error! */
-  if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
+  if ((mp_iseven (&x) == MP_YES) && (mp_iseven (&y) == MP_YES)) {
     res = MP_VAL;
     goto LBL_ERR;
   }
@@ -58,13 +58,13 @@
 
 top:
   /* 4.  while u is even do */
-  while (mp_iseven (&u) == 1) {
+  while (mp_iseven (&u) == MP_YES) {
     /* 4.1 u = u/2 */
     if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
       goto LBL_ERR;
     }
     /* 4.2 if A or B is odd then */
-    if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
+    if ((mp_isodd (&A) == MP_YES) || (mp_isodd (&B) == MP_YES)) {
       /* A = (A+y)/2, B = (B-x)/2 */
       if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
          goto LBL_ERR;
@@ -83,13 +83,13 @@
   }
 
   /* 5.  while v is even do */
-  while (mp_iseven (&v) == 1) {
+  while (mp_iseven (&v) == MP_YES) {
     /* 5.1 v = v/2 */
     if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
       goto LBL_ERR;
     }
     /* 5.2 if C or D is odd then */
-    if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
+    if ((mp_isodd (&C) == MP_YES) || (mp_isodd (&D) == MP_YES)) {
       /* C = (C+y)/2, D = (D-x)/2 */
       if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
          goto LBL_ERR;
@@ -137,7 +137,7 @@
   }
 
   /* if not zero goto step 4 */
-  if (mp_iszero (&u) == 0)
+  if (mp_iszero (&u) == MP_NO)
     goto top;
 
   /* now a = C, b = D, gcd == g*v */
@@ -170,6 +170,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_invmod_slow.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_is_square.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_is_square.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_IS_SQUARE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Check if remainders are possible squares - fast exclude non-squares */
@@ -82,13 +82,13 @@
    * free "t" so the easiest way is to goto ERR.  We know that res
    * is already equal to MP_OKAY from the mp_mod call 
    */ 
-  if ( (1L<<(r%11)) & 0x5C4L )             goto ERR;
-  if ( (1L<<(r%13)) & 0x9E4L )             goto ERR;
-  if ( (1L<<(r%17)) & 0x5CE8L )            goto ERR;
-  if ( (1L<<(r%19)) & 0x4F50CL )           goto ERR;
-  if ( (1L<<(r%23)) & 0x7ACCA0L )          goto ERR;
-  if ( (1L<<(r%29)) & 0xC2EDD0CL )         goto ERR;
-  if ( (1L<<(r%31)) & 0x6DE2B848L )        goto ERR;
+  if (((1L<<(r%11)) & 0x5C4L) != 0L)       goto ERR;
+  if (((1L<<(r%13)) & 0x9E4L) != 0L)       goto ERR;
+  if (((1L<<(r%17)) & 0x5CE8L) != 0L)      goto ERR;
+  if (((1L<<(r%19)) & 0x4F50CL) != 0L)     goto ERR;
+  if (((1L<<(r%23)) & 0x7ACCA0L) != 0L)    goto ERR;
+  if (((1L<<(r%29)) & 0xC2EDD0CL) != 0L)   goto ERR;
+  if (((1L<<(r%31)) & 0x6DE2B848L) != 0L)  goto ERR;
 
   /* Final check - is sqr(sqrt(arg)) == arg ? */
   if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
@@ -104,6 +104,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_jacobi.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_jacobi.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_JACOBI_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,27 +12,39 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes the jacobi c = (a | n) (or Legendre if n is prime)
  * HAC pp. 73 Algorithm 2.149
+ * HAC is wrong here, as the special case of (0 | 1) is not
+ * handled correctly.
  */
-int mp_jacobi (mp_int * a, mp_int * p, int *c)
+int mp_jacobi (mp_int * a, mp_int * n, int *c)
 {
   mp_int  a1, p1;
   int     k, s, r, res;
   mp_digit residue;
 
-  /* if p <= 0 return MP_VAL */
-  if (mp_cmp_d(p, 0) != MP_GT) {
+  /* if a < 0 return MP_VAL */
+  if (mp_isneg(a) == MP_YES) {
+     return MP_VAL;
+  }
+
+  /* if n <= 0 return MP_VAL */
+  if (mp_cmp_d(n, 0) != MP_GT) {
      return MP_VAL;
   }
 
-  /* step 1.  if a == 0, return 0 */
-  if (mp_iszero (a) == 1) {
-    *c = 0;
-    return MP_OKAY;
+  /* step 1. handle case of a == 0 */
+  if (mp_iszero (a) == MP_YES) {
+     /* special case of a == 0 and n == 1 */
+     if (mp_cmp_d (n, 1) == MP_EQ) {
+       *c = 1;
+     } else {
+       *c = 0;
+     }
+     return MP_OKAY;
   }
 
   /* step 2.  if a == 1, return 1 */
@@ -64,17 +76,17 @@
     s = 1;
   } else {
     /* else set s=1 if p = 1/7 (mod 8) or s=-1 if p = 3/5 (mod 8) */
-    residue = p->dp[0] & 7;
+    residue = n->dp[0] & 7;
 
-    if (residue == 1 || residue == 7) {
+    if ((residue == 1) || (residue == 7)) {
       s = 1;
-    } else if (residue == 3 || residue == 5) {
+    } else if ((residue == 3) || (residue == 5)) {
       s = -1;
     }
   }
 
   /* step 5.  if p == 3 (mod 4) *and* a1 == 3 (mod 4) then s = -s */
-  if ( ((p->dp[0] & 3) == 3) && ((a1.dp[0] & 3) == 3)) {
+  if ( ((n->dp[0] & 3) == 3) && ((a1.dp[0] & 3) == 3)) {
     s = -s;
   }
 
@@ -83,7 +95,7 @@
     *c = s;
   } else {
     /* n1 = n mod a1 */
-    if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
+    if ((res = mp_mod (n, &a1, &p1)) != MP_OKAY) {
       goto LBL_P1;
     }
     if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
@@ -100,6 +112,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_jacobi.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_karatsuba_mul.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_karatsuba_mul.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_KARATSUBA_MUL_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* c = |a| * |b| using Karatsuba Multiplication using 
@@ -82,8 +82,8 @@
   y1.used = b->used - B;
 
   {
-    register int x;
-    register mp_digit *tmpa, *tmpb, *tmpx, *tmpy;
+    int x;
+    mp_digit *tmpa, *tmpb, *tmpx, *tmpy;
 
     /* we copy the digits directly instead of using higher level functions
      * since we also need to shift the digits
@@ -162,6 +162,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_mul.c,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_karatsuba_sqr.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_karatsuba_sqr.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_KARATSUBA_SQR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Karatsuba squaring, computes b = a*a using three 
@@ -52,8 +52,8 @@
     goto X0X0;
 
   {
-    register int x;
-    register mp_digit *dst, *src;
+    int x;
+    mp_digit *dst, *src;
 
     src = a->dp;
 
@@ -116,6 +116,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_lcm.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_lcm.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_LCM_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes least common multiple as |a*b|/(a, b) */
@@ -55,6 +55,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_lcm.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_lshd.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_lshd.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_LSHD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* shift left a certain amount of digits */
@@ -26,14 +26,14 @@
   }
 
   /* grow to fit the new digits */
-  if (a->alloc < a->used + b) {
+  if (a->alloc < (a->used + b)) {
      if ((res = mp_grow (a, a->used + b)) != MP_OKAY) {
        return res;
      }
   }
 
   {
-    register mp_digit *top, *bottom;
+    mp_digit *top, *bottom;
 
     /* increment the used by the shift amount then copy upwards */
     a->used += b;
@@ -42,7 +42,7 @@
     top = a->dp + a->used - 1;
 
     /* base */
-    bottom = a->dp + a->used - 1 - b;
+    bottom = (a->dp + a->used - 1) - b;
 
     /* much like mp_rshd this is implemented using a sliding window
      * except the window goes the otherway around.  Copying from
@@ -62,6 +62,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_lshd.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,10 +12,10 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* c = a mod b, 0 <= c < b */
+/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
 int
 mp_mod (mp_int * a, mp_int * b, mp_int * c)
 {
@@ -31,11 +31,11 @@
     return res;
   }
 
-  if (t.sign != b->sign) {
-    res = mp_add (b, &t, c);
-  } else {
+  if ((mp_iszero(&t) != MP_NO) || (t.sign == b->sign)) {
     res = MP_OKAY;
     mp_exch (&t, c);
+  } else {
+    res = mp_add (b, &t, c);
   }
 
   mp_clear (&t);
@@ -43,6 +43,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mod_2d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mod_2d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MOD_2D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* calc a value mod 2**b */
@@ -39,7 +39,7 @@
   }
 
   /* zero digits above the last digit of the modulus */
-  for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) {
+  for (x = (b / DIGIT_BIT) + (((b % DIGIT_BIT) == 0) ? 0 : 1); x < c->used; x++) {
     c->dp[x] = 0;
   }
   /* clear the digit that is not completely outside/inside the modulus */
@@ -50,6 +50,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mod_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mod_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MOD_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 int
@@ -22,6 +22,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_montgomery_calc_normalization.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_montgomery_calc_normalization.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /*
@@ -29,7 +29,7 @@
   bits = mp_count_bits (b) % DIGIT_BIT;
 
   if (b->used > 1) {
-     if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) {
+     if ((res = mp_2expt (a, ((b->used - 1) * DIGIT_BIT) + bits - 1)) != MP_OKAY) {
         return res;
      }
   } else {
@@ -54,6 +54,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_calc_normalization.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_montgomery_reduce.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_montgomery_reduce.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MONTGOMERY_REDUCE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction */
@@ -28,10 +28,10 @@
    * than the available columns [255 per default] since carries
    * are fixed up in the inner loop.
    */
-  digs = n->used * 2 + 1;
+  digs = (n->used * 2) + 1;
   if ((digs < MP_WARRAY) &&
-      n->used <
-      (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
+      (n->used <
+      (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
     return fast_mp_montgomery_reduce (x, n, rho);
   }
 
@@ -52,13 +52,13 @@
      * following inner loop to reduce the
      * input one digit at a time
      */
-    mu = (mp_digit) (((mp_word)x->dp[ix]) * ((mp_word)rho) & MP_MASK);
+    mu = (mp_digit) (((mp_word)x->dp[ix] * (mp_word)rho) & MP_MASK);
 
     /* a = a + mu * m * b**i */
     {
-      register int iy;
-      register mp_digit *tmpn, *tmpx, u;
-      register mp_word r;
+      int iy;
+      mp_digit *tmpn, *tmpx, u;
+      mp_word r;
 
       /* alias for digits of the modulus */
       tmpn = n->dp;
@@ -72,8 +72,8 @@
       /* Multiply and add in place */
       for (iy = 0; iy < n->used; iy++) {
         /* compute product and sum */
-        r       = ((mp_word)mu) * ((mp_word)*tmpn++) +
-                  ((mp_word) u) + ((mp_word) * tmpx);
+        r       = ((mp_word)mu * (mp_word)*tmpn++) +
+                   (mp_word) u + (mp_word) *tmpx;
 
         /* get carry */
         u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
@@ -85,7 +85,7 @@
 
 
       /* propagate carries upwards as required*/
-      while (u) {
+      while (u != 0) {
         *tmpx   += u;
         u        = *tmpx >> DIGIT_BIT;
         *tmpx++ &= MP_MASK;
@@ -113,6 +113,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_reduce.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_montgomery_setup.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_montgomery_setup.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MONTGOMERY_SETUP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* setups the montgomery reduction stuff */
@@ -36,24 +36,24 @@
   }
 
   x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
-  x *= 2 - b * x;               /* here x*a==1 mod 2**8 */
+  x *= 2 - (b * x);             /* here x*a==1 mod 2**8 */
 #if !defined(MP_8BIT)
-  x *= 2 - b * x;               /* here x*a==1 mod 2**16 */
+  x *= 2 - (b * x);             /* here x*a==1 mod 2**16 */
 #endif
 #if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT))
-  x *= 2 - b * x;               /* here x*a==1 mod 2**32 */
+  x *= 2 - (b * x);             /* here x*a==1 mod 2**32 */
 #endif
 #ifdef MP_64BIT
-  x *= 2 - b * x;               /* here x*a==1 mod 2**64 */
+  x *= 2 - (b * x);             /* here x*a==1 mod 2**64 */
 #endif
 
   /* rho = -1/m mod b */
-  *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
+  *rho = (mp_digit)(((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 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mul.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mul.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MUL_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* high level multiplication (handles sign) */
@@ -44,23 +44,24 @@
 
 #ifdef BN_FAST_S_MP_MUL_DIGS_C
     if ((digs < MP_WARRAY) &&
-        MIN(a->used, b->used) <= 
-        (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
+        (MIN(a->used, b->used) <= 
+         (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
       res = fast_s_mp_mul_digs (a, b, c, digs);
     } else 
 #endif
+    {
 #ifdef BN_S_MP_MUL_DIGS_C
       res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
 #else
       res = MP_VAL;
 #endif
-
+    }
   }
   c->sign = (c->used > 0) ? neg : MP_ZPOS;
   return res;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mul.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mul_2.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mul_2.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MUL_2_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* b = a*2 */
@@ -21,7 +21,7 @@
   int     x, res, oldused;
 
   /* grow to accomodate result */
-  if (b->alloc < a->used + 1) {
+  if (b->alloc < (a->used + 1)) {
     if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) {
       return res;
     }
@@ -31,7 +31,7 @@
   b->used = a->used;
 
   {
-    register mp_digit r, rr, *tmpa, *tmpb;
+    mp_digit r, rr, *tmpa, *tmpb;
 
     /* alias for source */
     tmpa = a->dp;
@@ -77,6 +77,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mul_2d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mul_2d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MUL_2D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* shift left by a certain bit count */
@@ -28,8 +28,8 @@
      }
   }
 
-  if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) {
-     if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) {
+  if (c->alloc < (int)(c->used + (b / DIGIT_BIT) + 1)) {
+     if ((res = mp_grow (c, c->used + (b / DIGIT_BIT) + 1)) != MP_OKAY) {
        return res;
      }
   }
@@ -44,8 +44,8 @@
   /* shift any bit count < DIGIT_BIT */
   d = (mp_digit) (b % DIGIT_BIT);
   if (d != 0) {
-    register mp_digit *tmpc, shift, mask, r, rr;
-    register int x;
+    mp_digit *tmpc, shift, mask, r, rr;
+    int x;
 
     /* bitmask for carries */
     mask = (((mp_digit)1) << d) - 1;
@@ -80,6 +80,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mul_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mul_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MUL_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* multiply by a digit */
@@ -24,7 +24,7 @@
   int      ix, res, olduse;
 
   /* make sure c is big enough to hold a*b */
-  if (c->alloc < a->used + 1) {
+  if (c->alloc < (a->used + 1)) {
     if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) {
       return res;
     }
@@ -48,7 +48,7 @@
   /* compute columns */
   for (ix = 0; ix < a->used; ix++) {
     /* compute product and carry sum for this term */
-    r       = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b);
+    r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
 
     /* mask off higher bits to get a single digit */
     *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
@@ -74,6 +74,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mul_d.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_mulmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_mulmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_MULMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* d = a * b (mod c) */
@@ -35,6 +35,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_n_root.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_n_root.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_N_ROOT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,121 +12,19 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* find the n'th root of an integer 
- *
- * Result found such that (c)**b <= a and (c+1)**b > a 
- *
- * This algorithm uses Newton's approximation 
- * x[i+1] = x[i] - f(x[i])/f'(x[i]) 
- * which will find the root in log(N) time where 
- * each step involves a fair bit.  This is not meant to 
- * find huge roots [square and cube, etc].
+/* wrapper function for mp_n_root_ex()
+ * computes c = (a)**(1/b) such that (c)**b <= a and (c+1)**b > a
  */
 int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
 {
-  mp_int  t1, t2, t3;
-  int     res, neg;
-
-  /* input must be positive if b is even */
-  if ((b & 1) == 0 && a->sign == MP_NEG) {
-    return MP_VAL;
-  }
-
-  if ((res = mp_init (&t1)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_init (&t2)) != MP_OKAY) {
-    goto LBL_T1;
-  }
-
-  if ((res = mp_init (&t3)) != MP_OKAY) {
-    goto LBL_T2;
-  }
-
-  /* if a is negative fudge the sign but keep track */
-  neg     = a->sign;
-  a->sign = MP_ZPOS;
-
-  /* t2 = 2 */
-  mp_set (&t2, 2);
-
-  do {
-    /* t1 = t2 */
-    if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
-      goto LBL_T3;
-    }
-
-    /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
-    
-    /* t3 = t1**(b-1) */
-    if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {   
-      goto LBL_T3;
-    }
-
-    /* numerator */
-    /* t2 = t1**b */
-    if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {    
-      goto LBL_T3;
-    }
+  return mp_n_root_ex(a, b, c, 0);
+}
 
-    /* t2 = t1**b - a */
-    if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {  
-      goto LBL_T3;
-    }
-
-    /* denominator */
-    /* t3 = t1**(b-1) * b  */
-    if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {    
-      goto LBL_T3;
-    }
-
-    /* t3 = (t1**b - a)/(b * t1**(b-1)) */
-    if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {  
-      goto LBL_T3;
-    }
-
-    if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
-      goto LBL_T3;
-    }
-  }  while (mp_cmp (&t1, &t2) != MP_EQ);
-
-  /* result can be off by a few so check */
-  for (;;) {
-    if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
-      goto LBL_T3;
-    }
-
-    if (mp_cmp (&t2, a) == MP_GT) {
-      if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
-         goto LBL_T3;
-      }
-    } else {
-      break;
-    }
-  }
-
-  /* reset the sign of a first */
-  a->sign = neg;
-
-  /* set the result */
-  mp_exch (&t1, c);
-
-  /* set the sign of the result */
-  c->sign = neg;
-
-  res = MP_OKAY;
-
-LBL_T3:mp_clear (&t3);
-LBL_T2:mp_clear (&t2);
-LBL_T1:mp_clear (&t1);
-  return res;
-}
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_n_root.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_n_root_ex.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,132 @@
+#include <tommath_private.h>
+#ifdef BN_MP_N_ROOT_EX_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* find the n'th root of an integer
+ *
+ * Result found such that (c)**b <= a and (c+1)**b > a
+ *
+ * This algorithm uses Newton's approximation
+ * x[i+1] = x[i] - f(x[i])/f'(x[i])
+ * which will find the root in log(N) time where
+ * each step involves a fair bit.  This is not meant to
+ * find huge roots [square and cube, etc].
+ */
+int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast)
+{
+  mp_int  t1, t2, t3;
+  int     res, neg;
+
+  /* input must be positive if b is even */
+  if (((b & 1) == 0) && (a->sign == MP_NEG)) {
+    return MP_VAL;
+  }
+
+  if ((res = mp_init (&t1)) != MP_OKAY) {
+    return res;
+  }
+
+  if ((res = mp_init (&t2)) != MP_OKAY) {
+    goto LBL_T1;
+  }
+
+  if ((res = mp_init (&t3)) != MP_OKAY) {
+    goto LBL_T2;
+  }
+
+  /* if a is negative fudge the sign but keep track */
+  neg     = a->sign;
+  a->sign = MP_ZPOS;
+
+  /* t2 = 2 */
+  mp_set (&t2, 2);
+
+  do {
+    /* t1 = t2 */
+    if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
+
+    /* t3 = t1**(b-1) */
+    if ((res = mp_expt_d_ex (&t1, b - 1, &t3, fast)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    /* numerator */
+    /* t2 = t1**b */
+    if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    /* t2 = t1**b - a */
+    if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    /* denominator */
+    /* t3 = t1**(b-1) * b  */
+    if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    /* t3 = (t1**b - a)/(b * t1**(b-1)) */
+    if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+  }  while (mp_cmp (&t1, &t2) != MP_EQ);
+
+  /* result can be off by a few so check */
+  for (;;) {
+    if ((res = mp_expt_d_ex (&t1, b, &t2, fast)) != MP_OKAY) {
+      goto LBL_T3;
+    }
+
+    if (mp_cmp (&t2, a) == MP_GT) {
+      if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
+         goto LBL_T3;
+      }
+    } else {
+      break;
+    }
+  }
+
+  /* reset the sign of a first */
+  a->sign = neg;
+
+  /* set the result */
+  mp_exch (&t1, c);
+
+  /* set the sign of the result */
+  c->sign = neg;
+
+  res = MP_OKAY;
+
+LBL_T3:mp_clear (&t3);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
+  return res;
+}
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_neg.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_neg.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_NEG_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* b = -a */
@@ -35,6 +35,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_or.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_or.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_OR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* OR two ints together */
@@ -45,6 +45,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_fermat.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_fermat.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_FERMAT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* performs one Fermat test.
@@ -57,6 +57,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_fermat.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_is_divisible.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_is_divisible.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_IS_DIVISIBLE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines if an integers is divisible by one 
@@ -45,6 +45,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_is_prime.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_is_prime.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_IS_PRIME_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* performs a variable number of rounds of Miller-Rabin
@@ -31,7 +31,7 @@
   *result = MP_NO;
 
   /* valid value of t? */
-  if (t <= 0 || t > PRIME_SIZE) {
+  if ((t <= 0) || (t > PRIME_SIZE)) {
     return MP_VAL;
   }
 
@@ -78,6 +78,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_prime.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_miller_rabin.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_miller_rabin.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_MILLER_RABIN_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Miller-Rabin test of "a" to the base of "b" as described in 
@@ -67,10 +67,10 @@
   }
 
   /* if y != 1 and y != n1 do */
-  if (mp_cmp_d (&y, 1) != MP_EQ && mp_cmp (&y, &n1) != MP_EQ) {
+  if ((mp_cmp_d (&y, 1) != MP_EQ) && (mp_cmp (&y, &n1) != MP_EQ)) {
     j = 1;
     /* while j <= s-1 and y != n1 */
-    while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) {
+    while ((j <= (s - 1)) && (mp_cmp (&y, &n1) != MP_EQ)) {
       if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) {
          goto LBL_Y;
       }
@@ -98,6 +98,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_miller_rabin.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_next_prime.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_next_prime.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_NEXT_PRIME_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* finds the next prime after the number "a" using "t" trials
@@ -22,12 +22,12 @@
  */
 int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
 {
-   int      err, res, x, y;
+   int      err, res = MP_NO, x, y;
    mp_digit res_tab[PRIME_SIZE], step, kstep;
    mp_int   b;
 
    /* ensure t is valid */
-   if (t <= 0 || t > PRIME_SIZE) {
+   if ((t <= 0) || (t > PRIME_SIZE)) {
       return MP_VAL;
    }
 
@@ -84,7 +84,7 @@
          if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
       }
    } else {
-      if (mp_iseven(a) == 1) {
+      if (mp_iseven(a) == MP_YES) {
          /* force odd */
          if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
             return err;
@@ -129,7 +129,7 @@
                 y = 1;
              }
          }
-      } while (y == 1 && step < ((((mp_digit)1)<<DIGIT_BIT) - kstep));
+      } while ((y == 1) && (step < ((((mp_digit)1) << DIGIT_BIT) - kstep)));
 
       /* add the step */
       if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
@@ -137,7 +137,7 @@
       }
 
       /* if didn't pass sieve and step == MAX then skip test */
-      if (y == 1 && step >= ((((mp_digit)1)<<DIGIT_BIT) - kstep)) {
+      if ((y == 1) && (step >= ((((mp_digit)1) << DIGIT_BIT) - kstep))) {
          continue;
       }
 
@@ -165,6 +165,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_next_prime.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_rabin_miller_trials.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_rabin_miller_trials.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 
@@ -47,6 +47,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_prime_random_ex.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_prime_random_ex.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_PRIME_RANDOM_EX_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* makes a truly random prime of a given size (bits),
@@ -21,7 +21,6 @@
  * 
  *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
  *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
- *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
  *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
  *
  * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
@@ -37,12 +36,12 @@
    int res, err, bsize, maskOR_msb_offset;
 
    /* sanity check the input */
-   if (size <= 1 || t <= 0) {
+   if ((size <= 1) || (t <= 0)) {
       return MP_VAL;
    }
 
    /* LTM_PRIME_SAFE implies LTM_PRIME_BBS */
-   if (flags & LTM_PRIME_SAFE) {
+   if ((flags & LTM_PRIME_SAFE) != 0) {
       flags |= LTM_PRIME_BBS;
    }
 
@@ -61,13 +60,13 @@
    /* calc the maskOR_msb */
    maskOR_msb        = 0;
    maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
-   if (flags & LTM_PRIME_2MSB_ON) {
+   if ((flags & LTM_PRIME_2MSB_ON) != 0) {
       maskOR_msb       |= 0x80 >> ((9 - size) & 7);
    }  
 
    /* get the maskOR_lsb */
    maskOR_lsb         = 1;
-   if (flags & LTM_PRIME_BBS) {
+   if ((flags & LTM_PRIME_BBS) != 0) {
       maskOR_lsb     |= 3;
    }
 
@@ -95,7 +94,7 @@
          continue;
       }
 
-      if (flags & LTM_PRIME_SAFE) {
+      if ((flags & LTM_PRIME_SAFE) != 0) {
          /* see if (a-1)/2 is prime */
          if ((err = mp_sub_d(a, 1, a)) != MP_OKAY)                    { goto error; }
          if ((err = mp_div_2(a, a)) != MP_OKAY)                       { goto error; }
@@ -105,7 +104,7 @@
       }
    } while (res == MP_NO);
 
-   if (flags & LTM_PRIME_SAFE) {
+   if ((flags & LTM_PRIME_SAFE) != 0) {
       /* restore a to the original value */
       if ((err = mp_mul_2(a, a)) != MP_OKAY)                          { goto error; }
       if ((err = mp_add_d(a, 1, a)) != MP_OKAY)                       { goto error; }
@@ -120,6 +119,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_prime_random_ex.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_radix_size.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_radix_size.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_RADIX_SIZE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* returns size of ASCII reprensentation */
@@ -24,14 +24,8 @@
 
   *size = 0;
 
-  /* special case for binary */
-  if (radix == 2) {
-    *size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1;
-    return MP_OKAY;
-  }
-
   /* make sure the radix is in range */
-  if (radix < 2 || radix > 64) {
+  if ((radix < 2) || (radix > 64)) {
     return MP_VAL;
   }
 
@@ -40,6 +34,12 @@
     return MP_OKAY;
   }
 
+  /* special case for binary */
+  if (radix == 2) {
+    *size = mp_count_bits (a) + ((a->sign == MP_NEG) ? 1 : 0) + 1;
+    return MP_OKAY;
+  }
+
   /* digs is the digit count */
   digs = 0;
 
@@ -73,6 +73,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_radix_smap.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_radix_smap.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_RADIX_SMAP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,13 +12,13 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* 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 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_rand.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_rand.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_RAND_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* makes a pseudo-random int of a given size */
@@ -29,7 +29,7 @@
 
   /* first place a random non-zero digit */
   do {
-    d = ((mp_digit) abs (rand ())) & MP_MASK;
+    d = ((mp_digit) abs (MP_GEN_RANDOM())) & MP_MASK;
   } while (d == 0);
 
   if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
@@ -41,7 +41,7 @@
       return res;
     }
 
-    if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) {
+    if ((res = mp_add_d (a, ((mp_digit) abs (MP_GEN_RANDOM())), a)) != MP_OKAY) {
       return res;
     }
   }
@@ -50,6 +50,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_read_radix.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_read_radix.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_READ_RADIX_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* read a string [ASCII] in a given radix */
@@ -25,7 +25,7 @@
   mp_zero(a);
 
   /* make sure the radix is ok */
-  if (radix < 2 || radix > 64) {
+  if ((radix < 2) || (radix > 64)) {
     return MP_VAL;
   }
 
@@ -43,12 +43,12 @@
   mp_zero (a);
   
   /* process each digit of the string */
-  while (*str) {
-    /* if the radix < 36 the conversion is case insensitive
+  while (*str != '\0') {
+    /* if the radix <= 36 the conversion is case insensitive
      * this allows numbers like 1AB and 1ab to represent the same  value
      * [e.g. in hex]
      */
-    ch = (char) ((radix < 36) ? toupper (*str) : *str);
+    ch = (radix <= 36) ? (char)toupper((int)*str) : *str;
     for (y = 0; y < 64; y++) {
       if (ch == mp_s_rmap[y]) {
          break;
@@ -73,13 +73,13 @@
   }
   
   /* set the sign only if a != 0 */
-  if (mp_iszero(a) != 1) {
+  if (mp_iszero(a) != MP_YES) {
      a->sign = neg;
   }
   return MP_OKAY;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_read_signed_bin.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_read_signed_bin.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_READ_SIGNED_BIN_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
@@ -36,6 +36,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_read_unsigned_bin.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_read_unsigned_bin.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_READ_UNSIGNED_BIN_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
@@ -37,12 +37,12 @@
     }
 
 #ifndef MP_8BIT
-      a->dp[0] |= *b++;
-      a->used += 1;
+    a->dp[0] |= *b++;
+    a->used += 1;
 #else
-      a->dp[0] = (*b & MP_MASK);
-      a->dp[1] |= ((*b++ >> 7U) & 1);
-      a->used += 2;
+    a->dp[0] = (*b & MP_MASK);
+    a->dp[1] |= ((*b++ >> 7U) & 1);
+    a->used += 2;
 #endif
   }
   mp_clamp (a);
@@ -50,6 +50,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,10 +12,10 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* reduces x mod m, assumes 0 < x < m**2, mu is 
+/* reduces x mod m, assumes 0 < x < m**2, mu is
  * precomputed via mp_reduce_setup.
  * From HAC pp.604 Algorithm 14.42
  */
@@ -30,10 +30,10 @@
   }
 
   /* q1 = x / b**(k-1)  */
-  mp_rshd (&q, um - 1);         
+  mp_rshd (&q, um - 1);
 
   /* according to HAC this optimization is ok */
-  if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
+  if (((mp_digit) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
     if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) {
       goto CLEANUP;
     }
@@ -46,8 +46,8 @@
     if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
       goto CLEANUP;
     }
-#else 
-    { 
+#else
+    {
       res = MP_VAL;
       goto CLEANUP;
     }
@@ -55,7 +55,7 @@
   }
 
   /* q3 = q2 / b**(k+1) */
-  mp_rshd (&q, um + 1);         
+  mp_rshd (&q, um + 1);
 
   /* x = x mod b**(k+1), quick (no division) */
   if ((res = mp_mod_2d (x, DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
@@ -87,7 +87,7 @@
       goto CLEANUP;
     }
   }
-  
+
 CLEANUP:
   mp_clear (&q);
 
@@ -95,6 +95,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_2k.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_2k.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_2K_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* reduces a modulo n where n is of the form 2**p - d */
@@ -20,35 +20,37 @@
 {
    mp_int q;
    int    p, res;
-   
+
    if ((res = mp_init(&q)) != MP_OKAY) {
       return res;
    }
-   
-   p = mp_count_bits(n);    
+
+   p = mp_count_bits(n);
 top:
    /* q = a/2**p, a = a mod 2**p */
    if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
       goto ERR;
    }
-   
+
    if (d != 1) {
       /* q = q * d */
-      if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { 
+      if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) {
          goto ERR;
       }
    }
-   
+
    /* a = a + q */
    if ((res = s_mp_add(a, &q, a)) != MP_OKAY) {
       goto ERR;
    }
-   
+
    if (mp_cmp_mag(a, n) != MP_LT) {
-      s_mp_sub(a, n, a);
+      if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
+         goto ERR;
+      }
       goto top;
    }
-   
+
 ERR:
    mp_clear(&q);
    return res;
@@ -56,6 +58,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_2k_l.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_2k_l.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_2K_L_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,10 +12,10 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* reduces a modulo n where n is of the form 2**p - d 
+/* reduces a modulo n where n is of the form 2**p - d
    This differs from reduce_2k since "d" can be larger
    than a single digit.
 */
@@ -23,33 +23,35 @@
 {
    mp_int q;
    int    p, res;
-   
+
    if ((res = mp_init(&q)) != MP_OKAY) {
       return res;
    }
-   
-   p = mp_count_bits(n);    
+
+   p = mp_count_bits(n);
 top:
    /* q = a/2**p, a = a mod 2**p */
    if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
       goto ERR;
    }
-   
+
    /* q = q * d */
-   if ((res = mp_mul(&q, d, &q)) != MP_OKAY) { 
+   if ((res = mp_mul(&q, d, &q)) != MP_OKAY) {
       goto ERR;
    }
-   
+
    /* a = a + q */
    if ((res = s_mp_add(a, &q, a)) != MP_OKAY) {
       goto ERR;
    }
-   
+
    if (mp_cmp_mag(a, n) != MP_LT) {
-      s_mp_sub(a, n, a);
+      if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
+         goto ERR;
+      }
       goto top;
    }
-   
+
 ERR:
    mp_clear(&q);
    return res;
@@ -57,6 +59,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_l.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_2k_setup.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_2k_setup.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_2K_SETUP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines the setup value */
@@ -42,6 +42,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_2k_setup_l.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_2k_setup_l.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_2K_SETUP_L_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines the setup value */
@@ -39,6 +39,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_is_2k.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_is_2k.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_IS_2K_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines if mp_reduce_2k can be used */
@@ -47,6 +47,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_is_2k_l.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_is_2k_l.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_IS_2K_L_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* determines if reduce_2k_l can be used */
@@ -39,6 +39,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_reduce_setup.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_reduce_setup.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_REDUCE_SETUP_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* pre-calculate the value required for Barrett reduction
@@ -29,6 +29,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_rshd.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_rshd.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_RSHD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* shift right a certain amount of digits */
@@ -32,7 +32,7 @@
   }
 
   {
-    register mp_digit *bottom, *top;
+    mp_digit *bottom, *top;
 
     /* shift the digits down */
 
@@ -67,6 +67,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_set.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_set.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SET_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* set to a digit */
@@ -24,6 +24,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_set_int.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_set_int.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SET_INT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* set a 32-bit const */
@@ -43,6 +43,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_set_long.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,24 @@
+#include <tommath_private.h>
+#ifdef BN_MP_SET_LONG_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* set a platform dependent unsigned long int */
+MP_SET_XLONG(mp_set_long, unsigned long)
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_set_long_long.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,24 @@
+#include <tommath_private.h>
+#ifdef BN_MP_SET_LONG_LONG_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, [email protected], http://libtom.org
+ */
+
+/* set a platform dependent unsigned long long int */
+MP_SET_XLONG(mp_set_long_long, unsigned long long)
+#endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_shrink.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_shrink.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SHRINK_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,24 +12,30 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* shrink a bignum */
 int mp_shrink (mp_int * a)
 {
   mp_digit *tmp;
-  if (a->alloc != a->used && a->used > 0) {
-    if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * a->used)) == NULL) {
+  int used = 1;
+  
+  if(a->used > 0) {
+    used = a->used;
+  }
+  
+  if (a->alloc != used) {
+    if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * used)) == NULL) {
       return MP_MEM;
     }
     a->dp    = tmp;
-    a->alloc = a->used;
+    a->alloc = used;
   }
   return MP_OKAY;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_signed_bin_size.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_signed_bin_size.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SIGNED_BIN_SIZE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* get the size for an signed equivalent */
@@ -22,6 +22,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_sqr.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_sqr.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SQR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* computes b = a*a */
@@ -29,30 +29,32 @@
   } else 
 #endif
 #ifdef BN_MP_KARATSUBA_SQR_C
-if (a->used >= KARATSUBA_SQR_CUTOFF) {
+  if (a->used >= KARATSUBA_SQR_CUTOFF) {
     res = mp_karatsuba_sqr (a, b);
   } else 
 #endif
   {
 #ifdef BN_FAST_S_MP_SQR_C
     /* can we use the fast comba multiplier? */
-    if ((a->used * 2 + 1) < MP_WARRAY && 
-         a->used < 
-         (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) {
+    if ((((a->used * 2) + 1) < MP_WARRAY) &&
+         (a->used <
+         (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) - 1)))) {
       res = fast_s_mp_sqr (a, b);
     } else
 #endif
+    {
 #ifdef BN_S_MP_SQR_C
       res = s_mp_sqr (a, b);
 #else
       res = MP_VAL;
 #endif
+    }
   }
   b->sign = MP_ZPOS;
   return res;
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_sqrmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_sqrmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SQRMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* c = a * a (mod b) */
@@ -36,6 +36,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_sqrt.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_sqrt.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SQRT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* this function is less generic than mp_n_root, simpler and faster */
@@ -76,6 +76,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_sqrt.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/bn_mp_sqrtmod_prime.c	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,124 @@
+#include <tommath_private.h>
+#ifdef BN_MP_SQRTMOD_PRIME_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
+ *
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+/* Tonelli-Shanks algorithm
+ * https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm
+ * https://gmplib.org/list-archives/gmp-discuss/2013-April/005300.html
+ *
+ */
+
+int mp_sqrtmod_prime(mp_int *n, mp_int *prime, mp_int *ret)
+{
+  int res, legendre;
+  mp_int t1, C, Q, S, Z, M, T, R, two;
+  mp_digit i;
+
+  /* first handle the simple cases */
+  if (mp_cmp_d(n, 0) == MP_EQ) {
+    mp_zero(ret);
+    return MP_OKAY;
+  }
+  if (mp_cmp_d(prime, 2) == MP_EQ)                              return MP_VAL; /* prime must be odd */
+  if ((res = mp_jacobi(n, prime, &legendre)) != MP_OKAY)        return res;
+  if (legendre == -1)                                           return MP_VAL; /* quadratic non-residue mod prime */
+
+  if ((res = mp_init_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL)) != MP_OKAY) {
+	return res;
+  }
+
+  /* SPECIAL CASE: if prime mod 4 == 3
+   * compute directly: res = n^(prime+1)/4 mod prime
+   * Handbook of Applied Cryptography algorithm 3.36
+   */
+  if ((res = mp_mod_d(prime, 4, &i)) != MP_OKAY)                goto cleanup;
+  if (i == 3) {
+    if ((res = mp_add_d(prime, 1, &t1)) != MP_OKAY)             goto cleanup;
+    if ((res = mp_div_2(&t1, &t1)) != MP_OKAY)                  goto cleanup;
+    if ((res = mp_div_2(&t1, &t1)) != MP_OKAY)                  goto cleanup;
+    if ((res = mp_exptmod(n, &t1, prime, ret)) != MP_OKAY)      goto cleanup;
+    res = MP_OKAY;
+    goto cleanup;
+  }
+
+  /* NOW: Tonelli-Shanks algorithm */
+
+  /* factor out powers of 2 from prime-1, defining Q and S as: prime-1 = Q*2^S */
+  if ((res = mp_copy(prime, &Q)) != MP_OKAY)                    goto cleanup;
+  if ((res = mp_sub_d(&Q, 1, &Q)) != MP_OKAY)                   goto cleanup;
+  /* Q = prime - 1 */
+  mp_zero(&S);
+  /* S = 0 */
+  while (mp_iseven(&Q) != MP_NO) {
+    if ((res = mp_div_2(&Q, &Q)) != MP_OKAY)                    goto cleanup;
+    /* Q = Q / 2 */
+    if ((res = mp_add_d(&S, 1, &S)) != MP_OKAY)                 goto cleanup;
+    /* S = S + 1 */
+  }
+
+  /* find a Z such that the Legendre symbol (Z|prime) == -1 */
+  if ((res = mp_set_int(&Z, 2)) != MP_OKAY)                     goto cleanup;
+  /* Z = 2 */
+  while(1) {
+    if ((res = mp_jacobi(&Z, prime, &legendre)) != MP_OKAY)     goto cleanup;
+    if (legendre == -1) break;
+    if ((res = mp_add_d(&Z, 1, &Z)) != MP_OKAY)                 goto cleanup;
+    /* Z = Z + 1 */
+  }
+
+  if ((res = mp_exptmod(&Z, &Q, prime, &C)) != MP_OKAY)         goto cleanup;
+  /* C = Z ^ Q mod prime */
+  if ((res = mp_add_d(&Q, 1, &t1)) != MP_OKAY)                  goto cleanup;
+  if ((res = mp_div_2(&t1, &t1)) != MP_OKAY)                    goto cleanup;
+  /* t1 = (Q + 1) / 2 */
+  if ((res = mp_exptmod(n, &t1, prime, &R)) != MP_OKAY)         goto cleanup;
+  /* R = n ^ ((Q + 1) / 2) mod prime */
+  if ((res = mp_exptmod(n, &Q, prime, &T)) != MP_OKAY)          goto cleanup;
+  /* T = n ^ Q mod prime */
+  if ((res = mp_copy(&S, &M)) != MP_OKAY)                       goto cleanup;
+  /* M = S */
+  if ((res = mp_set_int(&two, 2)) != MP_OKAY)                   goto cleanup;
+
+  res = MP_VAL;
+  while (1) {
+    if ((res = mp_copy(&T, &t1)) != MP_OKAY)                    goto cleanup;
+    i = 0;
+    while (1) {
+      if (mp_cmp_d(&t1, 1) == MP_EQ) break;
+      if ((res = mp_exptmod(&t1, &two, prime, &t1)) != MP_OKAY) goto cleanup;
+      i++;
+    }
+    if (i == 0) {
+      if ((res = mp_copy(&R, ret)) != MP_OKAY)                  goto cleanup;
+      res = MP_OKAY;
+      goto cleanup;
+    }
+    if ((res = mp_sub_d(&M, i, &t1)) != MP_OKAY)                goto cleanup;
+    if ((res = mp_sub_d(&t1, 1, &t1)) != MP_OKAY)               goto cleanup;
+    if ((res = mp_exptmod(&two, &t1, prime, &t1)) != MP_OKAY)   goto cleanup;
+    /* t1 = 2 ^ (M - i - 1) */
+    if ((res = mp_exptmod(&C, &t1, prime, &t1)) != MP_OKAY)     goto cleanup;
+    /* t1 = C ^ (2 ^ (M - i - 1)) mod prime */
+    if ((res = mp_sqrmod(&t1, prime, &C)) != MP_OKAY)           goto cleanup;
+    /* C = (t1 * t1) mod prime */
+    if ((res = mp_mulmod(&R, &t1, prime, &R)) != MP_OKAY)       goto cleanup;
+    /* R = (R * t1) mod prime */
+    if ((res = mp_mulmod(&T, &C, prime, &T)) != MP_OKAY)        goto cleanup;
+    /* T = (T * C) mod prime */
+    mp_set(&M, i);
+    /* M = i */
+  }
+
+cleanup:
+  mp_clear_multi(&t1, &C, &Q, &S, &Z, &M, &T, &R, &two, NULL);
+  return res;
+}
+
+#endif
--- a/libtommath/bn_mp_sub.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_sub.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SUB_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* high level subtraction (handles signs) */
@@ -54,6 +54,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_sub.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_sub_d.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_sub_d.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SUB_D_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* single digit subtraction */
@@ -23,7 +23,7 @@
   int       res, ix, oldused;
 
   /* grow c as required */
-  if (c->alloc < a->used + 1) {
+  if (c->alloc < (a->used + 1)) {
      if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
         return res;
      }
@@ -49,7 +49,7 @@
   tmpc    = c->dp;
 
   /* if a <= b simply fix the single digit */
-  if ((a->used == 1 && a->dp[0] <= b) || a->used == 0) {
+  if (((a->used == 1) && (a->dp[0] <= b)) || (a->used == 0)) {
      if (a->used == 1) {
         *tmpc++ = b - *tmpa;
      } else {
@@ -67,13 +67,13 @@
 
      /* subtract first digit */
      *tmpc    = *tmpa++ - b;
-     mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
+     mu       = *tmpc >> ((sizeof(mp_digit) * CHAR_BIT) - 1);
      *tmpc++ &= MP_MASK;
 
      /* handle rest of the digits */
      for (ix = 1; ix < a->used; ix++) {
         *tmpc    = *tmpa++ - mu;
-        mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
+        mu       = *tmpc >> ((sizeof(mp_digit) * CHAR_BIT) - 1);
         *tmpc++ &= MP_MASK;
      }
   }
@@ -88,6 +88,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_sub_d.c,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_submod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_submod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_SUBMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* d = a - b (mod c) */
@@ -37,6 +37,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_to_signed_bin.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_to_signed_bin.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TO_SIGNED_BIN_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* store in signed [big endian] format */
@@ -23,11 +23,11 @@
   if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) {
     return res;
   }
-  b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1);
+  b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
   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 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_to_signed_bin_n.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_to_signed_bin_n.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TO_SIGNED_BIN_N_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* store in signed [big endian] format */
@@ -26,6 +26,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_to_unsigned_bin.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_to_unsigned_bin.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TO_UNSIGNED_BIN_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* store in unsigned [big endian] format */
@@ -26,7 +26,7 @@
   }
 
   x = 0;
-  while (mp_iszero (&t) == 0) {
+  while (mp_iszero (&t) == MP_NO) {
 #ifndef MP_8BIT
       b[x++] = (unsigned char) (t.dp[0] & 255);
 #else
@@ -43,6 +43,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_to_unsigned_bin_n.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_to_unsigned_bin_n.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TO_UNSIGNED_BIN_N_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* store in unsigned [big endian] format */
@@ -26,6 +26,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_toom_mul.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_toom_mul.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TOOM_MUL_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,31 +12,31 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
-/* multiplication using the Toom-Cook 3-way algorithm 
+/* multiplication using the Toom-Cook 3-way algorithm
  *
- * Much more complicated than Karatsuba but has a lower 
- * asymptotic running time of O(N**1.464).  This algorithm is 
- * only particularly useful on VERY large inputs 
+ * Much more complicated than Karatsuba but has a lower
+ * asymptotic running time of O(N**1.464).  This algorithm is
+ * only particularly useful on VERY large inputs
  * (we're talking 1000s of digits here...).
 */
 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
 {
     mp_int w0, w1, w2, w3, w4, tmp1, tmp2, a0, a1, a2, b0, b1, b2;
     int res, B;
-        
+
     /* init temps */
-    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, 
-                             &a0, &a1, &a2, &b0, &b1, 
+    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4,
+                             &a0, &a1, &a2, &b0, &b1,
                              &b2, &tmp1, &tmp2, NULL)) != MP_OKAY) {
        return res;
     }
-    
+
     /* B */
     B = MIN(a->used, b->used) / 3;
-    
+
     /* a = a2 * B**2 + a1 * B + a0 */
     if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
        goto ERR;
@@ -46,13 +46,15 @@
        goto ERR;
     }
     mp_rshd(&a1, B);
-    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
+    if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+       goto ERR;
+    }
 
     if ((res = mp_copy(a, &a2)) != MP_OKAY) {
        goto ERR;
     }
     mp_rshd(&a2, B*2);
-    
+
     /* b = b2 * B**2 + b1 * B + b0 */
     if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) {
        goto ERR;
@@ -62,23 +64,23 @@
        goto ERR;
     }
     mp_rshd(&b1, B);
-    mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
+    (void)mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
 
     if ((res = mp_copy(b, &b2)) != MP_OKAY) {
        goto ERR;
     }
     mp_rshd(&b2, B*2);
-    
+
     /* w0 = a0*b0 */
     if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     /* w4 = a2 * b2 */
     if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */
     if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
        goto ERR;
@@ -92,7 +94,7 @@
     if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) {
        goto ERR;
     }
@@ -105,11 +107,11 @@
     if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */
     if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
        goto ERR;
@@ -123,7 +125,7 @@
     if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) {
        goto ERR;
     }
@@ -136,11 +138,11 @@
     if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) {
        goto ERR;
     }
-    
+
     if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) {
        goto ERR;
     }
-    
+
 
     /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */
     if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
@@ -158,127 +160,127 @@
     if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) {
        goto ERR;
     }
-    
-    /* now solve the matrix 
-    
+
+    /* now solve the matrix
+
        0  0  0  0  1
        1  2  4  8  16
        1  1  1  1  1
        16 8  4  2  1
        1  0  0  0  0
-       
-       using 12 subtractions, 4 shifts, 
-              2 small divisions and 1 small multiplication 
+
+       using 12 subtractions, 4 shifts,
+              2 small divisions and 1 small multiplication
      */
-     
-     /* r1 - r4 */
-     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r0 */
-     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/2 */
-     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/2 */
-     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r2 - r0 - r4 */
-     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - 8r0 */
-     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - 8r4 */
-     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* 3r2 - r1 - r3 */
-     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/3 */
-     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/3 */
-     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     
-     /* at this point shift W[n] by B*n */
-     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
-        goto ERR;
-     }     
-     
-     if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) {
-        goto ERR;
-     }     
-     
+
+    /* r1 - r4 */
+    if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r0 */
+    if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1/2 */
+    if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3/2 */
+    if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r2 - r0 - r4 */
+    if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - r2 */
+    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r2 */
+    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - 8r0 */
+    if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - 8r4 */
+    if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* 3r2 - r1 - r3 */
+    if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - r2 */
+    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r2 */
+    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1/3 */
+    if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3/3 */
+    if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
+       goto ERR;
+    }
+
+    /* at this point shift W[n] by B*n */
+    if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
+       goto ERR;
+    }
+
+    if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) {
+       goto ERR;
+    }
+
 ERR:
-     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, 
-                    &a0, &a1, &a2, &b0, &b1, 
-                    &b2, &tmp1, &tmp2, NULL);
-     return res;
-}     
-     
+    mp_clear_multi(&w0, &w1, &w2, &w3, &w4,
+                   &a0, &a1, &a2, &b0, &b1,
+                   &b2, &tmp1, &tmp2, NULL);
+    return res;
+}
+
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_toom_mul.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_toom_sqr.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_toom_sqr.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TOOM_SQR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* squaring using Toom-Cook 3-way algorithm */
@@ -39,7 +39,9 @@
        goto ERR;
     }
     mp_rshd(&a1, B);
-    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
+    if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+       goto ERR;
+    }
 
     if ((res = mp_copy(a, &a2)) != MP_OKAY) {
        goto ERR;
@@ -115,112 +117,112 @@
        using 12 subtractions, 4 shifts, 2 small divisions and 1 small multiplication.
      */
 
-     /* r1 - r4 */
-     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r0 */
-     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/2 */
-     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/2 */
-     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r2 - r0 - r4 */
-     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - 8r0 */
-     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - 8r4 */
-     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* 3r2 - r1 - r3 */
-     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/3 */
-     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/3 */
-     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
+    /* r1 - r4 */
+    if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r0 */
+    if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1/2 */
+    if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3/2 */
+    if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r2 - r0 - r4 */
+    if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - r2 */
+    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r2 */
+    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - 8r0 */
+    if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - 8r4 */
+    if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* 3r2 - r1 - r3 */
+    if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1 - r2 */
+    if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3 - r2 */
+    if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r1/3 */
+    if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
+       goto ERR;
+    }
+    /* r3/3 */
+    if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
+       goto ERR;
+    }
 
-     /* at this point shift W[n] by B*n */
-     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
-        goto ERR;
-     }
+    /* at this point shift W[n] by B*n */
+    if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
+       goto ERR;
+    }
 
-     if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) {
-        goto ERR;
-     }
+    if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
+       goto ERR;
+    }
+    if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) {
+       goto ERR;
+    }
 
 ERR:
-     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
-     return res;
+    mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
+    return res;
 }
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_toradix.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_toradix.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TORADIX_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) */
@@ -24,12 +24,12 @@
   char   *_s = str;
 
   /* check range of the radix */
-  if (radix < 2 || radix > 64) {
+  if ((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;
@@ -47,7 +47,7 @@
   }
 
   digs = 0;
-  while (mp_iszero (&t) == 0) {
+  while (mp_iszero (&t) == MP_NO) {
     if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
       mp_clear (&t);
       return res;
@@ -70,6 +70,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_toradix.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_toradix_n.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_toradix_n.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_TORADIX_N_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) 
@@ -27,7 +27,7 @@
   char   *_s = str;
 
   /* check range of the maxlen, radix */
-  if (maxlen < 2 || radix < 2 || radix > 64) {
+  if ((maxlen < 2) || (radix < 2) || (radix > 64)) {
     return MP_VAL;
   }
 
@@ -56,7 +56,7 @@
   }
 
   digs = 0;
-  while (mp_iszero (&t) == 0) {
+  while (mp_iszero (&t) == MP_NO) {
     if (--maxlen < 1) {
        /* no more room */
        break;
@@ -83,6 +83,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_toradix_n.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_unsigned_bin_size.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_unsigned_bin_size.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_UNSIGNED_BIN_SIZE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -12,17 +12,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://math.libtomcrypt.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* get the size for an unsigned equivalent */
 int mp_unsigned_bin_size (mp_int * a)
 {
   int     size = mp_count_bits (a);
-  return (size / 8 + ((size & 7) != 0 ? 1 : 0));
+  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 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_xor.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_xor.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_XOR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* XOR two ints together */
@@ -46,6 +46,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_mp_zero.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_mp_zero.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_MP_ZERO_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* set to zero */
@@ -31,6 +31,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_prime_tab.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_prime_tab.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_PRIME_TAB_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 const mp_digit ltm_prime_tab[] = {
   0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
@@ -56,6 +56,6 @@
 };
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_prime_tab.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_reverse.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_reverse.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_REVERSE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* reverse an array, used for radix code */
@@ -34,6 +34,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_add.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_add.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_ADD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
@@ -36,7 +36,7 @@
   }
 
   /* init result */
-  if (c->alloc < max + 1) {
+  if (c->alloc < (max + 1)) {
     if ((res = mp_grow (c, max + 1)) != MP_OKAY) {
       return res;
     }
@@ -47,8 +47,8 @@
   c->used = max + 1;
 
   {
-    register mp_digit u, *tmpa, *tmpb, *tmpc;
-    register int i;
+    mp_digit u, *tmpa, *tmpb, *tmpc;
+    int i;
 
     /* alias for digit pointers */
 
@@ -104,6 +104,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_add.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_exptmod.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_exptmod.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_EXPTMOD_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 #ifdef MP_LOW_MEM
    #define TAB_SIZE 32
@@ -164,12 +164,12 @@
      * in the exponent.  Technically this opt is not required but it
      * does lower the # of trivial squaring/reductions used
      */
-    if (mode == 0 && y == 0) {
+    if ((mode == 0) && (y == 0)) {
       continue;
     }
 
     /* if the bit is zero and mode == 1 then we square */
-    if (mode == 1 && y == 0) {
+    if ((mode == 1) && (y == 0)) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
         goto LBL_RES;
       }
@@ -211,7 +211,7 @@
   }
 
   /* if bits remain then square/multiply */
-  if (mode == 2 && bitcpy > 0) {
+  if ((mode == 2) && (bitcpy > 0)) {
     /* square then multiply if the bit is set */
     for (x = 0; x < bitcpy; x++) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
@@ -247,6 +247,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_mul_digs.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_mul_digs.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_MUL_DIGS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* multiplies |a| * |b| and only computes upto digs digits of result
@@ -29,8 +29,8 @@
 
   /* can we use the fast multiplier? */
   if (((digs) < MP_WARRAY) &&
-      MIN (a->used, b->used) < 
-          (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
+      (MIN (a->used, b->used) < 
+          (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
     return fast_s_mp_mul_digs (a, b, c, digs);
   }
 
@@ -61,9 +61,9 @@
     /* compute the columns of the output and propagate the carry */
     for (iy = 0; iy < pb; iy++) {
       /* compute the column as a mp_word */
-      r       = ((mp_word)*tmpt) +
-                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
-                ((mp_word) u);
+      r       = (mp_word)*tmpt +
+                ((mp_word)tmpx * (mp_word)*tmpy++) +
+                (mp_word)u;
 
       /* the new column is the lower part of the result */
       *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
@@ -72,7 +72,7 @@
       u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
     }
     /* set carry if it is placed below digs */
-    if (ix + iy < digs) {
+    if ((ix + iy) < digs) {
       *tmpt = u;
     }
   }
@@ -85,6 +85,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_mul_high_digs.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_mul_high_digs.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_MUL_HIGH_DIGS_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* multiplies |a| * |b| and does not compute the lower digs digits
@@ -30,7 +30,7 @@
   /* can we use the fast multiplier? */
 #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
   if (((a->used + b->used + 1) < MP_WARRAY)
-      && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
+      && (MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
     return fast_s_mp_mul_high_digs (a, b, c, digs);
   }
 #endif
@@ -57,9 +57,9 @@
 
     for (iy = digs - ix; iy < pb; iy++) {
       /* calculate the double precision result */
-      r       = ((mp_word)*tmpt) +
-                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
-                ((mp_word) u);
+      r       = (mp_word)*tmpt +
+                ((mp_word)tmpx * (mp_word)*tmpy++) +
+                (mp_word)u;
 
       /* get the lower part */
       *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
@@ -76,6 +76,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_sqr.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_sqr.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_SQR_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
@@ -24,18 +24,18 @@
   mp_digit u, tmpx, *tmpt;
 
   pa = a->used;
-  if ((res = mp_init_size (&t, 2*pa + 1)) != MP_OKAY) {
+  if ((res = mp_init_size (&t, (2 * pa) + 1)) != MP_OKAY) {
     return res;
   }
 
   /* default used is maximum possible size */
-  t.used = 2*pa + 1;
+  t.used = (2 * pa) + 1;
 
   for (ix = 0; ix < pa; ix++) {
     /* first calculate the digit at 2*ix */
     /* calculate double precision result */
-    r = ((mp_word) t.dp[2*ix]) +
-        ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]);
+    r = (mp_word)t.dp[2*ix] +
+        ((mp_word)a->dp[ix] * (mp_word)a->dp[ix]);
 
     /* store lower part in result */
     t.dp[ix+ix] = (mp_digit) (r & ((mp_word) MP_MASK));
@@ -47,7 +47,7 @@
     tmpx        = a->dp[ix];
 
     /* alias for where to store the results */
-    tmpt        = t.dp + (2*ix + 1);
+    tmpt        = t.dp + ((2 * ix) + 1);
     
     for (iy = ix + 1; iy < pa; iy++) {
       /* first calculate the product */
@@ -79,6 +79,6 @@
 }
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bn_s_mp_sub.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bn_s_mp_sub.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BN_S_MP_SUB_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
@@ -35,8 +35,8 @@
   c->used = max;
 
   {
-    register mp_digit u, *tmpa, *tmpb, *tmpc;
-    register int i;
+    mp_digit u, *tmpa, *tmpb, *tmpc;
+    int i;
 
     /* alias for digit pointers */
     tmpa = a->dp;
@@ -47,14 +47,14 @@
     u = 0;
     for (i = 0; i < min; i++) {
       /* T[i] = A[i] - B[i] - U */
-      *tmpc = *tmpa++ - *tmpb++ - u;
+      *tmpc = (*tmpa++ - *tmpb++) - u;
 
       /* U = carry bit of T[i]
        * Note this saves performing an AND operation since
        * if a carry does occur it will propagate all the way to the
        * MSB.  As a result a single shift is enough to get the carry
        */
-      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
+      u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1));
 
       /* Clear carry from T[i] */
       *tmpc++ &= MP_MASK;
@@ -66,7 +66,7 @@
       *tmpc = *tmpa++ - u;
 
       /* U = carry bit of T[i] */
-      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
+      u = *tmpc >> ((mp_digit)((CHAR_BIT * sizeof(mp_digit)) - 1));
 
       /* Clear carry from T[i] */
       *tmpc++ &= MP_MASK;
@@ -84,6 +84,6 @@
 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bn_s_mp_sub.c,v $ */
-/* $Revision: 1.3 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/bncore.c	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/bncore.c	Sat Jun 24 22:37:14 2017 +0800
@@ -1,4 +1,4 @@
-#include <tommath.h>
+#include <tommath_private.h>
 #ifdef BNCORE_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis
  *
@@ -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.com
+ * Tom St Denis, [email protected], http://libtom.org
  */
 
 /* Known optimal configurations
@@ -31,6 +31,6 @@
         TOOM_SQR_CUTOFF      = 400; 
 #endif
 
-/* $Source: /cvs/libtom/libtommath/bncore.c,v $ */
-/* $Revision: 1.4 $ */
-/* $Date: 2006/03/31 14:18:44 $ */
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */
--- a/libtommath/booker.pl	Sat Jun 24 17:50:50 2017 +0800
+++ b/libtommath/booker.pl	Sat Jun 24 22:37:14 2017 +0800
@@ -15,7 +15,7 @@
    $graph = "";
 } else {
    $graph = ".ps";
-}   
+}
 
 open(IN,"<tommath.src") or die "Can't open source file";
 open(OUT,">tommath.tex") or die "Can't open destination file";
@@ -26,18 +26,18 @@
 while (<IN>) {
    print ".";
    if (!(++$x % 80)) { print "\n"; }
-   #update the headings 
+   #update the headings
    if (~($_ =~ /\*/)) {
-      if ($_ =~ /\\chapter{.+}/) {
+      if ($_ =~ /\\chapter\{.+}/) {
           ++$chapter;
           $section = $subsection = 0;
-      } elsif ($_ =~ /\\section{.+}/) {
+      } elsif ($_ =~ /\\section\{.+}/) {
           ++$section;
           $subsection = 0;
-      } elsif ($_ =~ /\\subsection{.+}/) {
+      } elsif ($_ =~ /\\subsection\{.+}/) {
           ++$subsection;
       }
-   }      
+   }
 
    if ($_ =~ m/MARK/) {
       @m = split(",",$_);
@@ -56,7 +56,7 @@
 while (<IN>) {
    ++$readline;
    ++$srcline;
-   
+
    if ($_ =~ m/MARK/) {
    } elsif ($_ =~ m/EXAM/ || $_ =~ m/LIST/) {
       if ($_ =~ m/EXAM/) {
@@ -64,29 +64,29 @@
       } else {
          $skipheader = 0;
       }
-      
+
       # EXAM,file
       chomp($_);
       @m = split(",",$_);
       open(SRC,"<$m[1]") or die "Error:$srcline:Can't open source file $m[1]";
-      
+
       print "$srcline:Inserting $m[1]:";
-      
+
       $line = 0;
       $tmp = $m[1];
       $tmp =~ s/_/"\\_"/ge;
       print OUT "\\vspace{+3mm}\\begin{small}\n\\hspace{-5.1mm}{\\bf File}: $tmp\n\\vspace{-3mm}\n\\begin{alltt}\n";
       $wroteline += 5;
-      
+
       if ($skipheader == 1) {
-         # scan till next end of comment, e.g. skip license 
+         # scan till next end of comment, e.g. skip license
          while (<SRC>) {
             $text[$line++] = $_;
-            last if ($_ =~ /math\.libtomcrypt\.com/);
+            last if ($_ =~ /libtom\.org/);
          }
-         <SRC>;   
+         <SRC>;
       }
-      
+
       $inline = 0;
       while (<SRC>) {
       next if ($_ =~ /\$Source/);
@@ -100,11 +100,11 @@
          $_ =~ s/}/"^}"/ge;
          $_ =~ s/\\/'\symbol{92}'/ge;
          $_ =~ s/\^/"\\"/ge;
-           
+
          printf OUT ("%03d   ", $line);
          for ($x = 0; $x < length($_); $x++) {
              print OUT chr(vec($_, $x, 8));
-             if ($x == 75) { 
+             if ($x == 75) {
                  print OUT "\n      ";
                  ++$wroteline;
              }
@@ -123,9 +123,9 @@
      $txt = $_;
      while ($txt =~ m/@\d+,[email protected]/) {
         @m = split("@",$txt);      # splits into text, one, two
-        @parms = split(",",$m[1]);  # splits one,two into two elements 
-                
-        # now search from $parms[0] down for $parms[1] 
+        @parms = split(",",$m[1]);  # splits one,two into two elements
+
+        # now search from $parms[0] down for $parms[1]
         $found1 = 0;
         $found2 = 0;
         for ($i = $parms[0]; $i < $totlines && $found1 == 0; $i++) {
@@ -134,7 +134,7 @@
               $found1 = 1;
            }
         }
-        
+
         # now search backwards
         for ($i = $parms[0] - 1; $i >= 0 && $found2 == 0; $i--) {
            if ($text[$i] =~ m/\Q$parms[1]\E/) {
@@ -142,7 +142,7 @@
               $found2 = 1;
            }
         }
-        
+
         # now use the closest match or the first if tied
         if ($found1 == 1 && $found2 == 0) {
            $found = 1;
@@ -160,8 +160,8 @@
         } else {
            $found = 0;
         }
-                      
-        # if found replace 
+
+        # if found replace
         if ($found == 1) {
            $delta = $parms[0] - $foundline;
            print "Found replacement tag for \"$parms[1]\" on line $srcline which refers to line $foundline (delta $delta)\n";
@@ -169,8 +169,8 @@
         } else {
            print "ERROR:  The tag \"$parms[1]\" on line $srcline was not found in the most recently parsed source!\n";
         }
-        
-        # remake the rest of the line 
+
+        # remake the rest of the line
         $cnt = @m;
         $txt = "";
         for ($i = 2; $i < $cnt; $i++) {
@@ -184,13 +184,13 @@
       $txt = $_;
       while ($txt =~ /~.+~/) {
          @m = split("~", $txt);
-         
+
          # word is the second position
          $word = @m[1];
          $a = $index1{$word};
          $b = $index2{$word};
          $c = $index3{$word};
-         
+
          # if chapter (a) is zero it wasn't found
          if ($a == 0) {
             print "ERROR: the tag \"$word\" on line $srcline was not found previously marked.\n";
@@ -199,7 +199,7 @@
             $str = $a;
             $str = $str . ".$b" if ($b != 0);
             $str = $str . ".$c" if ($c != 0);
-            
+
             if ($b == 0 && $c == 0) {
                # its a chapter
                if ($a <= 10) {
@@ -228,16 +228,16 @@
                   $str = "chapter " . $str;
                }
             } else {
-               $str = "section " . $str     if ($b != 0 && $c == 0);            
+               $str = "section " . $str     if ($b != 0 && $c == 0);
                $str = "sub-section " . $str if ($b != 0 && $c != 0);
             }
-            
+
             #substitute
             $_ =~ s/~\Q$word\E~/$str/;
-            
+
             print "Found replacement tag for marker \"$word\" on line $srcline which refers to $str\n";
          }
-         
+
          # remake rest of the line
          $cnt = @m;
          $txt = "";
@@ -263,3 +263,5 @@
 
 close (OUT);
 close (IN);
+
+system('perl -pli -e "s/\s*$//" tommath.tex');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtommath/callgraph.txt	Sat Jun 24 22:37:14 2017 +0800
@@ -0,0 +1,13356 @@
+BN_MP_KARATSUBA_MUL_C
++--->BN_MP_MUL_C
+|   +--->BN_MP_TOOM_MUL_C
+|   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_ZERO_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MUL_2_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ADD_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_SUB_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_DIV_2_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_MUL_2D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_MUL_D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_DIV_3_C
+|   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   +--->BN_MP_INIT_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_MUL_DIGS_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_C
++--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_INIT_C
++--->BN_MP_CLAMP_C
++--->BN_S_MP_ADD_C
+|   +--->BN_MP_GROW_C
++--->BN_MP_ADD_C
+|   +--->BN_MP_CMP_MAG_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
++--->BN_S_MP_SUB_C
+|   +--->BN_MP_GROW_C
++--->BN_MP_LSHD_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_ZERO_C
++--->BN_MP_CLEAR_C
+
+
+BN_MP_ZERO_C
+
+
+BN_MP_SET_C
++--->BN_MP_ZERO_C
+
+
+BN_MP_TO_SIGNED_BIN_C
++--->BN_MP_TO_UNSIGNED_BIN_C
+|   +--->BN_MP_INIT_COPY_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_C
+
+
+BN_S_MP_SUB_C
++--->BN_MP_GROW_C
++--->BN_MP_CLAMP_C
+
+
+BN_MP_JACOBI_C
++--->BN_MP_CMP_D_C
++--->BN_MP_INIT_COPY_C
+|   +--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
++--->BN_MP_CNT_LSB_C
++--->BN_MP_DIV_2D_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ZERO_C
+|   +--->BN_MP_MOD_2D_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_RSHD_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_EXCH_C
++--->BN_MP_MOD_C
+|   +--->BN_MP_DIV_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_SET_C
+|   |   +--->BN_MP_COUNT_BITS_C
+|   |   +--->BN_MP_ABS_C
+|   |   +--->BN_MP_MUL_2D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_C
+|   |   +--->BN_MP_SUB_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_ADD_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_MUL_D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
++--->BN_MP_CLEAR_C
+
+
+BN_MP_INIT_COPY_C
++--->BN_MP_INIT_SIZE_C
++--->BN_MP_COPY_C
+|   +--->BN_MP_GROW_C
+
+
+BN_MP_ABS_C
++--->BN_MP_COPY_C
+|   +--->BN_MP_GROW_C
+
+
+BN_MP_RADIX_SMAP_C
+
+
+BN_MP_EXCH_C
+
+
+BN_MP_EXPORT_C
++--->BN_MP_INIT_COPY_C
+|   +--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
++--->BN_MP_COUNT_BITS_C
++--->BN_MP_DIV_2D_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ZERO_C
+|   +--->BN_MP_MOD_2D_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_RSHD_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_EXCH_C
++--->BN_MP_CLEAR_C
+
+
+BN_MP_TO_UNSIGNED_BIN_N_C
++--->BN_MP_UNSIGNED_BIN_SIZE_C
+|   +--->BN_MP_COUNT_BITS_C
++--->BN_MP_TO_UNSIGNED_BIN_C
+|   +--->BN_MP_INIT_COPY_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_C
+
+
+BN_MP_TO_SIGNED_BIN_N_C
++--->BN_MP_SIGNED_BIN_SIZE_C
+|   +--->BN_MP_UNSIGNED_BIN_SIZE_C
+|   |   +--->BN_MP_COUNT_BITS_C
++--->BN_MP_TO_SIGNED_BIN_C
+|   +--->BN_MP_TO_UNSIGNED_BIN_C
+|   |   +--->BN_MP_INIT_COPY_C
+|   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_DIV_2D_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_ZERO_C
+|   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_C
+
+
+BN_MP_LCM_C
++--->BN_MP_INIT_MULTI_C
+|   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_GCD_C
+|   +--->BN_MP_ABS_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_INIT_COPY_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_CNT_LSB_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CMP_MAG_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_MUL_2D_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_CMP_MAG_C
++--->BN_MP_DIV_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ZERO_C
+|   +--->BN_MP_SET_C
+|   +--->BN_MP_COUNT_BITS_C
+|   +--->BN_MP_ABS_C
+|   +--->BN_MP_MUL_2D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CMP_C
+|   +--->BN_MP_SUB_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_MULTI_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_INIT_C
+|   +--->BN_MP_INIT_C
+|   +--->BN_MP_INIT_COPY_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   +--->BN_MP_RSHD_C
+|   +--->BN_MP_MUL_D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_MUL_C
+|   +--->BN_MP_TOOM_MUL_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_ZERO_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MUL_2_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ADD_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_SUB_C
+|   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_DIV_2_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_MUL_2D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_MUL_D_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_DIV_3_C
+|   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   +--->BN_MP_INIT_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_KARATSUBA_MUL_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ADD_C
+|   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_MUL_DIGS_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_C
++--->BN_MP_CLEAR_MULTI_C
+|   +--->BN_MP_CLEAR_C
+
+
+BN_MP_CMP_MAG_C
+
+
+BN_MP_PRIME_RABIN_MILLER_TRIALS_C
+
+
+BN_MP_MUL_2D_C
++--->BN_MP_COPY_C
+|   +--->BN_MP_GROW_C
++--->BN_MP_GROW_C
++--->BN_MP_LSHD_C
+|   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_ZERO_C
++--->BN_MP_CLAMP_C
+
+
+BN_MP_MUL_C
++--->BN_MP_TOOM_MUL_C
+|   +--->BN_MP_INIT_MULTI_C
+|   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_MOD_2D_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_ZERO_C
+|   +--->BN_MP_MUL_2_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_SUB_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_2_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_MUL_2D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_MUL_D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_3_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_CLEAR_MULTI_C
+|   |   +--->BN_MP_CLEAR_C
++--->BN_MP_KARATSUBA_MUL_C
+|   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_ADD_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_ZERO_C
+|   +--->BN_MP_CLEAR_C
++--->BN_FAST_S_MP_MUL_DIGS_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_CLAMP_C
++--->BN_S_MP_MUL_DIGS_C
+|   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_C
+
+
+BN_MP_SQR_C
++--->BN_MP_TOOM_SQR_C
+|   +--->BN_MP_INIT_MULTI_C
+|   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_MOD_2D_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_ZERO_C
+|   +--->BN_MP_MUL_2_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_SUB_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_2_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_MUL_2D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_MUL_D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_3_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   +--->BN_MP_INIT_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_CLEAR_MULTI_C
+|   |   +--->BN_MP_CLEAR_C
++--->BN_MP_KARATSUBA_SQR_C
+|   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_ADD_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   |   |   +--->BN_MP_ZERO_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_MP_CMP_MAG_C
+|   +--->BN_MP_CLEAR_C
++--->BN_FAST_S_MP_SQR_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_CLAMP_C
++--->BN_S_MP_SQR_C
+|   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_C
+
+
+BN_MP_INIT_C
+
+
+BN_MP_2EXPT_C
++--->BN_MP_ZERO_C
++--->BN_MP_GROW_C
+
+
+BN_MP_SIGNED_BIN_SIZE_C
++--->BN_MP_UNSIGNED_BIN_SIZE_C
+|   +--->BN_MP_COUNT_BITS_C
+
+
+BN_MP_OR_C
++--->BN_MP_INIT_COPY_C
+|   +--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
++--->BN_MP_CLAMP_C
++--->BN_MP_EXCH_C
++--->BN_MP_CLEAR_C
+
+
+BN_MP_MOD_C
++--->BN_MP_INIT_C
++--->BN_MP_DIV_C
+|   +--->BN_MP_CMP_MAG_C
+|   +--->BN_MP_COPY_C
+|   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_ZERO_C
+|   +--->BN_MP_INIT_MULTI_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_SET_C
+|   +--->BN_MP_COUNT_BITS_C
+|   +--->BN_MP_ABS_C
+|   +--->BN_MP_MUL_2D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_LSHD_C
+|   |   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CMP_C
+|   +--->BN_MP_SUB_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_ADD_C
+|   |   +--->BN_S_MP_ADD_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_EXCH_C
+|   +--->BN_MP_CLEAR_MULTI_C
+|   |   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_INIT_COPY_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_RSHD_C
+|   +--->BN_MP_RSHD_C
+|   +--->BN_MP_MUL_D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_CLEAR_C
++--->BN_MP_EXCH_C
++--->BN_MP_ADD_C
+|   +--->BN_S_MP_ADD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CMP_MAG_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+
+
+BN_MP_DIV_C
++--->BN_MP_CMP_MAG_C
++--->BN_MP_COPY_C
+|   +--->BN_MP_GROW_C
++--->BN_MP_ZERO_C
++--->BN_MP_INIT_MULTI_C
+|   +--->BN_MP_INIT_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_SET_C
++--->BN_MP_COUNT_BITS_C
++--->BN_MP_ABS_C
++--->BN_MP_MUL_2D_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_LSHD_C
+|   |   +--->BN_MP_RSHD_C
+|   +--->BN_MP_CLAMP_C
++--->BN_MP_CMP_C
++--->BN_MP_SUB_C
+|   +--->BN_S_MP_ADD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
++--->BN_MP_ADD_C
+|   +--->BN_S_MP_ADD_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_S_MP_SUB_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLAMP_C
++--->BN_MP_DIV_2D_C
+|   +--->BN_MP_INIT_C
+|   +--->BN_MP_MOD_2D_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CLEAR_C
+|   +--->BN_MP_RSHD_C
+|   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_EXCH_C
++--->BN_MP_EXCH_C
++--->BN_MP_CLEAR_MULTI_C
+|   +--->BN_MP_CLEAR_C
++--->BN_MP_INIT_SIZE_C
+|   +--->BN_MP_INIT_C
++--->BN_MP_INIT_C
++--->BN_MP_INIT_COPY_C
++--->BN_MP_LSHD_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_RSHD_C
++--->BN_MP_RSHD_C
++--->BN_MP_MUL_D_C
+|   +--->BN_MP_GROW_C
+|   +--->BN_MP_CLAMP_C
++--->BN_MP_CLAMP_C
++--->BN_MP_CLEAR_C
+
+
+BN_MP_INIT_SET_C
++--->BN_MP_INIT_C
++--->BN_MP_SET_C
+|   +--->BN_MP_ZERO_C
+
+
+BN_MP_PRIME_IS_PRIME_C
++--->BN_MP_CMP_D_C
++--->BN_MP_PRIME_IS_DIVISIBLE_C
+|   +--->BN_MP_MOD_D_C
+|   |   +--->BN_MP_DIV_D_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_DIV_2D_C
+|   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   +--->BN_MP_INIT_C
+|   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_INIT_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   +--->BN_MP_INIT_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_CLEAR_C
++--->BN_MP_INIT_C
++--->BN_MP_SET_C
+|   +--->BN_MP_ZERO_C
++--->BN_MP_PRIME_MILLER_RABIN_C
+|   +--->BN_MP_INIT_COPY_C
+|   |   +--->BN_MP_INIT_SIZE_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   +--->BN_MP_SUB_D_C
+|   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ADD_D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLAMP_C
+|   +--->BN_MP_CNT_LSB_C
+|   +--->BN_MP_DIV_2D_C
+|   |   +--->BN_MP_COPY_C
+|   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_ZERO_C
+|   |   +--->BN_MP_MOD_2D_C
+|   |   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_RSHD_C
+|   |   +--->BN_MP_CLAMP_C
+|   |   +--->BN_MP_EXCH_C
+|   +--->BN_MP_EXPTMOD_C
+|   |   +--->BN_MP_INVMOD_C
+|   |   |   +--->BN_FAST_MP_INVMOD_C
+|   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_MOD_C
+|   |   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   |   |   |   |   +--->BN_MP_ABS_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   +--->BN_MP_INVMOD_SLOW_C
+|   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   +--->BN_MP_MOD_C
+|   |   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   |   |   |   |   +--->BN_MP_ABS_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   |   |   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_CLEAR_C
+|   |   +--->BN_MP_ABS_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   +--->BN_MP_CLEAR_MULTI_C
+|   |   +--->BN_MP_REDUCE_IS_2K_L_C
+|   |   +--->BN_S_MP_EXPTMOD_C
+|   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   |   +--->BN_MP_REDUCE_SETUP_C
+|   |   |   |   +--->BN_MP_2EXPT_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_REDUCE_C
+|   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   +--->BN_MP_MUL_C
+|   |   |   |   |   +--->BN_MP_TOOM_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_KARATSUBA_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_S_MP_MUL_HIGH_DIGS_C
+|   |   |   |   |   +--->BN_FAST_S_MP_MUL_HIGH_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_FAST_S_MP_MUL_HIGH_DIGS_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_MUL_DIGS_C
+|   |   |   |   |   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_REDUCE_2K_SETUP_L_C
+|   |   |   |   +--->BN_MP_2EXPT_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_REDUCE_2K_L_C
+|   |   |   |   +--->BN_MP_MUL_C
+|   |   |   |   |   +--->BN_MP_TOOM_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_KARATSUBA_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_MOD_C
+|   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_SQR_C
+|   |   |   |   +--->BN_MP_TOOM_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_KARATSUBA_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_FAST_S_MP_SQR_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_MUL_C
+|   |   |   |   +--->BN_MP_TOOM_MUL_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_KARATSUBA_MUL_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_MUL_DIGS_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_EXCH_C
+|   |   +--->BN_MP_DR_IS_MODULUS_C
+|   |   +--->BN_MP_REDUCE_IS_2K_C
+|   |   |   +--->BN_MP_REDUCE_2K_C
+|   |   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   +--->BN_MP_EXPTMOD_FAST_C
+|   |   |   +--->BN_MP_COUNT_BITS_C
+|   |   |   +--->BN_MP_MONTGOMERY_SETUP_C
+|   |   |   +--->BN_FAST_MP_MONTGOMERY_REDUCE_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_MONTGOMERY_REDUCE_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_DR_SETUP_C
+|   |   |   +--->BN_MP_DR_REDUCE_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   +--->BN_MP_REDUCE_2K_SETUP_C
+|   |   |   |   +--->BN_MP_2EXPT_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_REDUCE_2K_C
+|   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
+|   |   |   |   +--->BN_MP_2EXPT_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_MULMOD_C
+|   |   |   |   +--->BN_MP_MUL_C
+|   |   |   |   |   +--->BN_MP_TOOM_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_KARATSUBA_MUL_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_FAST_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_MUL_DIGS_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_MOD_C
+|   |   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_MOD_C
+|   |   |   |   +--->BN_MP_DIV_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_MP_COPY_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   +--->BN_MP_COPY_C
+|   |   |   |   +--->BN_MP_GROW_C
+|   |   |   +--->BN_MP_SQR_C
+|   |   |   |   +--->BN_MP_TOOM_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_KARATSUBA_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   +--->BN_FAST_S_MP_SQR_C
+|   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   +--->BN_S_MP_SQR_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   +--->BN_MP_MUL_C
+|   |   |   |   +--->BN_MP_TOOM_MUL_C
+|   |   |   |   |   +--->BN_MP_INIT_MULTI_C
+|   |   |   |   |   +--->BN_MP_MOD_2D_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   +--->BN_MP_ZERO_C
+|   |   |   |   |   +--->BN_MP_MUL_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_SUB_C
+|   |   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_2_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_2D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_MUL_D_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_MP_DIV_3_C
+|   |   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   |   +--->BN_MP_EXCH_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   +--->BN_MP_KARATSUBA_MUL_C
+|   |   |   |   |   +--->BN_MP_INIT_SIZE_C
+|   |   |   |   |   +--->BN_MP_CLAMP_C
+|   |   |   |   |   +--->BN_S_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_ADD_C
+|   |   |   |   |   |   +--->BN_MP_CMP_MAG_C
+|   |   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_S_MP_SUB_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   +--->BN_MP_LSHD_C
+|   |   |   |   |   |   +--->BN_MP_GROW_C
+|   |   |   |   |   |   +--->BN_MP_RSHD_C
+|   |   |   |   |   |   |   +--->BN_MP_ZERO_C