commit
c63799c392
@ -90,6 +90,9 @@ matrix:
|
||||
- libc6-dev-i386
|
||||
- gcc-multilib
|
||||
|
||||
# RSA superclass with tests (no sanitizer, but debug info)
|
||||
- env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --cflags=-DLTM_NOTHING --cflags=-DSC_RSA_1_WITH_TESTS --with-travis-valgrind'
|
||||
|
||||
# Test "autotuning", the automatic evaluation and setting of the Toom-Cook cut-offs.
|
||||
#- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_8BIT --with-travis-valgrind --make-option=tune'
|
||||
#- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-travis-valgrind --make-option=tune'
|
||||
|
@ -121,7 +121,7 @@ static mp_err s_read_urandom(void *p, size_t n)
|
||||
#endif
|
||||
|
||||
#if defined(MP_PRNG_ENABLE_LTM_RNG)
|
||||
#define B_S_READ_LTM_RNG
|
||||
#define BN_S_READ_LTM_RNG
|
||||
unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
||||
void (*ltm_rng_callback)(void);
|
||||
|
||||
|
@ -35,9 +35,11 @@ int mtest_opponent(void)
|
||||
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
|
||||
sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = add_d_n = sub_d_n = 0;
|
||||
|
||||
#ifndef MP_FIXED_CUTOFFS
|
||||
/* force KARA and TOOM to enable despite cutoffs */
|
||||
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
|
||||
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
|
||||
|
121
demo/test.c
121
demo/test.c
@ -1,3 +1,4 @@
|
||||
#include <inttypes.h>
|
||||
#include "shared.h"
|
||||
|
||||
static long rand_long(void)
|
||||
@ -976,7 +977,7 @@ static int test_mp_prime_is_prime(void)
|
||||
printf("A certified prime is a prime but mp_prime_is_prime says it is not.\n");
|
||||
}
|
||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||
printf("prime tested was: ");
|
||||
printf("prime tested was: 0x");
|
||||
mp_fwrite(&a,16,stdout);
|
||||
putchar('\n');
|
||||
goto LBL_ERR;
|
||||
@ -1010,10 +1011,10 @@ static int test_mp_prime_is_prime(void)
|
||||
printf("\nfrobenius-underwood says sub is not prime!\n");
|
||||
}
|
||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||
printf("prime tested was: ");
|
||||
printf("prime tested was: 0x");
|
||||
mp_fwrite(&a,16,stdout);
|
||||
putchar('\n');
|
||||
printf("sub tested was: ");
|
||||
printf("sub tested was: 0x");
|
||||
mp_fwrite(&b,16,stdout);
|
||||
putchar('\n');
|
||||
goto LBL_ERR;
|
||||
@ -1035,7 +1036,7 @@ static int test_mp_prime_is_prime(void)
|
||||
printf("\n\nissue #143 - mp_prime_strong_lucas_selfridge FAILED!\n");
|
||||
}
|
||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||
printf("prime tested was: ");
|
||||
printf("prime tested was: 0x");
|
||||
mp_fwrite(&a,16,stdout);
|
||||
putchar('\n');
|
||||
goto LBL_ERR;
|
||||
@ -2219,54 +2220,62 @@ int unit_tests(int argc, char **argv)
|
||||
const char *name;
|
||||
int (*fn)(void);
|
||||
} test[] = {
|
||||
#define T(n) { #n, test_##n }
|
||||
T(feature_detection),
|
||||
T(trivial_stuff),
|
||||
T(mp_get_set_i32),
|
||||
T(mp_get_set_i64),
|
||||
T(mp_and),
|
||||
T(mp_cnt_lsb),
|
||||
T(mp_complement),
|
||||
T(mp_decr),
|
||||
T(mp_div_3),
|
||||
T(mp_dr_reduce),
|
||||
T(mp_fread_fwrite),
|
||||
T(mp_get_u32),
|
||||
T(mp_get_u64),
|
||||
T(mp_get_ul),
|
||||
T(mp_ilogb),
|
||||
T(mp_incr),
|
||||
T(mp_invmod),
|
||||
T(mp_is_square),
|
||||
T(mp_kronecker),
|
||||
T(mp_montgomery_reduce),
|
||||
T(mp_root_u32),
|
||||
T(mp_or),
|
||||
T(mp_prime_is_prime),
|
||||
T(mp_prime_next_prime),
|
||||
T(mp_prime_rand),
|
||||
T(mp_rand),
|
||||
T(mp_read_radix),
|
||||
T(mp_reduce_2k),
|
||||
T(mp_reduce_2k_l),
|
||||
#define T0(n) { #n, test_##n }
|
||||
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
|
||||
#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
|
||||
T0(feature_detection),
|
||||
T0(trivial_stuff),
|
||||
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
|
||||
T2(mp_get_set_i64, MP_GET_I64, MP_GET_MAG_U64),
|
||||
T1(mp_and, MP_AND),
|
||||
T1(mp_cnt_lsb, MP_CNT_LSB),
|
||||
T1(mp_complement, MP_COMPLEMENT),
|
||||
T1(mp_decr, MP_DECR),
|
||||
T1(mp_div_3, MP_DIV_3),
|
||||
T1(mp_dr_reduce, MP_DR_REDUCE),
|
||||
T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
|
||||
T1(mp_get_u32, MP_GET_I32),
|
||||
T1(mp_get_u64, MP_GET_I64),
|
||||
T1(mp_get_ul, MP_GET_L),
|
||||
T1(mp_ilogb, MP_ILOGB),
|
||||
T1(mp_incr, MP_INCR),
|
||||
T1(mp_invmod, MP_INVMOD),
|
||||
T1(mp_is_square, MP_IS_SQUARE),
|
||||
T1(mp_kronecker, MP_KRONECKER),
|
||||
T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
|
||||
T1(mp_root_u32, MP_ROOT_U32),
|
||||
T1(mp_or, MP_OR),
|
||||
T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
|
||||
T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
|
||||
T1(mp_prime_rand, MP_PRIME_RAND),
|
||||
T1(mp_rand, MP_RAND),
|
||||
T1(mp_read_radix, MP_READ_RADIX),
|
||||
T1(mp_reduce_2k, MP_REDUCE_2K),
|
||||
T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
|
||||
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
|
||||
T(mp_set_double),
|
||||
T1(mp_set_double, MP_SET_DOUBLE),
|
||||
#endif
|
||||
T(mp_signed_rsh),
|
||||
T(mp_sqrt),
|
||||
T(mp_sqrtmod_prime),
|
||||
T(mp_xor),
|
||||
T(s_mp_balance_mul),
|
||||
T(s_mp_karatsuba_mul),
|
||||
T(s_mp_karatsuba_sqr),
|
||||
T(s_mp_toom_mul),
|
||||
T(s_mp_toom_sqr)
|
||||
#undef T
|
||||
T1(mp_signed_rsh, MP_SIGNED_RSH),
|
||||
T1(mp_sqrt, MP_SQRT),
|
||||
T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
|
||||
T1(mp_xor, MP_XOR),
|
||||
T1(s_mp_balance_mul, S_MP_BALANCE_MUL),
|
||||
T1(s_mp_karatsuba_mul, S_MP_KARATSUBA_MUL),
|
||||
T1(s_mp_karatsuba_sqr, S_MP_KARATSUBA_SQR),
|
||||
T1(s_mp_toom_mul, S_MP_TOOM_MUL),
|
||||
T1(s_mp_toom_sqr, S_MP_TOOM_SQR),
|
||||
#undef T2
|
||||
#undef T1
|
||||
};
|
||||
unsigned long i;
|
||||
int res = EXIT_SUCCESS, j;
|
||||
unsigned long i, ok, fail, nop;
|
||||
uint64_t t;
|
||||
int j;
|
||||
|
||||
s_mp_rand_jenkins_init((uint64_t)time(NULL));
|
||||
ok = fail = nop = 0;
|
||||
|
||||
t = (uint64_t)time(NULL);
|
||||
printf("SEED: 0x%"PRIx64"\n\n", t);
|
||||
s_mp_rand_jenkins_init(t);
|
||||
mp_rand_source(s_mp_rand_jenkins);
|
||||
|
||||
for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
|
||||
@ -2279,13 +2288,19 @@ int unit_tests(int argc, char **argv)
|
||||
if (j == argc) continue;
|
||||
}
|
||||
printf("TEST %s\n\n", test[i].name);
|
||||
if (test[i].fn() != EXIT_SUCCESS) {
|
||||
if (test[i].fn == NULL) {
|
||||
nop++;
|
||||
printf("NOP %s\n\n", test[i].name);
|
||||
} else if (test[i].fn() == EXIT_SUCCESS) {
|
||||
ok++;
|
||||
printf("\n\n");
|
||||
} else {
|
||||
fail++;
|
||||
printf("\n\nFAIL %s\n\n", test[i].name);
|
||||
res = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
printf("Tests OK/NOP/FAIL: %lu/%lu/%lu\n", ok, nop, fail);
|
||||
|
||||
return res;
|
||||
if (fail != 0) return EXIT_FAILURE;
|
||||
else return EXIT_SUCCESS;
|
||||
}
|
||||
|
17
etc/makefile
17
etc/makefile
@ -1,4 +1,5 @@
|
||||
CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
|
||||
LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
|
||||
LTM_CFLAGS += $(CFLAGS)
|
||||
|
||||
# default lib name (requires install with root)
|
||||
# LIBNAME=-ltommath
|
||||
@ -8,31 +9,31 @@ LIBNAME=../libtommath.a
|
||||
|
||||
#provable primes
|
||||
pprime: pprime.o
|
||||
$(CC) $(CFLAGS) pprime.o $(LIBNAME) -o pprime
|
||||
$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
|
||||
|
||||
# portable [well requires clock()] tuning app
|
||||
tune: tune.o
|
||||
$(CC) $(CFLAGS) tune.o $(LIBNAME) -o tune
|
||||
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
|
||||
./tune_it.sh
|
||||
|
||||
test_standalone: tune.o
|
||||
# The benchmark program works as a testtool, too
|
||||
$(CC) $(CFLAGS) tune.o $(LIBNAME) -o test
|
||||
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
|
||||
|
||||
# spits out mersenne primes
|
||||
mersenne: mersenne.o
|
||||
$(CC) $(CFLAGS) mersenne.o $(LIBNAME) -o mersenne
|
||||
$(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
|
||||
|
||||
# finds DR safe primes for the given config
|
||||
drprime: drprime.o
|
||||
$(CC) $(CFLAGS) drprime.o $(LIBNAME) -o drprime
|
||||
$(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
|
||||
|
||||
# finds 2k safe primes for the given config
|
||||
2kprime: 2kprime.o
|
||||
$(CC) $(CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
|
||||
$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
|
||||
|
||||
mont: mont.o
|
||||
$(CC) $(CFLAGS) mont.o $(LIBNAME) -o mont
|
||||
$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
|
||||
|
||||
|
||||
clean:
|
||||
|
@ -381,7 +381,7 @@ EOS
|
||||
# scan for mp_* and make classes
|
||||
my @deps = ();
|
||||
foreach my $line (split /\n/, $content) {
|
||||
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*(?=\()|(?<=\()mp\_[a-z_0-9]*(?=,)/g) {
|
||||
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*((?=\;)|(?=\())|(?<=\()mp\_[a-z_0-9]*(?=\()/g) {
|
||||
my $a = $&;
|
||||
next if $a eq "mp_err";
|
||||
$a =~ tr/[a-z]/[A-Z]/;
|
||||
|
25
makefile
25
makefile
@ -17,11 +17,11 @@ coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME) -Wl,--no-whole-archive
|
||||
|
||||
include makefile_include.mk
|
||||
|
||||
%.o: %.c
|
||||
%.o: %.c $(HEADERS)
|
||||
ifneq ($V,1)
|
||||
@echo " * ${CC} $@"
|
||||
endif
|
||||
${silent} ${CC} -c ${CFLAGS} $< -o $@
|
||||
${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@
|
||||
|
||||
LCOV_ARGS=--directory .
|
||||
|
||||
@ -58,8 +58,6 @@ bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_s
|
||||
|
||||
#END_INS
|
||||
|
||||
$(OBJECTS): $(HEADERS)
|
||||
|
||||
$(LIBNAME): $(OBJECTS)
|
||||
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
||||
$(RANLIB) $@
|
||||
@ -79,11 +77,11 @@ profiled:
|
||||
#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 -lgcov -o timing
|
||||
$(CC) $(LTM_CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
|
||||
$(CC) $(LTM_CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
|
||||
./timing
|
||||
rm -f *.o timing
|
||||
$(CC) $(CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
|
||||
$(CC) $(LTM_CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
|
||||
$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
|
||||
ranlib $(LIBNAME)
|
||||
|
||||
@ -97,21 +95,18 @@ uninstall:
|
||||
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
|
||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||
|
||||
test: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o test
|
||||
|
||||
test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o test
|
||||
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
$(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test
|
||||
|
||||
.PHONY: mtest
|
||||
mtest:
|
||||
cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LFLAGS) -o mtest
|
||||
cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LFLAGS) -o mtest
|
||||
|
||||
timing: $(LIBNAME) demo/timing.c
|
||||
$(CC) $(CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LFLAGS) -o timing
|
||||
$(CC) $(LTM_CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LTM_LFLAGS) -o timing
|
||||
|
||||
tune: $(LIBNAME)
|
||||
$(MAKE) -C etc tune
|
||||
$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
|
||||
$(MAKE)
|
||||
|
||||
# You have to create a file .coveralls.yml with the content "repo_token: <the token>"
|
||||
|
@ -57,13 +57,13 @@ bn_s_mp_sqr.o bn_s_mp_sqr_fast.o bn_s_mp_sub.o bn_s_mp_toom_mul.o bn_s_mp_toom_s
|
||||
|
||||
objs: $(OBJECTS)
|
||||
|
||||
.c.o:
|
||||
$(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
|
||||
.c.o: $(HEADERS)
|
||||
$(LTCOMPILE) $(LTM_CFLAGS) $(LTM_LDFLAGS) -o $@ -c $<
|
||||
|
||||
LOBJECTS = $(OBJECTS:.o=.lo)
|
||||
|
||||
$(LIBNAME): $(OBJECTS)
|
||||
$(LTLINK) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LIBTOOLFLAGS)
|
||||
$(LTLINK) $(LTM_LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_SO) $(LTM_LIBTOOLFLAGS)
|
||||
|
||||
install: $(LIBNAME)
|
||||
install -d $(DESTDIR)$(LIBPATH)
|
||||
@ -79,27 +79,18 @@ uninstall:
|
||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
|
||||
|
||||
test: $(LIBNAME)
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/main.c -o demo/main.o
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/opponent.c -o demo/opponent.o
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/test.c -o demo/test.o
|
||||
$(LTLINK) $(LDFLAGS) -o test demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
|
||||
test_standalone: $(LIBNAME)
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/main.c -o demo/main.o
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/opponent.c -o demo/opponent.o
|
||||
$(LTCOMPILE) $(CFLAGS) -c demo/test.c -o demo/test.o
|
||||
$(LTLINK) $(LDFLAGS) -o test demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||
$(LTLINK) $(LTM_LDFLAGS) $^ -o test
|
||||
|
||||
.PHONY: mtest
|
||||
mtest:
|
||||
cd mtest ; $(CC) $(CFLAGS) -O0 mtest.c $(LDFLAGS) -o mtest
|
||||
cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LDFLAGS) -o mtest
|
||||
|
||||
timing: $(LIBNAME) demo/timing.c
|
||||
$(LTLINK) $(CFLAGS) $(LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
|
||||
$(LTLINK) $(LTM_CFLAGS) $(LTM_LDFLAGS) -DTIMER demo/timing.c $(LIBNAME) -o timing
|
||||
|
||||
tune: $(LIBNAME)
|
||||
$(LTCOMPILE) $(CFLAGS) -c etc/tune.c -o etc/tune.o
|
||||
$(LTLINK) $(LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
|
||||
$(LTCOMPILE) $(LTM_CFLAGS) -c etc/tune.c -o etc/tune.o
|
||||
$(LTLINK) $(LTM_LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
|
||||
cd etc/; /bin/sh tune_it.sh; cd ..
|
||||
$(MAKE) -f makefile.shared
|
||||
|
@ -47,60 +47,67 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
|
||||
LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
|
||||
|
||||
ifdef SANITIZER
|
||||
CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
|
||||
LTM_CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=float-divide-by-zero
|
||||
endif
|
||||
|
||||
ifndef NO_ADDTL_WARNINGS
|
||||
# additional warnings
|
||||
CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
|
||||
CFLAGS += -Wstrict-prototypes -Wpointer-arith
|
||||
LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
|
||||
LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith
|
||||
endif
|
||||
|
||||
ifdef CONV_WARNINGS
|
||||
CFLAGS += -std=c89 -Wconversion -Wsign-conversion
|
||||
LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion
|
||||
ifeq ($(CONV_WARNINGS), strict)
|
||||
CFLAGS += -DMP_USE_ENUMS -Wc++-compat
|
||||
LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat
|
||||
endif
|
||||
else
|
||||
CFLAGS += -Wsystem-headers
|
||||
LTM_CFLAGS += -Wsystem-headers
|
||||
endif
|
||||
|
||||
ifdef COMPILE_DEBUG
|
||||
#debug
|
||||
CFLAGS += -g3
|
||||
LTM_CFLAGS += -g3
|
||||
endif
|
||||
|
||||
ifdef COMPILE_SIZE
|
||||
#for size
|
||||
CFLAGS += -Os
|
||||
LTM_CFLAGS += -Os
|
||||
else
|
||||
|
||||
ifndef IGNORE_SPEED
|
||||
#for speed
|
||||
CFLAGS += -O3 -funroll-loops
|
||||
LTM_CFLAGS += -O3 -funroll-loops
|
||||
|
||||
#x86 optimizations [should be valid for any GCC install though]
|
||||
CFLAGS += -fomit-frame-pointer
|
||||
LTM_CFLAGS += -fomit-frame-pointer
|
||||
endif
|
||||
|
||||
endif # COMPILE_SIZE
|
||||
|
||||
ifneq ($(findstring clang,$(CC)),)
|
||||
CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
|
||||
LTM_CFLAGS += -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header
|
||||
endif
|
||||
ifneq ($(findstring mingw,$(CC)),)
|
||||
CFLAGS += -Wno-shadow
|
||||
LTM_CFLAGS += -Wno-shadow
|
||||
endif
|
||||
ifeq ($(PLATFORM), Darwin)
|
||||
CFLAGS += -Wno-nullability-completeness
|
||||
LTM_CFLAGS += -Wno-nullability-completeness
|
||||
endif
|
||||
ifeq ($(PLATFORM), CYGWIN)
|
||||
LIBTOOLFLAGS += -no-undefined
|
||||
endif
|
||||
|
||||
# add in the standard FLAGS
|
||||
LTM_CFLAGS += $(CFLAGS)
|
||||
LTM_LFLAGS += $(LFLAGS)
|
||||
LTM_LDFLAGS += $(LDFLAGS)
|
||||
LTM_LIBTOOLFLAGS += $(LIBTOOLFLAGS)
|
||||
|
||||
|
||||
ifeq ($(PLATFORM),FreeBSD)
|
||||
_ARCH := $(shell sysctl -b hw.machine_arch)
|
||||
else
|
||||
@ -119,7 +126,7 @@ endif
|
||||
HEADERS_PUB=tommath.h
|
||||
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h $(HEADERS_PUB)
|
||||
|
||||
test_standalone: CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
|
||||
test_standalone: LTM_CFLAGS+=-DLTM_DEMO_TEST_VS_MTEST=0
|
||||
|
||||
#LIBPATH The directory for libtommath to be installed to.
|
||||
#INCPATH The directory to install the header files for libtommath.
|
||||
@ -132,9 +139,9 @@ DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf
|
||||
|
||||
#make the code coverage of the library
|
||||
#
|
||||
coverage: CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
|
||||
coverage: LFLAGS += -lgcov
|
||||
coverage: LDFLAGS += -lgcov
|
||||
coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
|
||||
coverage: LTM_LFLAGS += -lgcov
|
||||
coverage: LTM_LDFLAGS += -lgcov
|
||||
|
||||
coverage: $(COVERAGE)
|
||||
$(COVERAGE_APP)
|
||||
|
@ -827,6 +827,7 @@
|
||||
# define BN_MP_GROW_C
|
||||
# define BN_MP_RAND_SOURCE_C
|
||||
# define BN_MP_ZERO_C
|
||||
# define BN_S_MP_RAND_PLATFORM_C
|
||||
# define BN_S_MP_RAND_SOURCE_C
|
||||
#endif
|
||||
|
||||
@ -1118,7 +1119,9 @@
|
||||
# define BN_MP_INIT_C
|
||||
# define BN_MP_MOD_C
|
||||
# define BN_MP_MUL_C
|
||||
# define BN_MP_REDUCE_2K_L_C
|
||||
# define BN_MP_REDUCE_2K_SETUP_L_C
|
||||
# define BN_MP_REDUCE_C
|
||||
# define BN_MP_REDUCE_SETUP_C
|
||||
# define BN_MP_SET_C
|
||||
# define BN_MP_SQR_C
|
||||
@ -1128,17 +1131,21 @@
|
||||
# define BN_MP_CLEAR_C
|
||||
# define BN_MP_COPY_C
|
||||
# define BN_MP_COUNT_BITS_C
|
||||
# define BN_MP_DR_REDUCE_C
|
||||
# define BN_MP_DR_SETUP_C
|
||||
# define BN_MP_EXCH_C
|
||||
# define BN_MP_INIT_SIZE_C
|
||||
# define BN_MP_MOD_C
|
||||
# define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
|
||||
# define BN_MP_MONTGOMERY_REDUCE_C
|
||||
# define BN_MP_MONTGOMERY_SETUP_C
|
||||
# define BN_MP_MULMOD_C
|
||||
# define BN_MP_MUL_C
|
||||
# define BN_MP_REDUCE_2K_C
|
||||
# define BN_MP_REDUCE_2K_SETUP_C
|
||||
# define BN_MP_SET_C
|
||||
# define BN_MP_SQR_C
|
||||
# define BN_S_MP_MONTGOMERY_REDUCE_FAST_C
|
||||
#endif
|
||||
|
||||
#if defined(BN_S_MP_GET_BIT_C)
|
||||
|
@ -4,10 +4,13 @@
|
||||
/* super class file for PK algos */
|
||||
|
||||
/* default ... include all MPI */
|
||||
#ifndef LTM_NOTHING
|
||||
#define LTM_ALL
|
||||
#endif
|
||||
|
||||
/* RSA only (does not support DH/DSA/ECC) */
|
||||
/* #define SC_RSA_1 */
|
||||
/* #define SC_RSA_1_WITH_TESTS */
|
||||
|
||||
/* For reference.... On an Athlon64 optimizing for speed...
|
||||
|
||||
@ -15,61 +18,93 @@
|
||||
|
||||
*/
|
||||
|
||||
#ifdef SC_RSA_1_WITH_TESTS
|
||||
# define BN_MP_ERROR_TO_STRING_C
|
||||
# define BN_MP_FREAD_C
|
||||
# define BN_MP_FWRITE_C
|
||||
# define BN_MP_INCR_C
|
||||
# define BN_MP_ISEVEN_C
|
||||
# define BN_MP_ISODD_C
|
||||
# define BN_MP_NEG_C
|
||||
# define BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
|
||||
# define BN_MP_RADIX_SIZE_C
|
||||
# define BN_MP_RAND_C
|
||||
# define BN_MP_REDUCE_C
|
||||
# define BN_MP_REDUCE_2K_L_C
|
||||
# define BN_MP_READ_SIGNED_BIN_C
|
||||
# define BN_MP_ROOT_U32_C
|
||||
# define BN_MP_SET_L_C
|
||||
# define BN_MP_SET_UL_C
|
||||
# define BN_MP_SIGNED_BIN_SIZE_C
|
||||
# define BN_MP_TO_RADIX_C
|
||||
# define BN_MP_TO_SIGNED_BIN_C
|
||||
# define BN_S_MP_RAND_JENKINS_C
|
||||
# define BN_S_MP_RAND_PLATFORM_C
|
||||
#endif
|
||||
|
||||
/* Works for RSA only, mpi.o is 68KiB */
|
||||
#ifdef SC_RSA_1
|
||||
# define BN_MP_SHRINK_C
|
||||
# define BN_MP_LCM_C
|
||||
# define BN_MP_PRIME_RANDOM_EX_C
|
||||
# define BN_MP_INVMOD_C
|
||||
# define BN_MP_GCD_C
|
||||
# define BN_MP_MOD_C
|
||||
# define BN_MP_MULMOD_C
|
||||
#if defined(SC_RSA_1) || defined (SC_RSA_1_WITH_TESTS)
|
||||
# define BN_CUTOFFS_C
|
||||
# define BN_MP_ADDMOD_C
|
||||
# define BN_MP_EXPTMOD_C
|
||||
# define BN_MP_SET_INT_C
|
||||
# define BN_MP_INIT_MULTI_C
|
||||
# define BN_MP_CLEAR_MULTI_C
|
||||
# define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
# define BN_MP_TO_UNSIGNED_BIN_C
|
||||
# define BN_MP_EXPTMOD_C
|
||||
# define BN_MP_GCD_C
|
||||
# define BN_MP_INIT_MULTI_C
|
||||
# define BN_MP_INVMOD_C
|
||||
# define BN_MP_LCM_C
|
||||
# define BN_MP_MOD_C
|
||||
# define BN_MP_MOD_D_C
|
||||
# define BN_MP_MULMOD_C
|
||||
# define BN_MP_PRIME_IS_PRIME_C
|
||||
# define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
|
||||
# define BN_S_MP_REVERSE_C
|
||||
# define BN_MP_PRIME_RAND_C
|
||||
# define BN_MP_RADIX_SMAP_C
|
||||
# define BN_MP_SET_INT_C
|
||||
# define BN_MP_SHRINK_C
|
||||
# define BN_MP_TO_UNSIGNED_BIN_C
|
||||
# define BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
# define BN_PRIME_TAB_C
|
||||
# define BN_S_MP_REVERSE_C
|
||||
|
||||
/* other modifiers */
|
||||
# define BN_MP_DIV_SMALL /* Slower division, not critical */
|
||||
|
||||
|
||||
/* here we are on the last pass so we turn things off. The functions classes are still there
|
||||
* but we remove them specifically from the build. This also invokes tweaks in functions
|
||||
* like removing support for even moduli, etc...
|
||||
*/
|
||||
# ifdef LTM_LAST
|
||||
# undef BN_S_MP_TOOM_MUL_C
|
||||
# undef BN_S_MP_TOOM_SQR_C
|
||||
# undef BN_S_MP_KARATSUBA_MUL_C
|
||||
# undef BN_S_MP_KARATSUBA_SQR_C
|
||||
# undef BN_MP_REDUCE_C
|
||||
# undef BN_MP_REDUCE_SETUP_C
|
||||
# undef BN_MP_DR_IS_MODULUS_C
|
||||
# undef BN_MP_DR_SETUP_C
|
||||
# undef BN_MP_DR_REDUCE_C
|
||||
# undef BN_MP_REDUCE_IS_2K_C
|
||||
# undef BN_MP_DIV_3_C
|
||||
# undef BN_MP_REDUCE_2K_SETUP_C
|
||||
# undef BN_MP_REDUCE_2K_C
|
||||
# undef BN_MP_REDUCE_IS_2K_C
|
||||
# undef BN_MP_REDUCE_SETUP_C
|
||||
# undef BN_S_MP_BALANCE_MUL_C
|
||||
# undef BN_S_MP_EXPTMOD_C
|
||||
# undef BN_MP_DIV_3_C
|
||||
# undef BN_S_MP_INVMOD_FAST_C
|
||||
# undef BN_S_MP_KARATSUBA_MUL_C
|
||||
# undef BN_S_MP_KARATSUBA_SQR_C
|
||||
# undef BN_S_MP_MUL_HIGH_DIGS_C
|
||||
# undef BN_S_MP_MUL_HIGH_DIGS_FAST_C
|
||||
# undef BN_S_MP_INVMOD_FAST_C
|
||||
# undef BN_S_MP_TOOM_MUL_C
|
||||
# undef BN_S_MP_TOOM_SQR_C
|
||||
|
||||
# ifndef SC_RSA_1_WITH_TESTS
|
||||
# undef BN_MP_REDUCE_C
|
||||
# endif
|
||||
|
||||
/* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
|
||||
* which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines]
|
||||
* which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
|
||||
* trouble.
|
||||
*/
|
||||
# undef BN_MP_MONTGOMERY_REDUCE_C
|
||||
# undef BN_S_MP_MUL_DIGS_C
|
||||
# undef BN_S_MP_SQR_C
|
||||
# undef BN_MP_MONTGOMERY_REDUCE_C
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user