commit
c63799c392
@ -90,6 +90,9 @@ matrix:
|
|||||||
- libc6-dev-i386
|
- libc6-dev-i386
|
||||||
- gcc-multilib
|
- 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.
|
# 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_8BIT --with-travis-valgrind --make-option=tune'
|
||||||
#- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --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
|
#endif
|
||||||
|
|
||||||
#if defined(MP_PRNG_ENABLE_LTM_RNG)
|
#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));
|
unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void));
|
||||||
void (*ltm_rng_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 =
|
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;
|
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 */
|
/* force KARA and TOOM to enable despite cutoffs */
|
||||||
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
|
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
|
||||||
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
|
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
|
/* 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"
|
#include "shared.h"
|
||||||
|
|
||||||
static long rand_long(void)
|
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");
|
printf("A certified prime is a prime but mp_prime_is_prime says it is not.\n");
|
||||||
}
|
}
|
||||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||||
printf("prime tested was: ");
|
printf("prime tested was: 0x");
|
||||||
mp_fwrite(&a,16,stdout);
|
mp_fwrite(&a,16,stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
@ -1010,10 +1011,10 @@ static int test_mp_prime_is_prime(void)
|
|||||||
printf("\nfrobenius-underwood says sub is not prime!\n");
|
printf("\nfrobenius-underwood says sub is not prime!\n");
|
||||||
}
|
}
|
||||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||||
printf("prime tested was: ");
|
printf("prime tested was: 0x");
|
||||||
mp_fwrite(&a,16,stdout);
|
mp_fwrite(&a,16,stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
printf("sub tested was: ");
|
printf("sub tested was: 0x");
|
||||||
mp_fwrite(&b,16,stdout);
|
mp_fwrite(&b,16,stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
goto LBL_ERR;
|
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");
|
printf("\n\nissue #143 - mp_prime_strong_lucas_selfridge FAILED!\n");
|
||||||
}
|
}
|
||||||
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
if ((err != MP_OKAY) || (cnt == MP_NO)) {
|
||||||
printf("prime tested was: ");
|
printf("prime tested was: 0x");
|
||||||
mp_fwrite(&a,16,stdout);
|
mp_fwrite(&a,16,stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
goto LBL_ERR;
|
goto LBL_ERR;
|
||||||
@ -2219,54 +2220,62 @@ int unit_tests(int argc, char **argv)
|
|||||||
const char *name;
|
const char *name;
|
||||||
int (*fn)(void);
|
int (*fn)(void);
|
||||||
} test[] = {
|
} test[] = {
|
||||||
#define T(n) { #n, test_##n }
|
#define T0(n) { #n, test_##n }
|
||||||
T(feature_detection),
|
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
|
||||||
T(trivial_stuff),
|
#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
|
||||||
T(mp_get_set_i32),
|
T0(feature_detection),
|
||||||
T(mp_get_set_i64),
|
T0(trivial_stuff),
|
||||||
T(mp_and),
|
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
|
||||||
T(mp_cnt_lsb),
|
T2(mp_get_set_i64, MP_GET_I64, MP_GET_MAG_U64),
|
||||||
T(mp_complement),
|
T1(mp_and, MP_AND),
|
||||||
T(mp_decr),
|
T1(mp_cnt_lsb, MP_CNT_LSB),
|
||||||
T(mp_div_3),
|
T1(mp_complement, MP_COMPLEMENT),
|
||||||
T(mp_dr_reduce),
|
T1(mp_decr, MP_DECR),
|
||||||
T(mp_fread_fwrite),
|
T1(mp_div_3, MP_DIV_3),
|
||||||
T(mp_get_u32),
|
T1(mp_dr_reduce, MP_DR_REDUCE),
|
||||||
T(mp_get_u64),
|
T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
|
||||||
T(mp_get_ul),
|
T1(mp_get_u32, MP_GET_I32),
|
||||||
T(mp_ilogb),
|
T1(mp_get_u64, MP_GET_I64),
|
||||||
T(mp_incr),
|
T1(mp_get_ul, MP_GET_L),
|
||||||
T(mp_invmod),
|
T1(mp_ilogb, MP_ILOGB),
|
||||||
T(mp_is_square),
|
T1(mp_incr, MP_INCR),
|
||||||
T(mp_kronecker),
|
T1(mp_invmod, MP_INVMOD),
|
||||||
T(mp_montgomery_reduce),
|
T1(mp_is_square, MP_IS_SQUARE),
|
||||||
T(mp_root_u32),
|
T1(mp_kronecker, MP_KRONECKER),
|
||||||
T(mp_or),
|
T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
|
||||||
T(mp_prime_is_prime),
|
T1(mp_root_u32, MP_ROOT_U32),
|
||||||
T(mp_prime_next_prime),
|
T1(mp_or, MP_OR),
|
||||||
T(mp_prime_rand),
|
T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
|
||||||
T(mp_rand),
|
T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
|
||||||
T(mp_read_radix),
|
T1(mp_prime_rand, MP_PRIME_RAND),
|
||||||
T(mp_reduce_2k),
|
T1(mp_rand, MP_RAND),
|
||||||
T(mp_reduce_2k_l),
|
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)
|
#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559)
|
||||||
T(mp_set_double),
|
T1(mp_set_double, MP_SET_DOUBLE),
|
||||||
#endif
|
#endif
|
||||||
T(mp_signed_rsh),
|
T1(mp_signed_rsh, MP_SIGNED_RSH),
|
||||||
T(mp_sqrt),
|
T1(mp_sqrt, MP_SQRT),
|
||||||
T(mp_sqrtmod_prime),
|
T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
|
||||||
T(mp_xor),
|
T1(mp_xor, MP_XOR),
|
||||||
T(s_mp_balance_mul),
|
T1(s_mp_balance_mul, S_MP_BALANCE_MUL),
|
||||||
T(s_mp_karatsuba_mul),
|
T1(s_mp_karatsuba_mul, S_MP_KARATSUBA_MUL),
|
||||||
T(s_mp_karatsuba_sqr),
|
T1(s_mp_karatsuba_sqr, S_MP_KARATSUBA_SQR),
|
||||||
T(s_mp_toom_mul),
|
T1(s_mp_toom_mul, S_MP_TOOM_MUL),
|
||||||
T(s_mp_toom_sqr)
|
T1(s_mp_toom_sqr, S_MP_TOOM_SQR),
|
||||||
#undef T
|
#undef T2
|
||||||
|
#undef T1
|
||||||
};
|
};
|
||||||
unsigned long i;
|
unsigned long i, ok, fail, nop;
|
||||||
int res = EXIT_SUCCESS, j;
|
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);
|
mp_rand_source(s_mp_rand_jenkins);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
|
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;
|
if (j == argc) continue;
|
||||||
}
|
}
|
||||||
printf("TEST %s\n\n", test[i].name);
|
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);
|
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)
|
# default lib name (requires install with root)
|
||||||
# LIBNAME=-ltommath
|
# LIBNAME=-ltommath
|
||||||
@ -8,31 +9,31 @@ LIBNAME=../libtommath.a
|
|||||||
|
|
||||||
#provable primes
|
#provable primes
|
||||||
pprime: pprime.o
|
pprime: pprime.o
|
||||||
$(CC) $(CFLAGS) pprime.o $(LIBNAME) -o pprime
|
$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
|
||||||
|
|
||||||
# portable [well requires clock()] tuning app
|
# portable [well requires clock()] tuning app
|
||||||
tune: tune.o
|
tune: tune.o
|
||||||
$(CC) $(CFLAGS) tune.o $(LIBNAME) -o tune
|
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
|
||||||
./tune_it.sh
|
./tune_it.sh
|
||||||
|
|
||||||
test_standalone: tune.o
|
test_standalone: tune.o
|
||||||
# The benchmark program works as a testtool, too
|
# 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
|
# spits out mersenne primes
|
||||||
mersenne: mersenne.o
|
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
|
# finds DR safe primes for the given config
|
||||||
drprime: drprime.o
|
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
|
# finds 2k safe primes for the given config
|
||||||
2kprime: 2kprime.o
|
2kprime: 2kprime.o
|
||||||
$(CC) $(CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
|
$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
|
||||||
|
|
||||||
mont: mont.o
|
mont: mont.o
|
||||||
$(CC) $(CFLAGS) mont.o $(LIBNAME) -o mont
|
$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -381,7 +381,7 @@ EOS
|
|||||||
# scan for mp_* and make classes
|
# scan for mp_* and make classes
|
||||||
my @deps = ();
|
my @deps = ();
|
||||||
foreach my $line (split /\n/, $content) {
|
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 = $&;
|
my $a = $&;
|
||||||
next if $a eq "mp_err";
|
next if $a eq "mp_err";
|
||||||
$a =~ tr/[a-z]/[A-Z]/;
|
$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
|
include makefile_include.mk
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c $(HEADERS)
|
||||||
ifneq ($V,1)
|
ifneq ($V,1)
|
||||||
@echo " * ${CC} $@"
|
@echo " * ${CC} $@"
|
||||||
endif
|
endif
|
||||||
${silent} ${CC} -c ${CFLAGS} $< -o $@
|
${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@
|
||||||
|
|
||||||
LCOV_ARGS=--directory .
|
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
|
#END_INS
|
||||||
|
|
||||||
$(OBJECTS): $(HEADERS)
|
|
||||||
|
|
||||||
$(LIBNAME): $(OBJECTS)
|
$(LIBNAME): $(OBJECTS)
|
||||||
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
||||||
$(RANLIB) $@
|
$(RANLIB) $@
|
||||||
@ -79,11 +77,11 @@ profiled:
|
|||||||
#make a single object profiled library
|
#make a single object profiled library
|
||||||
profiled_single:
|
profiled_single:
|
||||||
perl gen.pl
|
perl gen.pl
|
||||||
$(CC) $(CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
|
$(CC) $(LTM_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) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
|
||||||
./timing
|
./timing
|
||||||
rm -f *.o 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
|
$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
|
||||||
ranlib $(LIBNAME)
|
ranlib $(LIBNAME)
|
||||||
|
|
||||||
@ -97,21 +95,18 @@ uninstall:
|
|||||||
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
|
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
|
||||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||||
|
|
||||||
test: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o test
|
$(CC) $(LTM_CFLAGS) $^ $(LTM_LFLAGS) -o test
|
||||||
|
|
||||||
test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
|
||||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o test
|
|
||||||
|
|
||||||
.PHONY: mtest
|
.PHONY: mtest
|
||||||
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
|
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)
|
tune: $(LIBNAME)
|
||||||
$(MAKE) -C etc tune
|
$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
|
||||||
$(MAKE)
|
$(MAKE)
|
||||||
|
|
||||||
# You have to create a file .coveralls.yml with the content "repo_token: <the token>"
|
# 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)
|
objs: $(OBJECTS)
|
||||||
|
|
||||||
.c.o:
|
.c.o: $(HEADERS)
|
||||||
$(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
|
$(LTCOMPILE) $(LTM_CFLAGS) $(LTM_LDFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
LOBJECTS = $(OBJECTS:.o=.lo)
|
LOBJECTS = $(OBJECTS:.o=.lo)
|
||||||
|
|
||||||
$(LIBNAME): $(OBJECTS)
|
$(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: $(LIBNAME)
|
||||||
install -d $(DESTDIR)$(LIBPATH)
|
install -d $(DESTDIR)$(LIBPATH)
|
||||||
@ -79,27 +79,18 @@ uninstall:
|
|||||||
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
|
||||||
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
|
rm $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
|
||||||
|
|
||||||
test: $(LIBNAME)
|
test test_standalone: demo/main.o demo/opponent.o demo/test.o $(LIBNAME)
|
||||||
$(LTCOMPILE) $(CFLAGS) -c demo/main.c -o demo/main.o
|
$(LTLINK) $(LTM_LDFLAGS) $^ -o test
|
||||||
$(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)
|
|
||||||
|
|
||||||
.PHONY: mtest
|
.PHONY: mtest
|
||||||
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
|
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)
|
tune: $(LIBNAME)
|
||||||
$(LTCOMPILE) $(CFLAGS) -c etc/tune.c -o etc/tune.o
|
$(LTCOMPILE) $(LTM_CFLAGS) -c etc/tune.c -o etc/tune.o
|
||||||
$(LTLINK) $(LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
|
$(LTLINK) $(LTM_LDFLAGS) -o etc/tune etc/tune.o $(LIBNAME)
|
||||||
cd etc/; /bin/sh tune_it.sh; cd ..
|
cd etc/; /bin/sh tune_it.sh; cd ..
|
||||||
$(MAKE) -f makefile.shared
|
$(MAKE) -f makefile.shared
|
||||||
|
@ -47,60 +47,67 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
|
LTM_CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
|
||||||
|
|
||||||
ifdef SANITIZER
|
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
|
endif
|
||||||
|
|
||||||
ifndef NO_ADDTL_WARNINGS
|
ifndef NO_ADDTL_WARNINGS
|
||||||
# additional warnings
|
# additional warnings
|
||||||
CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
|
LTM_CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
|
||||||
CFLAGS += -Wstrict-prototypes -Wpointer-arith
|
LTM_CFLAGS += -Wstrict-prototypes -Wpointer-arith
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONV_WARNINGS
|
ifdef CONV_WARNINGS
|
||||||
CFLAGS += -std=c89 -Wconversion -Wsign-conversion
|
LTM_CFLAGS += -std=c89 -Wconversion -Wsign-conversion
|
||||||
ifeq ($(CONV_WARNINGS), strict)
|
ifeq ($(CONV_WARNINGS), strict)
|
||||||
CFLAGS += -DMP_USE_ENUMS -Wc++-compat
|
LTM_CFLAGS += -DMP_USE_ENUMS -Wc++-compat
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
CFLAGS += -Wsystem-headers
|
LTM_CFLAGS += -Wsystem-headers
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef COMPILE_DEBUG
|
ifdef COMPILE_DEBUG
|
||||||
#debug
|
#debug
|
||||||
CFLAGS += -g3
|
LTM_CFLAGS += -g3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef COMPILE_SIZE
|
ifdef COMPILE_SIZE
|
||||||
#for size
|
#for size
|
||||||
CFLAGS += -Os
|
LTM_CFLAGS += -Os
|
||||||
else
|
else
|
||||||
|
|
||||||
ifndef IGNORE_SPEED
|
ifndef IGNORE_SPEED
|
||||||
#for speed
|
#for speed
|
||||||
CFLAGS += -O3 -funroll-loops
|
LTM_CFLAGS += -O3 -funroll-loops
|
||||||
|
|
||||||
#x86 optimizations [should be valid for any GCC install though]
|
#x86 optimizations [should be valid for any GCC install though]
|
||||||
CFLAGS += -fomit-frame-pointer
|
LTM_CFLAGS += -fomit-frame-pointer
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endif # COMPILE_SIZE
|
endif # COMPILE_SIZE
|
||||||
|
|
||||||
ifneq ($(findstring clang,$(CC)),)
|
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
|
endif
|
||||||
ifneq ($(findstring mingw,$(CC)),)
|
ifneq ($(findstring mingw,$(CC)),)
|
||||||
CFLAGS += -Wno-shadow
|
LTM_CFLAGS += -Wno-shadow
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM), Darwin)
|
ifeq ($(PLATFORM), Darwin)
|
||||||
CFLAGS += -Wno-nullability-completeness
|
LTM_CFLAGS += -Wno-nullability-completeness
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM), CYGWIN)
|
ifeq ($(PLATFORM), CYGWIN)
|
||||||
LIBTOOLFLAGS += -no-undefined
|
LIBTOOLFLAGS += -no-undefined
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# add in the standard FLAGS
|
||||||
|
LTM_CFLAGS += $(CFLAGS)
|
||||||
|
LTM_LFLAGS += $(LFLAGS)
|
||||||
|
LTM_LDFLAGS += $(LDFLAGS)
|
||||||
|
LTM_LIBTOOLFLAGS += $(LIBTOOLFLAGS)
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(PLATFORM),FreeBSD)
|
ifeq ($(PLATFORM),FreeBSD)
|
||||||
_ARCH := $(shell sysctl -b hw.machine_arch)
|
_ARCH := $(shell sysctl -b hw.machine_arch)
|
||||||
else
|
else
|
||||||
@ -119,7 +126,7 @@ endif
|
|||||||
HEADERS_PUB=tommath.h
|
HEADERS_PUB=tommath.h
|
||||||
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h $(HEADERS_PUB)
|
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.
|
#LIBPATH The directory for libtommath to be installed to.
|
||||||
#INCPATH The directory to install the header files for libtommath.
|
#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
|
#make the code coverage of the library
|
||||||
#
|
#
|
||||||
coverage: CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
|
coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS
|
||||||
coverage: LFLAGS += -lgcov
|
coverage: LTM_LFLAGS += -lgcov
|
||||||
coverage: LDFLAGS += -lgcov
|
coverage: LTM_LDFLAGS += -lgcov
|
||||||
|
|
||||||
coverage: $(COVERAGE)
|
coverage: $(COVERAGE)
|
||||||
$(COVERAGE_APP)
|
$(COVERAGE_APP)
|
||||||
|
@ -827,6 +827,7 @@
|
|||||||
# define BN_MP_GROW_C
|
# define BN_MP_GROW_C
|
||||||
# define BN_MP_RAND_SOURCE_C
|
# define BN_MP_RAND_SOURCE_C
|
||||||
# define BN_MP_ZERO_C
|
# define BN_MP_ZERO_C
|
||||||
|
# define BN_S_MP_RAND_PLATFORM_C
|
||||||
# define BN_S_MP_RAND_SOURCE_C
|
# define BN_S_MP_RAND_SOURCE_C
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1118,7 +1119,9 @@
|
|||||||
# define BN_MP_INIT_C
|
# define BN_MP_INIT_C
|
||||||
# define BN_MP_MOD_C
|
# define BN_MP_MOD_C
|
||||||
# define BN_MP_MUL_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_2K_SETUP_L_C
|
||||||
|
# define BN_MP_REDUCE_C
|
||||||
# define BN_MP_REDUCE_SETUP_C
|
# define BN_MP_REDUCE_SETUP_C
|
||||||
# define BN_MP_SET_C
|
# define BN_MP_SET_C
|
||||||
# define BN_MP_SQR_C
|
# define BN_MP_SQR_C
|
||||||
@ -1128,17 +1131,21 @@
|
|||||||
# define BN_MP_CLEAR_C
|
# define BN_MP_CLEAR_C
|
||||||
# define BN_MP_COPY_C
|
# define BN_MP_COPY_C
|
||||||
# define BN_MP_COUNT_BITS_C
|
# define BN_MP_COUNT_BITS_C
|
||||||
|
# define BN_MP_DR_REDUCE_C
|
||||||
# define BN_MP_DR_SETUP_C
|
# define BN_MP_DR_SETUP_C
|
||||||
# define BN_MP_EXCH_C
|
# define BN_MP_EXCH_C
|
||||||
# define BN_MP_INIT_SIZE_C
|
# define BN_MP_INIT_SIZE_C
|
||||||
# define BN_MP_MOD_C
|
# define BN_MP_MOD_C
|
||||||
# define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
|
# define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
|
||||||
|
# define BN_MP_MONTGOMERY_REDUCE_C
|
||||||
# define BN_MP_MONTGOMERY_SETUP_C
|
# define BN_MP_MONTGOMERY_SETUP_C
|
||||||
# define BN_MP_MULMOD_C
|
# define BN_MP_MULMOD_C
|
||||||
# define BN_MP_MUL_C
|
# define BN_MP_MUL_C
|
||||||
|
# define BN_MP_REDUCE_2K_C
|
||||||
# define BN_MP_REDUCE_2K_SETUP_C
|
# define BN_MP_REDUCE_2K_SETUP_C
|
||||||
# define BN_MP_SET_C
|
# define BN_MP_SET_C
|
||||||
# define BN_MP_SQR_C
|
# define BN_MP_SQR_C
|
||||||
|
# define BN_S_MP_MONTGOMERY_REDUCE_FAST_C
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BN_S_MP_GET_BIT_C)
|
#if defined(BN_S_MP_GET_BIT_C)
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
/* super class file for PK algos */
|
/* super class file for PK algos */
|
||||||
|
|
||||||
/* default ... include all MPI */
|
/* default ... include all MPI */
|
||||||
|
#ifndef LTM_NOTHING
|
||||||
#define LTM_ALL
|
#define LTM_ALL
|
||||||
|
#endif
|
||||||
|
|
||||||
/* RSA only (does not support DH/DSA/ECC) */
|
/* RSA only (does not support DH/DSA/ECC) */
|
||||||
/* #define SC_RSA_1 */
|
/* #define SC_RSA_1 */
|
||||||
|
/* #define SC_RSA_1_WITH_TESTS */
|
||||||
|
|
||||||
/* For reference.... On an Athlon64 optimizing for speed...
|
/* 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 */
|
/* Works for RSA only, mpi.o is 68KiB */
|
||||||
#ifdef SC_RSA_1
|
#if defined(SC_RSA_1) || defined (SC_RSA_1_WITH_TESTS)
|
||||||
# define BN_MP_SHRINK_C
|
# define BN_CUTOFFS_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
|
|
||||||
# define BN_MP_ADDMOD_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_CLEAR_MULTI_C
|
||||||
# define BN_MP_UNSIGNED_BIN_SIZE_C
|
# define BN_MP_EXPTMOD_C
|
||||||
# define BN_MP_TO_UNSIGNED_BIN_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_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_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_PRIME_TAB_C
|
||||||
|
# define BN_S_MP_REVERSE_C
|
||||||
|
|
||||||
/* other modifiers */
|
/* other modifiers */
|
||||||
# define BN_MP_DIV_SMALL /* Slower division, not critical */
|
# 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
|
/* 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
|
* but we remove them specifically from the build. This also invokes tweaks in functions
|
||||||
* like removing support for even moduli, etc...
|
* like removing support for even moduli, etc...
|
||||||
*/
|
*/
|
||||||
# ifdef LTM_LAST
|
# 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_IS_MODULUS_C
|
||||||
# undef BN_MP_DR_SETUP_C
|
# undef BN_MP_DR_SETUP_C
|
||||||
# undef BN_MP_DR_REDUCE_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_SETUP_C
|
||||||
# undef BN_MP_REDUCE_2K_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_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_C
|
||||||
# undef BN_S_MP_MUL_HIGH_DIGS_FAST_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
|
/* 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 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
|
* which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
|
||||||
* trouble.
|
* trouble.
|
||||||
*/
|
*/
|
||||||
|
# undef BN_MP_MONTGOMERY_REDUCE_C
|
||||||
# undef BN_S_MP_MUL_DIGS_C
|
# undef BN_S_MP_MUL_DIGS_C
|
||||||
# undef BN_S_MP_SQR_C
|
# undef BN_S_MP_SQR_C
|
||||||
# undef BN_MP_MONTGOMERY_REDUCE_C
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user