Skip to content
Snippets Groups Projects
Commit 364fb601 authored by Matt Johnston's avatar Matt Johnston
Browse files

Update to libtommath v1.0

parent a79b6151
No related branches found
No related tags found
No related merge requests found
Showing
with 553 additions and 422 deletions
LibTomMath is hereby released into the Public Domain.
LibTomMath is licensed under DUAL licensing terms.
 
-- Tom St Denis
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]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
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]
Loading
Loading
@@ -2,88 +2,61 @@
#
#Tom St Denis
 
#version of library
VERSION=0.40
VPATH=@srcdir@
srcdir=@srcdir@
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
#for size
#CFLAGS += -Os
#x86 optimizations [should be valid for any GCC install though]
#CFLAGS += -fomit-frame-pointer
#debug
#CFLAGS += -g3
endif
CFLAGS += -I$(srcdir) -I../libtomcrypt/src/headers/ -I$(srcdir)/../libtomcrypt/src/headers/ -I../ -I$(srcdir)/../
 
#install as this user
ifndef INSTALL_GROUP
GROUP=wheel
ifeq ($V,1)
silent=
else
GROUP=$(INSTALL_GROUP)
silent=@
endif
 
ifndef INSTALL_USER
USER=root
else
USER=$(INSTALL_USER)
%.o: %.c
ifneq ($V,1)
@echo " * ${CC} $@"
endif
${silent} ${CC} -c ${CFLAGS} $^ -o $@
 
#default files to install
ifndef LIBNAME
LIBNAME=libtommath.a
endif
 
default: ${LIBNAME}
HEADERS=tommath.h tommath_class.h tommath_superclass.h
#LIBPATH-The directory for libtommath to be installed to.
#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
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
coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME) -Wl,--no-whole-archive
include makefile.include
LCOV_ARGS=--directory .
#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) $@ $(OBJECTS)
Loading
Loading
@@ -93,7 +66,7 @@ $(LIBNAME): $(OBJECTS)
#
# 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
Loading
Loading
@@ -101,11 +74,11 @@ profiled:
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
Loading
Loading
@@ -113,23 +86,30 @@ profiled_single:
$(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
Loading
Loading
@@ -139,17 +119,37 @@ docdvi: tommath.src
 
# 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
Loading
Loading
@@ -159,9 +159,11 @@ mandvi: bn.tex
#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:
Loading
Loading
@@ -171,16 +173,29 @@ clean:
-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
[![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.
This diff is collapsed.
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_ERROR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,12 +12,12 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
static const struct {
int code;
char *msg;
const char *msg;
} msgs[] = {
{ MP_OKAY, "Successful" },
{ MP_MEM, "Out of heap" },
Loading
Loading
@@ -25,7 +25,7 @@ static const struct {
};
 
/* 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;
 
Loading
Loading
@@ -42,6 +42,6 @@ char *mp_error_to_string(int code)
 
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_FAST_MP_INVMOD_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* computes the modular inverse via binary extended euclidean algorithm,
Loading
Loading
@@ -27,7 +27,7 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
int res, neg;
 
/* 2. [modified] b must be odd */
if (mp_iseven (b) == 1) {
if (mp_iseven (b) == MP_YES) {
return MP_VAL;
}
 
Loading
Loading
@@ -57,13 +57,13 @@ int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 
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;
}
Loading
Loading
@@ -75,13 +75,13 @@ top:
}
 
/* 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;
Loading
Loading
@@ -115,7 +115,7 @@ top:
}
 
/* if not zero goto step 4 */
if (mp_iszero (&u) == 0) {
if (mp_iszero (&u) == MP_NO) {
goto top;
}
 
Loading
Loading
@@ -143,6 +143,6 @@ LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* computes xR**-1 == x (mod N) via Montgomery Reduction
Loading
Loading
@@ -32,7 +32,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
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;
}
Loading
Loading
@@ -42,8 +42,8 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
* 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;
Loading
Loading
@@ -57,7 +57,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
}
 
/* 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;
}
}
Loading
Loading
@@ -72,7 +72,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
* 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
Loading
Loading
@@ -90,9 +90,9 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
* 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;
Loading
Loading
@@ -115,8 +115,8 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
* 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 */
 
Loading
Loading
@@ -126,7 +126,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
/* 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);
}
 
Loading
Loading
@@ -143,7 +143,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
/* 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));
}
 
Loading
Loading
@@ -167,6 +167,6 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
}
#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$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_FAST_S_MP_MUL_DIGS_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* Fast (comba) multiplier
Loading
Loading
@@ -35,7 +35,7 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
{
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) {
Loading
Loading
@@ -78,16 +78,16 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
 
/* 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];
}
Loading
Loading
@@ -102,6 +102,6 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
#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$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* this is a modified version of fast_s_mul_digs that only produces
Loading
Loading
@@ -75,7 +75,7 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
c->used = pa;
 
{
register mp_digit *tmpc;
mp_digit *tmpc;
 
tmpc = c->dp + digs;
for (ix = digs; ix < pa; ix++) {
Loading
Loading
@@ -93,6 +93,6 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
#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$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_FAST_S_MP_SQR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* the jist of squaring...
Loading
Loading
@@ -66,7 +66,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
* 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++) {
Loading
Loading
@@ -109,6 +109,6 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
}
#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$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_2EXPT_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* computes a = 2**b
Loading
Loading
@@ -29,12 +29,12 @@ mp_2expt (mp_int * a, int b)
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);
Loading
Loading
@@ -43,6 +43,6 @@ mp_2expt (mp_int * a, int b)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_ABS_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* b = |a|
Loading
Loading
@@ -38,6 +38,6 @@ mp_abs (mp_int * a, mp_int * b)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_ADD_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* high level addition (handles signs) */
Loading
Loading
@@ -48,6 +48,6 @@ int mp_add (mp_int * a, mp_int * b, mp_int * c)
 
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_ADD_D_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* single digit addition */
Loading
Loading
@@ -23,14 +23,14 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
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;
 
Loading
Loading
@@ -107,6 +107,6 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
 
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
/* $Revision: 1.4 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_ADDMOD_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* d = a + b (mod c) */
Loading
Loading
@@ -36,6 +36,6 @@ mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_AND_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* AND two ints together */
Loading
Loading
@@ -52,6 +52,6 @@ mp_and (mp_int * a, mp_int * b, mp_int * c)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_CLAMP_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* trim unused digits
Loading
Loading
@@ -28,7 +28,7 @@ mp_clamp (mp_int * a)
/* 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);
}
 
Loading
Loading
@@ -39,6 +39,6 @@ mp_clamp (mp_int * a)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#include "dbhelpers.h"
#ifdef BN_MP_CLEAR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
Loading
Loading
@@ -13,7 +13,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* clear one (frees) */
Loading
Loading
@@ -36,6 +36,6 @@ mp_clear (mp_int * a)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_CLEAR_MULTI_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
#include <stdarg.h>
 
Loading
Loading
@@ -29,6 +29,6 @@ void mp_clear_multi(mp_int *mp, ...)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
#include <tommath.h>
#include <tommath_private.h>
#ifdef BN_MP_CMP_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
Loading
Loading
@@ -12,7 +12,7 @@
* The library is free for all purposes without any express
* guarantee it works.
*
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
 
/* compare two ints (signed)*/
Loading
Loading
@@ -38,6 +38,6 @@ mp_cmp (mp_int * a, mp_int * b)
}
#endif
 
/* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/03/31 14:18:44 $ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment