Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*.gcda
*.gcno
*.gcov
*.dll
*.exp
*.pdb
*.lib
*.tmp
[Dd]ebug/
Expand Down
58 changes: 42 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# #
#############################################################################

# Run the tests based on Ubuntu 16.04
dist: xenial
# The Ubuntu version we're going to use to run the tests
dist: bionic

# Compilation failures are in gcc_errors_*.log
# Failed tests in test_*.log
Expand Down Expand Up @@ -72,15 +72,26 @@ matrix:
packages:
- astyle

# Check public symbols of dynamic libraries
- env: BUILDOPTIONS='--symbols'
addons:
apt:
packages:
- libtool-bin

# Run always with valgrind (no sanitizer, but debug info)
- env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc-4.9 --with-m64 --with-valgrind'
- env: COMPILE_DEBUG=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind'

# Shared library build
- env: COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc --make-option=-f --make-option=makefile.shared'
addons:
apt:
packages:
- gcc-4.9
- gcc-8
- libtool-bin

# GCC for the 32-bit architecture (no valgrind)
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m32'
- env: BUILDOPTIONS='--with-cc=gcc --with-m32'
addons:
apt:
packages:
Expand Down Expand Up @@ -108,9 +119,9 @@ matrix:

# GCC for the x86-64 architecture testing against a different Bigint-implementation
# with 333333 different inputs.
#- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --with-travis-valgrind'
#- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --with-travis-valgrind'
# ... and a better random source.
- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --mtest-real-rand --with-travis-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --mtest-real-rand --with-travis-valgrind'

# clang for the x86-64 architecture testing against a different Bigint-implementation
# with 333333 different inputs
Expand All @@ -121,20 +132,20 @@ matrix:
# GCC for the x64_32 architecture (32-bit longs and 32-bit pointers)
# TODO: Probably not possible to run anything in x32 in Travis
# but needs to be checked to be sure.
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --with-mx32'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --with-mx32'
addons:
apt:
packages:
- libc6-dev-x32
- gcc-multilib

# GCC for the x86-64 architecture (64-bit longs and 64-bit pointers)
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc-4.7 --with-m64 --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-travis-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
addons:
apt:
packages:
- gcc-4.7
- gcc-5
- env: BUILDOPTIONS='--with-cc=gcc-4.8 --with-m64 --with-travis-valgrind'
addons:
apt:
Expand All @@ -147,6 +158,21 @@ matrix:
- env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_USE_MEMOPS --with-m64 --with-travis-valgrind'
- env: SANITIZER=1 CONV_WARNINGS=strict BUILDOPTIONS='--with-cc=clang-7 --c89 --with-m64 --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind --cflags=-DMP_PREC=MP_MIN_PREC'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-10 --with-m64 --with-travis-valgrind'
addons:
apt:
packages:
- clang-10
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-9 --with-m64 --with-travis-valgrind'
addons:
apt:
packages:
- clang-9
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-8 --with-m64 --with-travis-valgrind'
addons:
apt:
packages:
- clang-8
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-travis-valgrind'
addons:
apt:
Expand All @@ -164,18 +190,18 @@ matrix:
- clang-4.0

# Link time optimization
- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-travis-valgrind'
- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=gcc --with-m64 --with-travis-valgrind'
#- env: SANITIZER=1 COMPILE_LTO=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-travis-valgrind'

# GCC for the x86-64 architecture with restricted limb sizes
# formerly started with the option "--with-low-mp" to testme.sh
# but testing all three in one run took to long and timed out.
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_32BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-travis-valgrind'

# clang for the x86-64 architecture with restricted limb sizes
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_16BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_32BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-travis-valgrind'
- env: SANITIZER=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-travis-valgrind'

# Notifications go to
# An email address is also possible.
Expand Down
5 changes: 4 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ build_script:
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
nmake -f makefile.msvc all
nmake -f makefile.msvc test.exe
nmake -f makefile.msvc clean-obj
nmake -f makefile.msvc test_dll.exe CFLAGS="/Ox /MD /DLTM_TEST_DYNAMIC"
test_script:
- cmd: test.exe
- cmd: test_dll.exe
7 changes: 5 additions & 2 deletions s_mp_rand_jenkins.c → demo/s_mp_rand_jenkins.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

