summaryrefslogtreecommitdiffstats
path: root/libtommath/tommath_private.h
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath/tommath_private.h')
-rw-r--r--libtommath/tommath_private.h69
1 files changed, 30 insertions, 39 deletions
diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h
index 29607d4..61d382d 100644
--- a/libtommath/tommath_private.h
+++ b/libtommath/tommath_private.h
@@ -1,11 +1,12 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
-#ifndef TOMMATH_PRIV_H_
-#define TOMMATH_PRIV_H_
+#ifndef TOMMATH_PRIVATE_H_
+#define TOMMATH_PRIVATE_H_
#include <tommath.h>
#include "tommath_class.h"
+#include <limits.h>
/*
* Private symbols
@@ -117,11 +118,6 @@ do { \
# define MP_KARATSUBA_SQR_CUTOFF MP_DEFAULT_KARATSUBA_SQR_CUTOFF
# define MP_TOOM_MUL_CUTOFF MP_DEFAULT_TOOM_MUL_CUTOFF
# define MP_TOOM_SQR_CUTOFF MP_DEFAULT_TOOM_SQR_CUTOFF
-#else
-# define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
-# define MP_KARATSUBA_SQR_CUTOFF KARATSUBA_SQR_CUTOFF
-# define MP_TOOM_MUL_CUTOFF TOOM_MUL_CUTOFF
-# define MP_TOOM_SQR_CUTOFF TOOM_SQR_CUTOFF
#endif
/* define heap macros */
@@ -163,10 +159,27 @@ extern void MP_FREE(void *mem, size_t size);
#define MP_SIZEOF_BITS(type) ((size_t)CHAR_BIT * sizeof(type))
#define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
-/* TODO: Remove PRIVATE_MP_PREC as soon as deprecated MP_PREC is removed from tommath.h */
-#ifdef PRIVATE_MP_PREC
-# undef MP_PREC
-# define MP_PREC PRIVATE_MP_PREC
+#define PRIVATE_MP_WARRAY (1 << ((MP_SIZEOF_BITS(mp_word) - (2 * MP_DIGIT_BIT)) + 1))
+
+#if defined(MP_16BIT)
+typedef unsigned int mp_word;
+#elif defined(MP_64BIT) && defined(__GNUC__)
+typedef unsigned long mp_word __attribute__((mode(TI)));
+#elif defined(_WIN32)
+typedef unsigned __int64 mp_word;
+#else
+typedef unsigned long long mp_word;
+#endif
+
+MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == 2 * sizeof(mp_digit))
+
+/* default precision */
+#ifndef MP_PREC
+# ifndef MP_LOW_MEM
+# define MP_PREC 32 /* default digits of precision */
+# else
+# define MP_PREC 8 /* default digits of precision */
+# endif
#endif
/* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */
@@ -198,7 +211,8 @@ MP_PRIVATE mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_dig
MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
MP_PRIVATE mp_err s_mp_rand_platform(void *p, size_t n) MP_WUR;
-MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat);
+typedef int mp_prime_callback(unsigned char *dst, int len, void *dat);
+MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat);
MP_PRIVATE void s_mp_reverse(unsigned char *s, size_t len);
MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result);
@@ -208,33 +222,10 @@ MP_PRIVATE mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
MP_PRIVATE void s_mp_rand_jenkins_init(uint64_t seed);
#endif
-extern MP_PRIVATE const char *const mp_s_rmap;
-extern MP_PRIVATE const unsigned char mp_s_rmap_reverse[];
-extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
-extern MP_PRIVATE const mp_digit *s_mp_prime_tab;
-
-/* deprecated functions */
-#if 0
-MP_DEPRECATED(s_mp_invmod_fast) mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
-MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n,
- mp_digit rho);
-MP_DEPRECATED(s_mp_mul_digs_fast) mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c,
- int digs);
-MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b,
- mp_int *c,
- int digs);
-MP_DEPRECATED(s_mp_sqr_fast) mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b);
-MP_DEPRECATED(s_mp_balance_mul) mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c);
-MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P,
- mp_int *Y,
- int redmode);
-MP_DEPRECATED(s_mp_invmod_slow) mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c);
-MP_DEPRECATED(s_mp_karatsuba_mul) mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);
-MP_DEPRECATED(s_mp_karatsuba_sqr) mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b);
-MP_DEPRECATED(s_mp_toom_mul) mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c);
-MP_DEPRECATED(s_mp_toom_sqr) mp_err mp_toom_sqr(const mp_int *a, mp_int *b);
-MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len);
-#endif
+#define MP_RMAP_REVERSE_SIZE 88
+extern MP_PRIVATE const char s_mp_rmap[];
+extern MP_PRIVATE const unsigned char s_mp_rmap_reverse[];
+extern MP_PRIVATE const mp_digit s_mp_prime_tab[];
#define MP_GET_ENDIANNESS(x) \
do{\