summaryrefslogtreecommitdiffstats
path: root/libtommath/tommath.h
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:55:16 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:55:16 (GMT)
commit0c568099ee71bd20c9b950c3be3dc53c55e80b93 (patch)
tree50b5db830e1da945cd2d1b497c1583c8e9bc1252 /libtommath/tommath.h
parent914d6e15467f0f0635f410f5915644ac40de618e (diff)
parent5753c7a42b638962406f9f7f822e48561e7a6253 (diff)
downloadtcl-0c568099ee71bd20c9b950c3be3dc53c55e80b93.zip
tcl-0c568099ee71bd20c9b950c3be3dc53c55e80b93.tar.gz
tcl-0c568099ee71bd20c9b950c3be3dc53c55e80b93.tar.bz2
Update libtommath to latest "develop"
Diffstat (limited to 'libtommath/tommath.h')
-rw-r--r--libtommath/tommath.h33
1 files changed, 18 insertions, 15 deletions
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index 50a3a81..51f703b 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -26,6 +26,11 @@
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__)
+# define MP_32BIT
+#endif
+
/* detect 64-bit mode if possible */
#if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) || \
defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || \
@@ -65,9 +70,7 @@ typedef uint32_t mp_word;
#elif defined(MP_64BIT)
/* for GCC only on supported platforms */
typedef uint64_t mp_digit;
-# if defined(_WIN32)
-typedef unsigned __int128 mp_word;
-# elif defined(__GNUC__)
+# if defined(__GNUC__)
typedef unsigned long mp_word __attribute__((mode(TI)));
# else
/* it seems you have a problem
@@ -104,7 +107,7 @@ typedef mp_digit mp_min_u32;
/* use arc4random on platforms that support it */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
# define MP_GEN_RANDOM() arc4random()
-# define MP_GEN_RANDOM_MAX 0xffffffff
+# define MP_GEN_RANDOM_MAX 0xffffffffu
#endif
/* use rand() as fall-back if there's no better rand function */
@@ -159,7 +162,7 @@ extern int KARATSUBA_MUL_CUTOFF,
#endif
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
-#define MP_WARRAY (1 << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1))
+#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1))
/* the infamous mp_int structure */
typedef struct {
@@ -394,7 +397,7 @@ int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
int mp_sqrt(const mp_int *arg, mp_int *ret);
/* special sqrt (mod prime) */
-int mp_sqrtmod_prime(const mp_int *arg, const mp_int *prime, mp_int *ret);
+int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret);
/* is number a square? */
int mp_is_square(const mp_int *arg, int *ret);
@@ -407,13 +410,13 @@ int mp_reduce_setup(mp_int *a, const mp_int *b);
/* Barrett Reduction, computes a (mod b) with a precomputed value c
*
- * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
- * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
+ * Assumes that 0 < x <= m*m, note if 0 > x > -(m*m) then you can merely
+ * compute the reduction as -1 * mp_reduce(mp_abs(x)) [pseudo code].
*/
-int mp_reduce(mp_int *a, const mp_int *b, const mp_int *c);
+int mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu);
/* setups the montgomery reduction */
-int mp_montgomery_setup(const mp_int *a, mp_digit *mp);
+int mp_montgomery_setup(const mp_int *n, mp_digit *rho);
/* computes a = B**n mod b without division or multiplication useful for
* normalizing numbers in a Montgomery system.
@@ -421,7 +424,7 @@ int mp_montgomery_setup(const mp_int *a, mp_digit *mp);
int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b);
/* computes x/R == x (mod N) via Montgomery Reduction */
-int mp_montgomery_reduce(mp_int *a, const mp_int *m, mp_digit mp);
+int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho);
/* returns 1 if a is a valid DR modulus */
int mp_dr_is_modulus(const mp_int *a);
@@ -429,8 +432,8 @@ int mp_dr_is_modulus(const mp_int *a);
/* sets the value of "d" required for mp_dr_reduce */
void mp_dr_setup(const mp_int *a, mp_digit *d);
-/* reduces a modulo b using the Diminished Radix method */
-int mp_dr_reduce(mp_int *a, const mp_int *b, mp_digit mp);
+/* reduces a modulo n using the Diminished Radix method */
+int mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k);
/* returns true if a can be reduced with mp_reduce_2k */
int mp_reduce_is_2k(const mp_int *a);
@@ -450,8 +453,8 @@ int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d);
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
int mp_reduce_2k_l(mp_int *a, const mp_int *n, const mp_int *d);
-/* d = a**b (mod c) */
-int mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
+/* Y = G**X (mod P) */
+int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y);
/* ---> Primes <--- */