summaryrefslogtreecommitdiffstats
path: root/generic/tclTomMath.h
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 08:31:55 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 08:31:55 (GMT)
commita187f65cfd5964971d7ed52f09e18fdbb4bf51cc (patch)
tree6b7bbde03122d1571d4543d10eccfe88610bd680 /generic/tclTomMath.h
parent0faaca01de4e9fa2039c7fdd34f60b138f665249 (diff)
parent30f7e69b182d1267056ee2628a860891f6555aa3 (diff)
downloadtcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.zip
tcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.tar.gz
tcl-a187f65cfd5964971d7ed52f09e18fdbb4bf51cc.tar.bz2
Merge libtommath upstream changes (astyle formatting only). No functional changes. All Tcl-specific modifications are kept.
Diffstat (limited to 'generic/tclTomMath.h')
-rw-r--r--generic/tclTomMath.h156
1 files changed, 78 insertions, 78 deletions
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index 34ac1bb..14cf5b6 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -28,9 +28,9 @@ extern "C" {
/* detect 64-bit mode if possible */
#if defined(NEVER) /* 128-bit ints fail in too many places */
- #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
- #define MP_64BIT
- #endif
+# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# define MP_64BIT
+# endif
#endif
/* some default configurations.
@@ -43,94 +43,94 @@ extern "C" {
*/
#ifdef MP_8BIT
#ifndef MP_DIGIT_DECLARED
- typedef uint8_t mp_digit;
+typedef uint8_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint16_t mp_word;
+typedef uint16_t mp_word;
#define MP_WORD_DECLARED
#endif
-#define MP_SIZEOF_MP_DIGIT 1
-#ifdef DIGIT_BIT
-#error You must not define DIGIT_BIT when using MP_8BIT
-#endif
+# define MP_SIZEOF_MP_DIGIT 1
+# ifdef DIGIT_BIT
+# error You must not define DIGIT_BIT when using MP_8BIT
+# endif
#elif defined(MP_16BIT)
#ifndef MP_DIGIT_DECLARED
- typedef uint16_t mp_digit;
+typedef uint16_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint32_t mp_word;
+typedef uint32_t mp_word;
#define MP_WORD_DECLARED
#endif
-#define MP_SIZEOF_MP_DIGIT 2
-#ifdef DIGIT_BIT
-#error You must not define DIGIT_BIT when using MP_16BIT
-#endif
+# define MP_SIZEOF_MP_DIGIT 2
+# ifdef DIGIT_BIT
+# error You must not define DIGIT_BIT when using MP_16BIT
+# endif
#elif defined(MP_64BIT)
- /* for GCC only on supported platforms */
+/* for GCC only on supported platforms */
#ifndef MP_DIGIT_DECLARED
- typedef uint64_t mp_digit;
+typedef uint64_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
-#if defined(_WIN32)
+# if defined(_WIN32)
#ifndef MP_WORD_DECLARED
- typedef unsigned __int128 mp_word;
+typedef unsigned __int128 mp_word;
#define MP_WORD_DECLARED
#endif
-#elif defined(__GNUC__)
- typedef unsigned long mp_word __attribute__ ((mode(TI)));
-#else
- /* it seems you have a problem
- * but we assume you can somewhere define your own uint128_t */
+# elif defined(__GNUC__)
+typedef unsigned long mp_word __attribute__((mode(TI)));
+# else
+/* it seems you have a problem
+ * but we assume you can somewhere define your own uint128_t */
#ifndef MP_WORD_DECLARED
- typedef uint128_t mp_word;
+typedef uint128_t mp_word;
#define MP_WORD_DECLARED
#endif
-#endif
+# endif
- #define DIGIT_BIT 60
+# define DIGIT_BIT 60
#else
- /* this is the default case, 28-bit digits */
+/* this is the default case, 28-bit digits */
- /* this is to make porting into LibTomCrypt easier :-) */
+/* this is to make porting into LibTomCrypt easier :-) */
#ifndef MP_DIGIT_DECLARED
- typedef uint32_t mp_digit;
+typedef uint32_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint64_t mp_word;
+typedef uint64_t mp_word;
#define MP_WORD_DECLARED
#endif
-#ifdef MP_31BIT
- /* this is an extension that uses 31-bit digits */
- #define DIGIT_BIT 31
-#else
- /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
- #define DIGIT_BIT 28
- #define MP_28BIT
-#endif
+# ifdef MP_31BIT
+/* this is an extension that uses 31-bit digits */
+# define DIGIT_BIT 31
+# else
+/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
+# define DIGIT_BIT 28
+# define MP_28BIT
+# endif
#endif
/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
#ifndef DIGIT_BIT
- #define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
- typedef uint_least32_t mp_min_u32;
+# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
+typedef uint_least32_t mp_min_u32;
#else
- typedef mp_digit mp_min_u32;
+typedef mp_digit mp_min_u32;
#endif
/* 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() arc4random()
+# define MP_GEN_RANDOM_MAX 0xffffffff
#endif
/* use rand() as fall-back if there's no better rand function */
#ifndef MP_GEN_RANDOM
- #define MP_GEN_RANDOM() rand()
- #define MP_GEN_RANDOM_MAX RAND_MAX
+# define MP_GEN_RANDOM() rand()
+# define MP_GEN_RANDOM_MAX RAND_MAX
#endif
#define MP_DIGIT_BIT DIGIT_BIT
@@ -163,9 +163,9 @@ typedef int mp_err;
/* you'll have to tune these... */
#if defined(BUILD_tcl) || !defined(_WIN32)
MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
- KARATSUBA_SQR_CUTOFF,
- TOOM_MUL_CUTOFF,
- TOOM_SQR_CUTOFF;
+ KARATSUBA_SQR_CUTOFF,
+ TOOM_MUL_CUTOFF,
+ TOOM_SQR_CUTOFF;
#endif
/* define this to use lower memory usage routines (exptmods mostly) */
@@ -173,11 +173,11 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
/* 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
+# ifndef MP_LOW_MEM
+# define MP_PREC 32 /* default digits of precision */
+# else
+# define MP_PREC 8 /* default digits of precision */
+# endif
#endif
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
@@ -189,17 +189,17 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
typedef struct mp_int mp_int;
#endif
struct mp_int {
- int used, alloc, sign;
- mp_digit *dp;
+ int used, alloc, sign;
+ mp_digit *dp;
};
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
-#define USED(m) ((m)->used)
-#define DIGIT(m,k) ((m)->dp[(k)])
-#define SIGN(m) ((m)->sign)
+#define USED(m) ((m)->used)
+#define DIGIT(m, k) ((m)->dp[(k)])
+#define SIGN(m) ((m)->sign)
/* error code to char* string */
const char *mp_error_to_string(int code);
@@ -278,27 +278,27 @@ int mp_set_long_long(mp_int *a, Tcl_WideUInt b);
/* get a 32-bit value */
/*
-unsigned long mp_get_int(const mp_int * a);
+unsigned long mp_get_int(const mp_int *a);
*/
/* get a platform dependent unsigned long value */
/*
-unsigned long mp_get_long(const mp_int * a);
+unsigned long mp_get_long(const mp_int *a);
*/
/* get a platform dependent unsigned long long value */
/*
-Tcl_WideUInt mp_get_long_long(const mp_int * a);
+Tcl_WideUInt mp_get_long_long(const mp_int *a);
*/
/* initialize and set a digit */
/*
-int mp_init_set (mp_int * a, mp_digit b);
+int mp_init_set(mp_int *a, mp_digit b);
*/
/* initialize and set 32-bit value */
/*
-int mp_init_set_int (mp_int * a, unsigned long b);
+int mp_init_set_int(mp_int *a, unsigned long b);
*/
/* copy, b = a */
@@ -318,12 +318,12 @@ void mp_clamp(mp_int *a);
/* import binary data */
/*
-int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op);
+int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op);
*/
/* export binary data */
/*
-int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op);
+int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op);
*/
/* ---> digit manipulation <--- */
@@ -457,7 +457,7 @@ int mp_cmp_d(const mp_int *a, mp_digit b);
/* c = a + b */
/*
-int mp_add_d(const mp_int *a, const mp_digit b, mp_int *c);
+int mp_add_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* c = a - b */
@@ -482,10 +482,10 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d);
/* c = a**b */
/*
-int mp_expt_d(const mp_int *a, const mp_digit b, mp_int *c);
+int mp_expt_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/*
-int mp_expt_d_ex (const mp_int * a, const mp_digit b, mp_int * c, int fast);
+int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
*/
/* c = a mod b, 0 <= c < b */
@@ -543,12 +543,12 @@ int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
*/
/*
-int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
+int mp_n_root_ex(mp_int *a, mp_digit b, mp_int *c, int fast);
*/
/* special sqrt algo */
/*
-int mp_sqrt(mp_int *arg, mp_int *ret);
+int mp_sqrt(const mp_int *arg, mp_int *ret);
*/
/* special sqrt (mod prime) */
@@ -651,9 +651,9 @@ int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
/* number of primes */
#ifdef MP_8BIT
-# define PRIME_SIZE 31
+# define PRIME_SIZE 31
#else
-# define PRIME_SIZE 256
+# define PRIME_SIZE 256
#endif
/* table of first PRIME_SIZE primes */
@@ -741,7 +741,7 @@ int mp_count_bits(const mp_int *a);
*/
/*
-int mp_unsigned_bin_size(mp_int *a);
+int mp_unsigned_bin_size(const mp_int *a);
*/
/*
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
@@ -750,7 +750,7 @@ int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
int mp_to_unsigned_bin(const mp_int *a, unsigned char *b);
*/
/*
-int mp_to_unsigned_bin_n (const mp_int * a, unsigned char *b, unsigned long *outlen);
+int mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
*/
/*
@@ -763,7 +763,7 @@ int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
int mp_to_signed_bin(const mp_int *a, unsigned char *b);
*/
/*
-int mp_to_signed_bin_n (const mp_int * a, unsigned char *b, unsigned long *outlen);
+int mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
*/
/*
@@ -773,7 +773,7 @@ int mp_read_radix(mp_int *a, const char *str, int radix);
int mp_toradix(const mp_int *a, char *str, int radix);
*/
/*
-int mp_toradix_n(const mp_int * a, char *str, int radix, int maxlen);
+int mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen);
*/
/*
int mp_radix_size(const mp_int *a, int radix, int *size);
@@ -801,7 +801,7 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream);
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
#ifdef __cplusplus
- }
+}
#endif
#endif