From 98036f8f9d6591f75cbbb744ae789e53250d2459 Mon Sep 17 00:00:00 2001 From: Kevin B Kenny Date: Tue, 27 Dec 2005 17:59:37 +0000 Subject: Import of libtommath 0.37 --- libtommath/bn.pdf | Bin 340681 -> 341050 bytes libtommath/bn.tex | 2 +- libtommath/bn_mp_sub_d.c | 8 +- libtommath/bn_mp_toradix_n.c | 19 +- libtommath/booker.pl | 2 +- libtommath/changes.txt | 6 + libtommath/makefile | 19 +- libtommath/makefile.bcc | 2 +- libtommath/makefile.shared | 10 +- libtommath/poster.pdf | Bin 37805 -> 37800 bytes libtommath/pre_gen/mpi.c | 503 ++++++++++++++++++++++--------------------- libtommath/tommath.pdf | Bin 1159821 -> 1160280 bytes libtommath/tommath.src | 2 +- libtommath/tommath.tex | 232 ++++++++++---------- 14 files changed, 418 insertions(+), 387 deletions(-) diff --git a/libtommath/bn.pdf b/libtommath/bn.pdf index 0124c71..b54b602 100644 Binary files a/libtommath/bn.pdf and b/libtommath/bn.pdf differ diff --git a/libtommath/bn.tex b/libtommath/bn.tex index 8b37766..f89e200 100644 --- a/libtommath/bn.tex +++ b/libtommath/bn.tex @@ -49,7 +49,7 @@ \begin{document} \frontmatter \pagestyle{empty} -\title{LibTomMath User Manual \\ v0.36} +\title{LibTomMath User Manual \\ v0.37} \author{Tom St Denis \\ tomstdenis@iahu.ca} \maketitle This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been diff --git a/libtommath/bn_mp_sub_d.c b/libtommath/bn_mp_sub_d.c index 0b31cbe..ffeea09 100644 --- a/libtommath/bn_mp_sub_d.c +++ b/libtommath/bn_mp_sub_d.c @@ -36,6 +36,10 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) a->sign = MP_ZPOS; res = mp_add_d(a, b, c); a->sign = c->sign = MP_NEG; + + /* clamp */ + mp_clamp(c); + return res; } @@ -85,5 +89,5 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/bn_mp_sub_d.c,v $ */ -/* $Revision: 1.1.1.2 $ */ -/* $Date: 2005/09/26 16:31:56 $ */ +/* $Revision: 1.1.1.3 $ */ +/* $Date: 2005/12/27 17:59:38 $ */ diff --git a/libtommath/bn_mp_toradix_n.c b/libtommath/bn_mp_toradix_n.c index d07ba95..607a4be 100644 --- a/libtommath/bn_mp_toradix_n.c +++ b/libtommath/bn_mp_toradix_n.c @@ -27,12 +27,12 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) char *_s = str; /* check range of the maxlen, radix */ - if (maxlen < 3 || radix < 2 || radix > 64) { + if (maxlen < 2 || radix < 2 || radix > 64) { return MP_VAL; } /* quick out if its zero */ - if (mp_iszero(a) == 1) { + if (mp_iszero(a) == MP_YES) { *str++ = '0'; *str = '\0'; return MP_OKAY; @@ -57,21 +57,20 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) digs = 0; while (mp_iszero (&t) == 0) { + if (--maxlen < 1) { + /* no more room */ + break; + } if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) { mp_clear (&t); return res; } *str++ = mp_s_rmap[d]; ++digs; - - if (--maxlen == 1) { - /* no more room */ - break; - } } /* reverse the digits of the string. In this case _s points - * to the first digit [exluding the sign] of the number] + * to the first digit [exluding the sign] of the number */ bn_reverse ((unsigned char *)_s, digs); @@ -85,5 +84,5 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/bn_mp_toradix_n.c,v $ */ -/* $Revision: 1.1.1.2 $ */ -/* $Date: 2005/09/26 16:31:56 $ */ +/* $Revision: 1.1.1.3 $ */ +/* $Date: 2005/12/27 17:59:38 $ */ diff --git a/libtommath/booker.pl b/libtommath/booker.pl index f419ab4..df8b30d 100644 --- a/libtommath/booker.pl +++ b/libtommath/booker.pl @@ -221,7 +221,7 @@ while () { $str = "chapter eight"; } elsif ($a == 9) { $str = "chapter nine"; - } elsif ($a == 2) { + } elsif ($a == 10) { $str = "chapter ten"; } } else { diff --git a/libtommath/changes.txt b/libtommath/changes.txt index 4f27d63..1322d14 100644 --- a/libtommath/changes.txt +++ b/libtommath/changes.txt @@ -1,3 +1,9 @@ +November 18th, 2005 +v0.37 -- [Don Porter] reported on a TCL list [HEY SEND ME BUGREPORTS ALREADY!!!] that mp_add_d() would compute -0 with some inputs. Fixed. + -- [rinick@gmail.com] reported the makefile.bcc was messed up. Fixed. + -- [Kevin Kenny] reported some issues with mp_toradix_n(). Now it doesn't require a min of 3 chars of output. + -- Made the make command renamable. Wee + August 1st, 2005 v0.36 -- LTM_PRIME_2MSB_ON was fixed and the "OFF" flag was removed. -- [Peter LaDow] found a typo in the XREALLOC macro diff --git a/libtommath/makefile b/libtommath/makefile index a4697d4..192e842 100644 --- a/libtommath/makefile +++ b/libtommath/makefile @@ -3,10 +3,14 @@ #Tom St Denis #version of library -VERSION=0.36 +VERSION=0.37 CFLAGS += -I./ -Wall -W -Wshadow -Wsign-compare +ifndef MAKE + MAKE=make +endif + ifndef IGNORE_SPEED #for speed @@ -124,7 +128,7 @@ timing: $(LIBNAME) # makes the LTM book DVI file, requires tetex, perl and makeindex [part of tetex I think] docdvi: tommath.src - cd pics ; make + cd pics ; MAKE=${MAKE} ${MAKE} echo "hello" > tommath.ind perl booker.pl latex tommath > /dev/null @@ -141,7 +145,7 @@ poster: poster.tex docs: docdvi dvipdf tommath rm -f tommath.log tommath.aux tommath.dvi tommath.idx tommath.toc tommath.lof tommath.ind tommath.ilg - cd pics ; make clean + cd pics ; MAKE=${MAKE} ${MAKE} clean #LTM user manual mandvi: bn.tex @@ -161,10 +165,10 @@ pretty: clean: rm -f *.bat *.pdf *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test ltmtest mpitest mtest/mtest mtest/mtest.exe \ - *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.da *.dyn *.dpi tommath.tex `find -type f | grep [~] | xargs` *.lo *.la + *.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.da *.dyn *.dpi tommath.tex `find . -type f | grep [~] | xargs` *.lo *.la rm -rf .libs - cd etc ; make clean - cd pics ; make clean + cd etc ; MAKE=${MAKE} ${MAKE} clean + cd pics ; MAKE=${MAKE} ${MAKE} clean #zipup the project (take that!) no_oops: clean @@ -177,4 +181,5 @@ zipup: clean manual poster docs cd .. ; rm -rf ltm* libtommath-$(VERSION) ; mkdir libtommath-$(VERSION) ; \ cp -R ./libtommath/* ./libtommath-$(VERSION)/ ; \ tar -c libtommath-$(VERSION)/* | bzip2 -9vvc > ltm-$(VERSION).tar.bz2 ; \ - zip -9 -r ltm-$(VERSION).zip libtommath-$(VERSION)/* + zip -9 -r ltm-$(VERSION).zip libtommath-$(VERSION)/* ; \ + mv -f ltm* ~ ; rm -rf libtommath-$(VERSION) diff --git a/libtommath/makefile.bcc b/libtommath/makefile.bcc index 647c69a..67743d9 100644 --- a/libtommath/makefile.bcc +++ b/libtommath/makefile.bcc @@ -39,6 +39,6 @@ TARGET = libtommath.lib $(TARGET): $(OBJECTS) -.c.objbjbjbj: +.c.obj: $(CC) $(CFLAGS) $< $(LIB) $(TARGET) -+$@ diff --git a/libtommath/makefile.shared b/libtommath/makefile.shared index 821558c..9d2c20a 100644 --- a/libtommath/makefile.shared +++ b/libtommath/makefile.shared @@ -1,7 +1,7 @@ #Makefile for GCC # #Tom St Denis -VERSION=0:36 +VERSION=0:37 CC = libtool --mode=compile gcc @@ -80,11 +80,13 @@ bn_mp_prime_random_ex.o bn_mp_get_int.o bn_mp_sqrt.o bn_mp_is_square.o bn_mp_ini bn_mp_init_set_int.o bn_mp_invmod_slow.o bn_mp_prime_rabin_miller_trials.o \ bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o +objs: $(OBJECTS) + $(LIBNAME): $(OBJECTS) libtool --mode=link gcc *.lo -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION) - libtool --mode=link gcc *.o -o $(LIBNAME_S) - ranlib $(LIBNAME_S) - libtool --mode=install install -c $(LIBNAME) $(LIBPATH)/$@ + +install: $(LIBNAME) + libtool --mode=install install -c $(LIBNAME) $(LIBPATH)/$(LIBNAME) install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH) install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH) diff --git a/libtommath/poster.pdf b/libtommath/poster.pdf index 5a39a04..95bf4b3 100644 Binary files a/libtommath/poster.pdf and b/libtommath/poster.pdf differ diff --git a/libtommath/pre_gen/mpi.c b/libtommath/pre_gen/mpi.c index 78945ac..d915a58 100644 --- a/libtommath/pre_gen/mpi.c +++ b/libtommath/pre_gen/mpi.c @@ -44,8 +44,8 @@ char *mp_error_to_string(int code) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_error.c */ @@ -196,8 +196,8 @@ LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_fast_mp_invmod.c */ @@ -372,8 +372,8 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_fast_mp_montgomery_reduce.c */ @@ -486,8 +486,8 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_fast_s_mp_mul_digs.c */ @@ -591,8 +591,8 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_fast_s_mp_mul_high_digs.c */ @@ -709,8 +709,8 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_fast_s_mp_sqr.c */ @@ -761,8 +761,8 @@ mp_2expt (mp_int * a, int b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_2expt.c */ @@ -808,8 +808,8 @@ mp_abs (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_abs.c */ @@ -865,8 +865,8 @@ int mp_add (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_add.c */ @@ -913,6 +913,9 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c) /* fix sign */ a->sign = c->sign = MP_NEG; + /* clamp */ + mp_clamp(c); + return res; } @@ -978,8 +981,8 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_add_d.c */ @@ -1023,8 +1026,8 @@ mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_addmod.c */ @@ -1084,8 +1087,8 @@ mp_and (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_and.c */ @@ -1132,8 +1135,8 @@ mp_clamp (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_clamp.c */ @@ -1180,8 +1183,8 @@ mp_clear (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_clear.c */ @@ -1218,8 +1221,8 @@ void mp_clear_multi(mp_int *mp, ...) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_clear_multi.c */ @@ -1265,8 +1268,8 @@ mp_cmp (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_cmp.c */ @@ -1313,8 +1316,8 @@ int mp_cmp_d(mp_int * a, mp_digit b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_cmp_d.c */ @@ -1372,8 +1375,8 @@ int mp_cmp_mag (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_cmp_mag.c */ @@ -1429,8 +1432,8 @@ int mp_cnt_lsb(mp_int *a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_cnt_lsb.c */ @@ -1501,8 +1504,8 @@ mp_copy (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_copy.c */ @@ -1550,8 +1553,8 @@ mp_count_bits (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_count_bits.c */ @@ -1846,8 +1849,8 @@ LBL_Q:mp_clear (&q); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_div.c */ @@ -1918,8 +1921,8 @@ int mp_div_2(mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_div_2.c */ @@ -2019,8 +2022,8 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_div_2d.c */ @@ -2102,8 +2105,8 @@ mp_div_3 (mp_int * a, mp_int *c, mp_digit * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_div_3.c */ @@ -2216,8 +2219,8 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_div_d.c */ @@ -2263,8 +2266,8 @@ int mp_dr_is_modulus(mp_int *a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_dr_is_modulus.c */ @@ -2361,8 +2364,8 @@ top: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_dr_reduce.c */ @@ -2397,8 +2400,8 @@ void mp_dr_setup(mp_int *a, mp_digit *d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_dr_setup.c */ @@ -2435,8 +2438,8 @@ mp_exch (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_exch.c */ @@ -2496,8 +2499,8 @@ int mp_expt_d (mp_int * a, mp_digit b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_expt_d.c */ @@ -2612,8 +2615,8 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_exptmod.c */ @@ -2937,8 +2940,8 @@ LBL_M: /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_exptmod_fast.c */ @@ -3023,8 +3026,8 @@ _ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_exteuclid.c */ @@ -3094,8 +3097,8 @@ int mp_fread(mp_int *a, int radix, FILE *stream) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_fread.c */ @@ -3150,8 +3153,8 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_fwrite.c */ @@ -3267,8 +3270,8 @@ LBL_U:mp_clear (&v); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_gcd.c */ @@ -3316,8 +3319,8 @@ unsigned long mp_get_int(mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_get_int.c */ @@ -3377,8 +3380,8 @@ int mp_grow (mp_int * a, int size) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_grow.c */ @@ -3427,8 +3430,8 @@ int mp_init (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init.c */ @@ -3463,8 +3466,8 @@ int mp_init_copy (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init_copy.c */ @@ -3526,8 +3529,8 @@ int mp_init_multi(mp_int *mp, ...) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init_multi.c */ @@ -3562,8 +3565,8 @@ int mp_init_set (mp_int * a, mp_digit b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init_set.c */ @@ -3597,8 +3600,8 @@ int mp_init_set_int (mp_int * a, unsigned long b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init_set_int.c */ @@ -3649,8 +3652,8 @@ int mp_init_size (mp_int * a, int size) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_init_size.c */ @@ -3696,8 +3699,8 @@ int mp_invmod (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_invmod.c */ @@ -3875,8 +3878,8 @@ LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_invmod_slow.c */ @@ -3988,8 +3991,8 @@ ERR:mp_clear(&t); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_is_square.c */ @@ -4097,8 +4100,8 @@ LBL_A1:mp_clear (&a1); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_jacobi.c */ @@ -4268,8 +4271,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_karatsuba_mul.c */ @@ -4393,8 +4396,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_karatsuba_sqr.c */ @@ -4457,8 +4460,8 @@ LBL_T: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_lcm.c */ @@ -4528,8 +4531,8 @@ int mp_lshd (mp_int * a, int b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_lshd.c */ @@ -4580,8 +4583,8 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mod.c */ @@ -4639,8 +4642,8 @@ mp_mod_2d (mp_int * a, int b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mod_2d.c */ @@ -4670,8 +4673,8 @@ mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mod_d.c */ @@ -4733,8 +4736,8 @@ int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_montgomery_calc_normalization.c */ @@ -4855,8 +4858,8 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_montgomery_reduce.c */ @@ -4918,8 +4921,8 @@ mp_montgomery_setup (mp_int * n, mp_digit * rho) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_montgomery_setup.c */ @@ -4988,8 +4991,8 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mul.c */ @@ -5074,8 +5077,8 @@ int mp_mul_2(mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mul_2.c */ @@ -5163,8 +5166,8 @@ int mp_mul_2d (mp_int * a, int b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mul_2d.c */ @@ -5246,8 +5249,8 @@ mp_mul_d (mp_int * a, mp_digit b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mul_d.c */ @@ -5290,8 +5293,8 @@ int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_mulmod.c */ @@ -5426,8 +5429,8 @@ LBL_T1:mp_clear (&t1); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_n_root.c */ @@ -5470,8 +5473,8 @@ int mp_neg (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_neg.c */ @@ -5524,8 +5527,8 @@ int mp_or (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_or.c */ @@ -5590,8 +5593,8 @@ LBL_T:mp_clear (&t); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_fermat.c */ @@ -5644,8 +5647,8 @@ int mp_prime_is_divisible (mp_int * a, int *result) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_is_divisible.c */ @@ -5731,8 +5734,8 @@ LBL_B:mp_clear (&b); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_is_prime.c */ @@ -5838,8 +5841,8 @@ LBL_N1:mp_clear (&n1); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_miller_rabin.c */ @@ -6012,8 +6015,8 @@ LBL_ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_next_prime.c */ @@ -6068,8 +6071,8 @@ int mp_prime_rabin_miller_trials(int size) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_rabin_miller_trials.c */ @@ -6197,8 +6200,8 @@ error: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_prime_random_ex.c */ @@ -6241,7 +6244,7 @@ int mp_radix_size (mp_int * a, int radix, int *size) } if (mp_iszero(a) == MP_YES) { - *size = 2; + *size = 2; return MP_OKAY; } @@ -6279,8 +6282,8 @@ int mp_radix_size (mp_int * a, int radix, int *size) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_radix_size.c */ @@ -6307,8 +6310,8 @@ const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_radix_smap.c */ @@ -6366,8 +6369,8 @@ mp_rand (mp_int * a, int digits) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_rand.c */ @@ -6395,6 +6398,9 @@ int mp_read_radix (mp_int * a, const char *str, int radix) int y, res, neg; char ch; + /* zero the digit bignum */ + mp_zero(a); + /* make sure the radix is ok */ if (radix < 2 || radix > 64) { return MP_VAL; @@ -6452,8 +6458,8 @@ int mp_read_radix (mp_int * a, const char *str, int radix) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_read_radix.c */ @@ -6497,8 +6503,8 @@ int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_read_signed_bin.c */ @@ -6556,8 +6562,8 @@ int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_read_unsigned_bin.c */ @@ -6660,8 +6666,8 @@ CLEANUP: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce.c */ @@ -6725,8 +6731,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_2k.c */ @@ -6791,8 +6797,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_2k_l.c */ @@ -6842,8 +6848,8 @@ int mp_reduce_2k_setup(mp_int *a, mp_digit *d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_2k_setup.c */ @@ -6890,8 +6896,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_2k_setup_l.c */ @@ -6946,8 +6952,8 @@ int mp_reduce_is_2k(mp_int *a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_is_2k.c */ @@ -6994,8 +7000,8 @@ int mp_reduce_is_2k_l(mp_int *a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_is_2k_l.c */ @@ -7032,8 +7038,8 @@ int mp_reduce_setup (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_reduce_setup.c */ @@ -7108,8 +7114,8 @@ void mp_rshd (mp_int * a, int b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_rshd.c */ @@ -7141,8 +7147,8 @@ void mp_set (mp_int * a, mp_digit b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_set.c */ @@ -7193,8 +7199,8 @@ int mp_set_int (mp_int * a, unsigned long b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_set_int.c */ @@ -7232,8 +7238,8 @@ int mp_shrink (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_shrink.c */ @@ -7263,8 +7269,8 @@ int mp_signed_bin_size (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_signed_bin_size.c */ @@ -7325,8 +7331,8 @@ if (a->used >= KARATSUBA_SQR_CUTOFF) { #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_sqr.c */ @@ -7370,8 +7376,8 @@ mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_sqrmod.c */ @@ -7455,8 +7461,8 @@ E2: mp_clear(&t1); #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_sqrt.c */ @@ -7518,8 +7524,8 @@ mp_sub (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_sub.c */ @@ -7562,6 +7568,10 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) a->sign = MP_ZPOS; res = mp_add_d(a, b, c); a->sign = c->sign = MP_NEG; + + /* clamp */ + mp_clamp(c); + return res; } @@ -7611,8 +7621,8 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_sub_d.c */ @@ -7657,8 +7667,8 @@ mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_submod.c */ @@ -7694,8 +7704,8 @@ int mp_to_signed_bin (mp_int * a, unsigned char *b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_to_signed_bin.c */ @@ -7729,8 +7739,8 @@ int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_to_signed_bin_n.c */ @@ -7781,8 +7791,8 @@ int mp_to_unsigned_bin (mp_int * a, unsigned char *b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_to_unsigned_bin.c */ @@ -7816,8 +7826,8 @@ int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_to_unsigned_bin_n.c */ @@ -8104,8 +8114,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_toom_mul.c */ @@ -8334,8 +8344,8 @@ ERR: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_toom_sqr.c */ @@ -8413,8 +8423,8 @@ int mp_toradix (mp_int * a, char *str, int radix) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_toradix.c */ @@ -8448,12 +8458,12 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) char *_s = str; /* check range of the maxlen, radix */ - if (maxlen < 3 || radix < 2 || radix > 64) { + if (maxlen < 2 || radix < 2 || radix > 64) { return MP_VAL; } /* quick out if its zero */ - if (mp_iszero(a) == 1) { + if (mp_iszero(a) == MP_YES) { *str++ = '0'; *str = '\0'; return MP_OKAY; @@ -8478,21 +8488,20 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) digs = 0; while (mp_iszero (&t) == 0) { + if (--maxlen < 1) { + /* no more room */ + break; + } if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) { mp_clear (&t); return res; } *str++ = mp_s_rmap[d]; ++digs; - - if (--maxlen == 1) { - /* no more room */ - break; - } } /* reverse the digits of the string. In this case _s points - * to the first digit [exluding the sign] of the number] + * to the first digit [exluding the sign] of the number */ bn_reverse ((unsigned char *)_s, digs); @@ -8506,8 +8515,8 @@ int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_toradix_n.c */ @@ -8538,8 +8547,8 @@ int mp_unsigned_bin_size (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_unsigned_bin_size.c */ @@ -8593,8 +8602,8 @@ mp_xor (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_xor.c */ @@ -8633,8 +8642,8 @@ void mp_zero (mp_int * a) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_mp_zero.c */ @@ -8698,8 +8707,8 @@ const mp_digit ltm_prime_tab[] = { #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_prime_tab.c */ @@ -8741,8 +8750,8 @@ bn_reverse (unsigned char *s, int len) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_reverse.c */ @@ -8854,8 +8863,8 @@ s_mp_add (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_add.c */ @@ -9110,8 +9119,8 @@ LBL_M: #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_exptmod.c */ @@ -9204,8 +9213,8 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_mul_digs.c */ @@ -9289,8 +9298,8 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_mul_high_digs.c */ @@ -9377,8 +9386,8 @@ int s_mp_sqr (mp_int * a, mp_int * b) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_sqr.c */ @@ -9470,8 +9479,8 @@ s_mp_sub (mp_int * a, mp_int * b, mp_int * c) #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bn_s_mp_sub.c */ @@ -9510,8 +9519,8 @@ int KARATSUBA_MUL_CUTOFF = 80, /* Min. number of digits before Karatsub #endif /* $Source: /root/tcl/repos-to-convert/tcl/libtommath/pre_gen/mpi.c,v $ */ -/* $Revision: 1.1.1.3 $ */ -/* $Date: 2005/09/26 16:32:22 $ */ +/* $Revision: 1.1.1.4 $ */ +/* $Date: 2005/12/27 18:00:26 $ */ /* End: bncore.c */ diff --git a/libtommath/tommath.pdf b/libtommath/tommath.pdf index 71ddffe..5c314f5 100644 Binary files a/libtommath/tommath.pdf and b/libtommath/tommath.pdf differ diff --git a/libtommath/tommath.src b/libtommath/tommath.src index b392ead..8e03635 100644 --- a/libtommath/tommath.src +++ b/libtommath/tommath.src @@ -66,7 +66,7 @@ QUALCOMM Australia \\ } } \maketitle -This text has been placed in the public domain. This text corresponds to the v0.36 release of the +This text has been placed in the public domain. This text corresponds to the v0.37 release of the LibTomMath project. \begin{alltt} diff --git a/libtommath/tommath.tex b/libtommath/tommath.tex index b69421b..a852a8d 100644 --- a/libtommath/tommath.tex +++ b/libtommath/tommath.tex @@ -66,7 +66,7 @@ QUALCOMM Australia \\ } } \maketitle -This text has been placed in the public domain. This text corresponds to the v0.36 release of the +This text has been placed in the public domain. This text corresponds to the v0.37 release of the LibTomMath project. \begin{alltt} @@ -8808,70 +8808,73 @@ This algorithm initiates a temporary mp\_int with the value of the single digit 039 /* fix sign */ 040 a->sign = c->sign = MP_NEG; 041 -042 return res; -043 \} +042 /* clamp */ +043 mp_clamp(c); 044 -045 /* old number of used digits in c */ -046 oldused = c->used; +045 return res; +046 \} 047 -048 /* sign always positive */ -049 c->sign = MP_ZPOS; +048 /* old number of used digits in c */ +049 oldused = c->used; 050 -051 /* source alias */ -052 tmpa = a->dp; +051 /* sign always positive */ +052 c->sign = MP_ZPOS; 053 -054 /* destination alias */ -055 tmpc = c->dp; +054 /* source alias */ +055 tmpa = a->dp; 056 -057 /* if a is positive */ -058 if (a->sign == MP_ZPOS) \{ -059 /* add digit, after this we're propagating -060 * the carry. -061 */ -062 *tmpc = *tmpa++ + b; -063 mu = *tmpc >> DIGIT_BIT; -064 *tmpc++ &= MP_MASK; -065 -066 /* now handle rest of the digits */ -067 for (ix = 1; ix < a->used; ix++) \{ -068 *tmpc = *tmpa++ + mu; -069 mu = *tmpc >> DIGIT_BIT; -070 *tmpc++ &= MP_MASK; -071 \} -072 /* set final carry */ -073 ix++; -074 *tmpc++ = mu; -075 -076 /* setup size */ -077 c->used = a->used + 1; -078 \} else \{ -079 /* a was negative and |a| < b */ -080 c->used = 1; -081 -082 /* the result is a single digit */ -083 if (a->used == 1) \{ -084 *tmpc++ = b - a->dp[0]; -085 \} else \{ -086 *tmpc++ = b; -087 \} -088 -089 /* setup count so the clearing of oldused -090 * can fall through correctly -091 */ -092 ix = 1; -093 \} -094 -095 /* now zero to oldused */ -096 while (ix++ < oldused) \{ -097 *tmpc++ = 0; -098 \} -099 mp_clamp(c); -100 -101 return MP_OKAY; -102 \} +057 /* destination alias */ +058 tmpc = c->dp; +059 +060 /* if a is positive */ +061 if (a->sign == MP_ZPOS) \{ +062 /* add digit, after this we're propagating +063 * the carry. +064 */ +065 *tmpc = *tmpa++ + b; +066 mu = *tmpc >> DIGIT_BIT; +067 *tmpc++ &= MP_MASK; +068 +069 /* now handle rest of the digits */ +070 for (ix = 1; ix < a->used; ix++) \{ +071 *tmpc = *tmpa++ + mu; +072 mu = *tmpc >> DIGIT_BIT; +073 *tmpc++ &= MP_MASK; +074 \} +075 /* set final carry */ +076 ix++; +077 *tmpc++ = mu; +078 +079 /* setup size */ +080 c->used = a->used + 1; +081 \} else \{ +082 /* a was negative and |a| < b */ +083 c->used = 1; +084 +085 /* the result is a single digit */ +086 if (a->used == 1) \{ +087 *tmpc++ = b - a->dp[0]; +088 \} else \{ +089 *tmpc++ = b; +090 \} +091 +092 /* setup count so the clearing of oldused +093 * can fall through correctly +094 */ +095 ix = 1; +096 \} +097 +098 /* now zero to oldused */ +099 while (ix++ < oldused) \{ +100 *tmpc++ = 0; +101 \} +102 mp_clamp(c); 103 -104 #endif -105 +104 return MP_OKAY; +105 \} +106 +107 #endif +108 \end{alltt} \end{small} @@ -9481,62 +9484,65 @@ as part of larger input without any significant problem. 020 int y, res, neg; 021 char ch; 022 -023 /* make sure the radix is ok */ -024 if (radix < 2 || radix > 64) \{ -025 return MP_VAL; -026 \} -027 -028 /* if the leading digit is a -029 * minus set the sign to negative. -030 */ -031 if (*str == '-') \{ -032 ++str; -033 neg = MP_NEG; -034 \} else \{ -035 neg = MP_ZPOS; -036 \} -037 -038 /* set the integer to the default of zero */ -039 mp_zero (a); -040 -041 /* process each digit of the string */ -042 while (*str) \{ -043 /* if the radix < 36 the conversion is case insensitive -044 * this allows numbers like 1AB and 1ab to represent the same value -045 * [e.g. in hex] -046 */ -047 ch = (char) ((radix < 36) ? toupper (*str) : *str); -048 for (y = 0; y < 64; y++) \{ -049 if (ch == mp_s_rmap[y]) \{ -050 break; -051 \} -052 \} -053 -054 /* if the char was found in the map -055 * and is less than the given radix add it -056 * to the number, otherwise exit the loop. -057 */ -058 if (y < radix) \{ -059 if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) \{ -060 return res; -061 \} -062 if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) \{ +023 /* zero the digit bignum */ +024 mp_zero(a); +025 +026 /* make sure the radix is ok */ +027 if (radix < 2 || radix > 64) \{ +028 return MP_VAL; +029 \} +030 +031 /* if the leading digit is a +032 * minus set the sign to negative. +033 */ +034 if (*str == '-') \{ +035 ++str; +036 neg = MP_NEG; +037 \} else \{ +038 neg = MP_ZPOS; +039 \} +040 +041 /* set the integer to the default of zero */ +042 mp_zero (a); +043 +044 /* process each digit of the string */ +045 while (*str) \{ +046 /* if the radix < 36 the conversion is case insensitive +047 * this allows numbers like 1AB and 1ab to represent the same value +048 * [e.g. in hex] +049 */ +050 ch = (char) ((radix < 36) ? toupper (*str) : *str); +051 for (y = 0; y < 64; y++) \{ +052 if (ch == mp_s_rmap[y]) \{ +053 break; +054 \} +055 \} +056 +057 /* if the char was found in the map +058 * and is less than the given radix add it +059 * to the number, otherwise exit the loop. +060 */ +061 if (y < radix) \{ +062 if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) \{ 063 return res; 064 \} -065 \} else \{ -066 break; -067 \} -068 ++str; -069 \} -070 -071 /* set the sign only if a != 0 */ -072 if (mp_iszero(a) != 1) \{ -073 a->sign = neg; -074 \} -075 return MP_OKAY; -076 \} -077 #endif -078 +065 if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) \{ +066 return res; +067 \} +068 \} else \{ +069 break; +070 \} +071 ++str; +072 \} +073 +074 /* set the sign only if a != 0 */ +075 if (mp_iszero(a) != 1) \{ +076 a->sign = neg; +077 \} +078 return MP_OKAY; +079 \} +080 #endif +081 \end{alltt} \end{small} -- cgit v0.12