From 7cb32717a995bee029ee18710b3e25e8e73f7377 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 28 Jan 2019 21:53:18 +0000 Subject: Update to libtommath v1.1.0 --- libtommath/bn_mp_prime_is_prime.c | 11 +- libtommath/changes.txt | 22 + libtommath/libtommath_VS2008.sln | 29 ++ libtommath/libtommath_VS2008.vcproj | 890 ++++++++++++++++++++++++++++++++++++ libtommath/makefile | 2 + libtommath/makefile.shared | 1 + libtommath/makefile.unix | 2 +- libtommath/makefile_include.mk | 6 +- libtommath/tommath.h | 7 +- libtommath/tommath_class.h | 1 + 10 files changed, 958 insertions(+), 13 deletions(-) create mode 100644 libtommath/libtommath_VS2008.sln create mode 100644 libtommath/libtommath_VS2008.vcproj diff --git a/libtommath/bn_mp_prime_is_prime.c b/libtommath/bn_mp_prime_is_prime.c index 8d96e6a..15637c8 100644 --- a/libtommath/bn_mp_prime_is_prime.c +++ b/libtommath/bn_mp_prime_is_prime.c @@ -71,7 +71,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) } #ifdef MP_8BIT /* The search in the loop above was exhaustive in this case */ - if (a->used == 1 && PRIME_SIZE >= 31) { + if ((a->used == 1) && (PRIME_SIZE >= 31)) { return MP_OKAY; } #endif @@ -126,7 +126,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) */ #if defined (MP_8BIT) || defined (LTM_USE_FROBENIUS_TEST) err = mp_prime_frobenius_underwood(a, &res); - if (err != MP_OKAY && err != MP_ITER) { + if ((err != MP_OKAY) && (err != MP_ITER)) { goto LBL_B; } if (res == MP_NO) { @@ -296,7 +296,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) * One 8-bit digit is too small, so concatenate two if the size of * unsigned int allows for it. */ - if ((sizeof(unsigned int) * CHAR_BIT)/2 >= (sizeof(mp_digit) * CHAR_BIT)) { + if (((sizeof(unsigned int) * CHAR_BIT)/2) >= (sizeof(mp_digit) * CHAR_BIT)) { if ((err = mp_rand(&b, 1)) != MP_OKAY) { goto LBL_B; } @@ -305,10 +305,9 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) fips_rand &= mask; } #endif - if (fips_rand > ((unsigned int) INT_MAX - DIGIT_BIT)) { + if (fips_rand > (unsigned int)(INT_MAX - DIGIT_BIT)) { len = INT_MAX / DIGIT_BIT; - } - else { + } else { len = (((int)fips_rand + DIGIT_BIT) / DIGIT_BIT); } /* Unlikely. */ diff --git a/libtommath/changes.txt b/libtommath/changes.txt index 51da801..aa0c64c 100644 --- a/libtommath/changes.txt +++ b/libtommath/changes.txt @@ -1,3 +1,25 @@ +Jan 28th, 2019 +v1.1.0 + -- Christoph Zurnieden contributed FIPS 186.4 compliant + prime-checking (PR #113), several other fixes and a load of documentation + -- Daniel Mendler provided two's-complement functions (PR #124) + and mp_{set,get}_double() (PR #123) + -- Francois Perrad took care of linting the sources, provided all fixes and + a astylerc to auto-format the sources. + -- A bunch of patches by Kevin B Kenny have been back-ported from TCL + -- Jan Nijtmans provided the patches to `const`ify all API + function arguments (also from TCL) + -- mp_rand() has now several native random provider implementations + and doesn't rely on `rand()` anymore + -- Karel Miko provided fixes when building for MS Windows + and re-worked the makefile generating process + -- The entire environment and build logic has been extended and improved + regarding auto-detection of platforms, libtool and a lot more + -- Prevent some potential BOF cases + -- Improved/fixed mp_lshd() and mp_invmod() + -- A load more bugs were fixed by various contributors + + Aug 29th, 2017 v1.0.1 -- Dmitry Kovalenko provided fixes to mp_add_d() and mp_init_copy() diff --git a/libtommath/libtommath_VS2008.sln b/libtommath/libtommath_VS2008.sln new file mode 100644 index 0000000..6bfc159 --- /dev/null +++ b/libtommath/libtommath_VS2008.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tommath", "libtommath_VS2008.vcproj", "{42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.ActiveCfg = Debug|Win32 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|Win32.Build.0 = Debug|Win32 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|x64.ActiveCfg = Debug|x64 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Debug|x64.Build.0 = Debug|x64 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.ActiveCfg = Release|Win32 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|Win32.Build.0 = Release|Win32 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|x64.ActiveCfg = Release|x64 + {42109FEE-B0B9-4FCD-9E56-2863BF8C55D2}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {83B84178-7B4F-4B78-9C5D-17B8201D5B61} + EndGlobalSection +EndGlobal diff --git a/libtommath/libtommath_VS2008.vcproj b/libtommath/libtommath_VS2008.vcproj new file mode 100644 index 0000000..5b2637b --- /dev/null +++ b/libtommath/libtommath_VS2008.vcproj @@ -0,0 +1,890 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libtommath/makefile b/libtommath/makefile index 4e5f0f1..a07c274 100644 --- a/libtommath/makefile +++ b/libtommath/makefile @@ -141,6 +141,8 @@ zipup: clean astyle new_file manual poster docs $(MAKE) -C libtommath-$(VERSION)/ pre_gen tar -c libtommath-$(VERSION)/ | xz -6e -c - > ltm-$(VERSION).tar.xz zip -9rq ltm-$(VERSION).zip libtommath-$(VERSION) + cp doc/bn.pdf bn-$(VERSION).pdf + cp doc/tommath.pdf tommath-$(VERSION).pdf rm -rf libtommath-$(VERSION) gpg -b -a ltm-$(VERSION).tar.xz gpg -b -a ltm-$(VERSION).zip diff --git a/libtommath/makefile.shared b/libtommath/makefile.shared index d5d1818..3955f83 100644 --- a/libtommath/makefile.shared +++ b/libtommath/makefile.shared @@ -83,6 +83,7 @@ test_standalone: $(LIBNAME) demo/demo.o $(CC) $(CFLAGS) -c demo/demo.c -o demo/demo.o $(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -o test demo/demo.o $(LIBNAME) +.PHONY: mtest mtest: cd mtest ; $(CC) $(CFLAGS) $(LDFLAGS) mtest.c -o mtest diff --git a/libtommath/makefile.unix b/libtommath/makefile.unix index a51b973..b89cf47 100644 --- a/libtommath/makefile.unix +++ b/libtommath/makefile.unix @@ -21,7 +21,7 @@ RANLIB = ranlib CFLAGS = -O2 LDFLAGS = -VERSION = 1.0.1 +VERSION = 1.1.0 #Compilation flags LTM_CFLAGS = -I. $(CFLAGS) diff --git a/libtommath/makefile_include.mk b/libtommath/makefile_include.mk index 4814593..ec2205b 100644 --- a/libtommath/makefile_include.mk +++ b/libtommath/makefile_include.mk @@ -3,9 +3,9 @@ # #version of library -VERSION=1.0.1 -VERSION_PC=1.0.1 -VERSION_SO=1:1 +VERSION=1.1.0 +VERSION_PC=1.1.0 +VERSION_SO=2:0:1 PLATFORM := $(shell uname | sed -e 's/_.*//') diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 6469edf..ee5da86 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -283,9 +283,10 @@ int mp_rand(mp_int *a, int digits); int mp_rand_digit(mp_digit *r); #ifdef MP_PRNG_ENABLE_LTM_RNG -/* as last resort we will fall back to libtomcrypt's rng_get_bytes() - * in case you don't use libtomcrypt or use it w/o rng_get_bytes() - * you have to implement it somewhere else, as it's required */ +/* A last resort to provide random data on systems without any of the other + * implemented ways to gather entropy. + * It is compatible with `rng_get_bytes()` from libtomcrypt so you could + * provide that one and then set `ltm_rng = rng_get_bytes;` */ extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); extern void (*ltm_rng_callback)(void); #endif diff --git a/libtommath/tommath_class.h b/libtommath/tommath_class.h index 6363042..46f9996 100644 --- a/libtommath/tommath_class.h +++ b/libtommath/tommath_class.h @@ -9,6 +9,7 @@ * * SPDX-License-Identifier: Unlicense */ + #if !(defined(LTM1) && defined(LTM2) && defined(LTM3)) #if defined(LTM2) # define LTM3 -- cgit v0.12