/* Bob Jenkins' http://burtleburtle.net/bob/rand/smallprng.html */
/* Chosen for speed and a good "mix" */

/* TODO: jenkins prng is not thread safe as of now */

typedef struct {
uint64_t a;
uint64_t b;
Expand All @@ -25,7 +28,7 @@ static uint64_t s_rand_jenkins_val(void)
return jenkins_x.d;
}

void s_mp_rand_jenkins_init(uint64_t seed)
static void s_mp_rand_jenkins_init(uint64_t seed)
{
int i;
jenkins_x.a = 0xF1EA5EEDuL;
Expand All @@ -35,7 +38,7 @@ void s_mp_rand_jenkins_init(uint64_t seed)
}
}

mp_err s_mp_rand_jenkins(void *p, size_t n)
static mp_err s_mp_rand_jenkins(void *p, size_t n)
{
char *q = (char *)p;
while (n > 0u) {
Expand Down
41 changes: 25 additions & 16 deletions demo/test.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <inttypes.h>
#include "shared.h"

#define S_MP_RAND_JENKINS_C
#include "s_mp_rand_jenkins.c"

static long rand_long(void)
{
long x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
Expand All @@ -14,7 +17,7 @@ static long rand_long(void)
static int rand_int(void)
{
int x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
Expand All @@ -24,7 +27,7 @@ static int rand_int(void)
static int32_t rand_int32(void)
{
int32_t x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
Expand All @@ -34,7 +37,7 @@ static int32_t rand_int32(void)
static int64_t rand_int64(void)
{
int64_t x;
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
if (s_mp_rand_jenkins(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -2134,15 +2137,20 @@ static int test_mp_pack_unpack(void)
return EXIT_FAILURE;
}

#ifndef LTM_TEST_DYNAMIC
#define ONLY_PUBLIC_API_C
#endif

static int unit_tests(int argc, char **argv)
{
static const struct {
const char *name;
int (*fn)(void);
} test[] = {
#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 }
#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 }
#define T3(n, o1, o2, o3) { #n, (MP_HAS(o1) && MP_HAS(o2) && MP_HAS(o3)) ? test_##n : NULL }
T0(feature_detection),
T0(trivial_stuff),
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
Expand All @@ -2151,7 +2159,7 @@ static int unit_tests(int argc, char **argv)
T1(mp_cnt_lsb, MP_CNT_LSB),
T1(mp_complement, MP_COMPLEMENT),
T1(mp_decr, MP_SUB_D),
T1(s_mp_div_3, S_MP_DIV_3),
T2(s_mp_div_3, ONLY_PUBLIC_API, S_MP_DIV_3),
T1(mp_dr_reduce, MP_DR_REDUCE),
T2(mp_pack_unpack,MP_PACK, MP_UNPACK),
T2(mp_fread_fwrite, MP_FREAD, MP_FWRITE),
Expand All @@ -2176,21 +2184,22 @@ static int unit_tests(int argc, char **argv)
T1(mp_reduce_2k, MP_REDUCE_2K),
T1(mp_reduce_2k_l, MP_REDUCE_2K_L),
T1(mp_radix_size, MP_RADIX_SIZE),
T1(s_mp_radix_size_overestimate, S_MP_RADIX_SIZE_OVERESTIMATE),
T2(s_mp_radix_size_overestimate, ONLY_PUBLIC_API, S_MP_RADIX_SIZE_OVERESTIMATE),
#if defined(MP_HAS_SET_DOUBLE)
T1(mp_set_double, MP_SET_DOUBLE),
#endif
T1(mp_signed_rsh, MP_SIGNED_RSH),
T2(mp_sqrt, MP_SQRT, MP_ROOT_N),
T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
T1(mp_xor, MP_XOR),
T2(s_mp_div_recursive, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
T2(s_mp_div_small, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
T1(s_mp_mul_balance, S_MP_MUL_BALANCE),
T1(s_mp_mul_karatsuba, S_MP_MUL_KARATSUBA),
T1(s_mp_sqr_karatsuba, S_MP_SQR_KARATSUBA),
T1(s_mp_mul_toom, S_MP_MUL_TOOM),
T1(s_mp_sqr_toom, S_MP_SQR_TOOM)
T3(s_mp_div_recursive, ONLY_PUBLIC_API, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
T3(s_mp_div_small, ONLY_PUBLIC_API, S_MP_DIV_SMALL, S_MP_DIV_SCHOOL),
T2(s_mp_mul_balance, ONLY_PUBLIC_API, S_MP_MUL_BALANCE),
T2(s_mp_mul_karatsuba, ONLY_PUBLIC_API, S_MP_MUL_KARATSUBA),
T2(s_mp_sqr_karatsuba, ONLY_PUBLIC_API, S_MP_SQR_KARATSUBA),
T2(s_mp_mul_toom, ONLY_PUBLIC_API, S_MP_MUL_TOOM),
T2(s_mp_sqr_toom, ONLY_PUBLIC_API, S_MP_SQR_TOOM)
#undef T3
#undef T2
#undef T1
};
Expand Down
17 changes: 8 additions & 9 deletions etc/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
LTM_CFLAGS += -Wall -W -Wextra -Wshadow -O3 -I../
LTM_CFLAGS += $(CFLAGS)
LTM_TUNE_CFLAGS = $(CFLAGS) $(LTM_CFLAGS) -Wall -W -Wextra -Wshadow -O3 -I../

# default lib name (requires install with root)
# LIBNAME=-ltommath
Expand All @@ -9,31 +8,31 @@ LIBNAME=../libtommath.a

#provable primes
pprime: pprime.o
$(CC) $(LTM_CFLAGS) pprime.o $(LIBNAME) -o pprime
$(CC) $(LTM_TUNE_CFLAGS) pprime.o $(LIBNAME) -o pprime

# portable [well requires clock()] tuning app
tune: tune.o
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o tune
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o tune
./tune_it.sh

test_standalone: tune.o
# The benchmark program works as a testtool, too
$(CC) $(LTM_CFLAGS) tune.o $(LIBNAME) -o test
$(CC) $(LTM_TUNE_CFLAGS) tune.o $(LIBNAME) -o test

# spits out mersenne primes
mersenne: mersenne.o
$(CC) $(LTM_CFLAGS) mersenne.o $(LIBNAME) -o mersenne
$(CC) $(LTM_TUNE_CFLAGS) mersenne.o $(LIBNAME) -o mersenne

# finds DR safe primes for the given config
drprime: drprime.o
$(CC) $(LTM_CFLAGS) drprime.o $(LIBNAME) -o drprime
$(CC) $(LTM_TUNE_CFLAGS) drprime.o $(LIBNAME) -o drprime

# finds 2k safe primes for the given config
2kprime: 2kprime.o
$(CC) $(LTM_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime
$(CC) $(LTM_TUNE_CFLAGS) 2kprime.o $(LIBNAME) -o 2kprime

mont: mont.o
$(CC) $(LTM_CFLAGS) mont.o $(LIBNAME) -o mont
$(CC) $(LTM_TUNE_CFLAGS) mont.o $(LIBNAME) -o mont


clean:
Expand Down
6 changes: 4 additions & 2 deletions etc/tune.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
*
* Tom St Denis, tstdenis82@gmail.com
*/
#include "../tommath.h"
#include "../tommath_private.h"
#include "tommath_private.h"
#include <time.h>
#include <inttypes.h>
#include <errno.h>

#define S_MP_RAND_JENKINS_C
#include "../demo/s_mp_rand_jenkins.c"

/*
Please take in mind that both multiplicands are of the same size. The balancing
mechanism in mp_balance works well but has some overhead itself. You can test
Expand Down
4 changes: 4 additions & 0 deletions helper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ sub generate_def {
;
EXPORTS
$files
MP_MUL_KARATSUBA_CUTOFF
MP_SQR_KARATSUBA_CUTOFF
MP_MUL_TOOM_CUTOFF
MP_SQR_TOOM_CUTOFF
";
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions libtommath_VS2008.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@
RelativePath="mp_rand.c"
>
</File>
<File
RelativePath="mp_rand_source.c"
>
</File>
<File
RelativePath="mp_read_radix.c"
>
Expand Down Expand Up @@ -892,10 +896,6 @@
RelativePath="s_mp_radix_size_overestimate.c"
>
</File>
<File
RelativePath="s_mp_rand_jenkins.c"
>
</File>
<File
RelativePath="s_mp_rand_platform.c"
>
Expand Down
Loading