summaryrefslogtreecommitdiffstats
path: root/libtommath
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-01 16:15:49 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-01 16:15:49 (GMT)
commitc848a8872a27a167d3eba3391874be66feb637c5 (patch)
tree1e54764a8fb316243c1143a4317dde7bf22de75b /libtommath
parent01c6f7705f0b241490d171673c2b3073083ce9cc (diff)
downloadtcl-c848a8872a27a167d3eba3391874be66feb637c5.zip
tcl-c848a8872a27a167d3eba3391874be66feb637c5.tar.gz
tcl-c848a8872a27a167d3eba3391874be66feb637c5.tar.bz2
Add compat/stdint.h, upgrade to libtommath 1.2.0, adapt as much as possible accordingly (still WIP)
Diffstat (limited to 'libtommath')
-rw-r--r--libtommath/bn_mp_expt_u32.c2
-rw-r--r--libtommath/makefile.mingw4
-rw-r--r--libtommath/tommath.h83
-rwxr-xr-xlibtommath/win32/libtommath.dllbin66560 -> 71680 bytes
-rw-r--r--libtommath/win32/tommath.libbin25364 -> 27422 bytes
-rwxr-xr-xlibtommath/win64/libtommath.dllbin75264 -> 81408 bytes
-rw-r--r--libtommath/win64/libtommath.dll.abin86060 -> 128166 bytes
-rwxr-xr-xlibtommath/win64/tommath.libbin24736 -> 26734 bytes
8 files changed, 65 insertions, 24 deletions
diff --git a/libtommath/bn_mp_expt_u32.c b/libtommath/bn_mp_expt_u32.c
index 67c8fd2..2ab67ba 100644
--- a/libtommath/bn_mp_expt_u32.c
+++ b/libtommath/bn_mp_expt_u32.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* calculate c = a**b using a square-multiply algorithm */
-mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c)
+mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
{
mp_err err;
diff --git a/libtommath/makefile.mingw b/libtommath/makefile.mingw
index 7eee57d..d9d17de 100644
--- a/libtommath/makefile.mingw
+++ b/libtommath/makefile.mingw
@@ -11,11 +11,11 @@
#The following can be overridden from command line e.g. make -f makefile.mingw CC=gcc ARFLAGS=rcs
PREFIX = c:\mingw
-CC = gcc
+CC = i686-w64-mingw32-gcc
AR = ar
ARFLAGS = r
RANLIB = ranlib
-STRIP = strip
+STRIP = i686-w64-mingw32-strip
CFLAGS = -O2
LDFLAGS =
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index 285fc8a..41d07fd 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -32,7 +32,7 @@ extern "C" {
#endif
/* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */
-#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_32BIT) && !defined(MP_64BIT)
+#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
# define MP_32BIT
#endif
@@ -61,23 +61,30 @@ extern "C" {
/* some default configurations.
*
* A "mp_digit" must be able to hold MP_DIGIT_BIT + 1 bits
+ * A "mp_word" must be able to hold 2*MP_DIGIT_BIT + 1 bits
*
* At the very least a mp_digit must be able to hold 7 bits
* [any size beyond that is ok provided it doesn't overflow the data type]
*/
#ifdef MP_8BIT
-typedef unsigned char mp_digit;
+typedef uint8_t mp_digit;
+typedef uint16_t private_mp_word;
# define MP_DIGIT_BIT 7
#elif defined(MP_16BIT)
-typedef unsigned short mp_digit;
+typedef uint16_t mp_digit;
+typedef uint32_t private_mp_word;
# define MP_DIGIT_BIT 15
#elif defined(MP_64BIT)
/* for GCC only on supported platforms */
-typedef unsigned long long mp_digit;
+typedef uint64_t mp_digit;
+#if defined(__GNUC__)
+typedef unsigned long private_mp_word __attribute__((mode(TI)));
+#endif
# define MP_DIGIT_BIT 60
#else
-typedef unsigned int mp_digit;
+typedef uint32_t mp_digit;
+typedef uint64_t private_mp_word;
# ifdef MP_31BIT
/*
* This is an extension that uses 31-bit digits.
@@ -93,6 +100,11 @@ typedef unsigned int mp_digit;
# endif
#endif
+/* mp_word is a private type */
+#define mp_word MP_DEPRECATED_PRAGMA("mp_word has been made private") private_mp_word
+
+#define MP_SIZEOF_MP_DIGIT (MP_DEPRECATED_PRAGMA("MP_SIZEOF_MP_DIGIT has been deprecated, use sizeof (mp_digit)") sizeof (mp_digit))
+
#define MP_MASK ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1))
#define MP_DIGIT_MAX MP_MASK
@@ -101,6 +113,10 @@ typedef unsigned int mp_digit;
#define MP_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
#define MP_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
+#define LTM_PRIME_BBS (MP_DEPRECATED_PRAGMA("LTM_PRIME_BBS has been deprecated, use MP_PRIME_BBS") MP_PRIME_BBS)
+#define LTM_PRIME_SAFE (MP_DEPRECATED_PRAGMA("LTM_PRIME_SAFE has been deprecated, use MP_PRIME_SAFE") MP_PRIME_SAFE)
+#define LTM_PRIME_2MSB_ON (MP_DEPRECATED_PRAGMA("LTM_PRIME_2MSB_ON has been deprecated, use MP_PRIME_2MSB_ON") MP_PRIME_2MSB_ON)
+
#ifdef MP_USE_ENUMS
typedef enum {
MP_ZPOS = 0, /* positive */
@@ -185,6 +201,10 @@ TOOM_SQR_CUTOFF;
# define MP_PREC (MP_DEPRECATED_PRAGMA("MP_PREC is an internal macro") PRIVATE_MP_PREC)
#endif
+/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
+#define PRIVATE_MP_WARRAY (int)(1uLL << (((CHAR_BIT * sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
+#define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") PRIVATE_MP_WARRAY)
+
#if defined(__GNUC__) && __GNUC__ >= 4
# define MP_NULL_TERMINATED __attribute__((sentinel))
#else
@@ -238,6 +258,10 @@ typedef struct {
mp_digit *dp;
} mp_int;
+/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
+typedef int private_mp_prime_callback(unsigned char *dst, int len, void *dat);
+typedef private_mp_prime_callback MP_DEPRECATED(mp_rand_source) ltm_prime_callback;
+
/* error code to char* string */
const char *mp_error_to_string(mp_err code) MP_WUR;
@@ -280,7 +304,6 @@ double mp_get_double(const mp_int *a) MP_WUR;
mp_err mp_set_double(mp_int *a, double b) MP_WUR;
/* get integer, set integer and init with integer (int32_t) */
-#ifndef MP_NO_STDINT
int32_t mp_get_i32(const mp_int *a) MP_WUR;
void mp_set_i32(mp_int *a, int32_t b);
mp_err mp_init_i32(mp_int *a, int32_t b) MP_WUR;
@@ -303,9 +326,8 @@ mp_err mp_init_u64(mp_int *a, uint64_t b) MP_WUR;
/* get magnitude */
uint32_t mp_get_mag_u32(const mp_int *a) MP_WUR;
uint64_t mp_get_mag_u64(const mp_int *a) MP_WUR;
-#endif
unsigned long mp_get_mag_ul(const mp_int *a) MP_WUR;
-Tcl_WideUInt mp_get_mag_ull(const mp_int *a) MP_WUR;
+unsigned long long mp_get_mag_ull(const mp_int *a) MP_WUR;
/* get integer, set integer (long) */
long mp_get_l(const mp_int *a) MP_WUR;
@@ -317,15 +339,15 @@ mp_err mp_init_l(mp_int *a, long b) MP_WUR;
void mp_set_ul(mp_int *a, unsigned long b);
mp_err mp_init_ul(mp_int *a, unsigned long b) MP_WUR;
-/* get integer, set integer (Tcl_WideInt) */
-Tcl_WideInt mp_get_ll(const mp_int *a) MP_WUR;
-void mp_set_ll(mp_int *a, Tcl_WideInt b);
-mp_err mp_init_ll(mp_int *a, Tcl_WideInt b) MP_WUR;
+/* get integer, set integer (long long) */
+long long mp_get_ll(const mp_int *a) MP_WUR;
+void mp_set_ll(mp_int *a, long long b);
+mp_err mp_init_ll(mp_int *a, long long b) MP_WUR;
-/* get integer, set integer (Tcl_WideUInt) */
-#define mp_get_ull(a) ((Tcl_WideUInt)mp_get_ll(a))
-void mp_set_ull(mp_int *a, Tcl_WideUInt b);
-mp_err mp_init_ull(mp_int *a, Tcl_WideUInt b) MP_WUR;
+/* get integer, set integer (unsigned long long) */
+#define mp_get_ull(a) ((unsigned long long)mp_get_ll(a))
+void mp_set_ull(mp_int *a, unsigned long long b);
+mp_err mp_init_ull(mp_int *a, unsigned long long b) MP_WUR;
/* set to single unsigned digit, up to MP_DIGIT_MAX */
void mp_set(mp_int *a, mp_digit b);
@@ -334,10 +356,10 @@ mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR;
/* get integer, set integer and init with integer (deprecated) */
MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_get_mag_ul/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR;
-MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) Tcl_WideUInt mp_get_long_long(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b);
MP_DEPRECATED(mp_set_ul) mp_err mp_set_long(mp_int *a, unsigned long b);
-MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, Tcl_WideUInt b);
+MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, unsigned long long b);
MP_DEPRECATED(mp_init_ul) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR;
/* copy, b = a */
@@ -534,7 +556,7 @@ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
*
* returns error if a < 0 and b is even
*/
-mp_err mp_root_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR;
+mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
@@ -614,6 +636,12 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
#endif
#define PRIME_SIZE (MP_DEPRECATED_PRAGMA("PRIME_SIZE has been made internal") PRIVATE_MP_PRIME_TAB_SIZE)
+/* table of first PRIME_SIZE primes */
+MP_DEPRECATED(internal) extern const mp_digit ltm_prime_tab[PRIVATE_MP_PRIME_TAB_SIZE];
+
+/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
+MP_DEPRECATED(mp_prime_is_prime) mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result) MP_WUR;
+
/* performs one Fermat test of "a" using base "b".
* Sets result to 0 if composite or 1 if probable prime
*/
@@ -662,6 +690,17 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result) MP_WUR;
*/
mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR;
+/* makes a truly random prime of a given size (bytes),
+ * call with bbs = 1 if you want it to be congruent to 3 mod 4
+ *
+ * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
+ * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
+ * so it can be NULL
+ *
+ * The prime generated will be larger than 2^(8*size).
+ */
+#define mp_prime_random(a, t, size, bbs, cb, dat) (MP_DEPRECATED_PRAGMA("mp_prime_random has been deprecated, use mp_prime_rand instead") mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?MP_PRIME_BBS:0, cb, dat))
+
/* makes a truly random prime of a given size (bits),
*
* Flags are as follows:
@@ -675,13 +714,15 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR;
* so it can be NULL
*
*/
+MP_DEPRECATED(mp_prime_rand) mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags,
+ private_mp_prime_callback cb, void *dat) MP_WUR;
mp_err mp_prime_rand(mp_int *a, int t, int size, int flags) MP_WUR;
/* Integer logarithm to integer base */
-mp_err mp_log_u32(const mp_int *a, unsigned int base, unsigned int *c) MP_WUR;
+mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) MP_WUR;
/* c = a**b */
-mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR;
+mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
diff --git a/libtommath/win32/libtommath.dll b/libtommath/win32/libtommath.dll
index 4497517..aa0a8cb 100755
--- a/libtommath/win32/libtommath.dll
+++ b/libtommath/win32/libtommath.dll
Binary files differ
diff --git a/libtommath/win32/tommath.lib b/libtommath/win32/tommath.lib
index bc866fb..8cf1ea0 100644
--- a/libtommath/win32/tommath.lib
+++ b/libtommath/win32/tommath.lib
Binary files differ
diff --git a/libtommath/win64/libtommath.dll b/libtommath/win64/libtommath.dll
index 77d685b..2225faf 100755
--- a/libtommath/win64/libtommath.dll
+++ b/libtommath/win64/libtommath.dll
Binary files differ
diff --git a/libtommath/win64/libtommath.dll.a b/libtommath/win64/libtommath.dll.a
index 54a76d7..40adaf7 100644
--- a/libtommath/win64/libtommath.dll.a
+++ b/libtommath/win64/libtommath.dll.a
Binary files differ
diff --git a/libtommath/win64/tommath.lib b/libtommath/win64/tommath.lib
index 9b0e7ad..515d21f 100755
--- a/libtommath/win64/tommath.lib
+++ b/libtommath/win64/tommath.lib
Binary files differ