summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-04-10 22:16:39 (GMT)
committerGuido van Rossum <guido@python.org>1998-04-10 22:16:39 (GMT)
commit1109fbca76d08bb2f11f2899580d2ab7dbe796fa (patch)
treed52f999b597674ea5648059207a1eccaf173e141
parentbb3649e2ba386adc16fadc2e0d1f2606c047e6aa (diff)
downloadcpython-1109fbca76d08bb2f11f2899580d2ab7dbe796fa.zip
cpython-1109fbca76d08bb2f11f2899580d2ab7dbe796fa.tar.gz
cpython-1109fbca76d08bb2f11f2899580d2ab7dbe796fa.tar.bz2
Make new gcc -Wall happy
-rw-r--r--Objects/fileobject.c9
-rw-r--r--Objects/funcobject.c3
-rw-r--r--Objects/longobject.c2
-rw-r--r--Objects/stringobject.c6
4 files changed, 13 insertions, 7 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 51752abc..49517c5 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -190,10 +190,12 @@ file_dealloc(f)
(*f->f_close)(f->f_fp);
Py_END_ALLOW_THREADS
}
- if (f->f_name != NULL)
+ if (f->f_name != NULL) {
Py_DECREF(f->f_name);
- if (f->f_mode != NULL)
+ }
+ if (f->f_mode != NULL) {
Py_DECREF(f->f_mode);
+ }
free((char *)f);
}
@@ -771,8 +773,9 @@ file_readlines(f, args)
goto error;
}
cleanup:
- if (big_buffer)
+ if (big_buffer) {
Py_DECREF(big_buffer);
+ }
return list;
}
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index be67259..d62dd08 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -110,8 +110,9 @@ PyFunction_SetDefaults(op, defaults)
}
if (defaults == Py_None)
defaults = NULL;
- else if (PyTuple_Check(defaults))
+ else if (PyTuple_Check(defaults)) {
Py_XINCREF(defaults);
+ }
else {
PyErr_SetString(PyExc_SystemError, "non-tuple default args");
return -1;
diff --git a/Objects/longobject.c b/Objects/longobject.c
index d95e86c..becf1bc 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -497,7 +497,7 @@ PyLong_FromString(str, pend, base)
static PyLongObject *x_divrem
Py_PROTO((PyLongObject *, PyLongObject *, PyLongObject **));
static PyObject *long_pos Py_PROTO((PyLongObject *));
-static long_divrem Py_PROTO((PyLongObject *, PyLongObject *,
+static int long_divrem Py_PROTO((PyLongObject *, PyLongObject *,
PyLongObject **, PyLongObject **));
/* Long division with remainder, top-level routine */
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 5928128..5e6a5a5 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1016,14 +1016,16 @@ PyString_Format(format, args)
"not all arguments converted");
goto error;
}
- if (args_owned)
+ if (args_owned) {
Py_DECREF(args);
+ }
_PyString_Resize(&result, reslen - rescnt);
return result;
error:
Py_DECREF(result);
- if (args_owned)
+ if (args_owned) {
Py_DECREF(args);
+ }
return NULL;
}
tion value='bug_io_32_11'>bug_io_32_11 Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 10:07:04 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-18 10:07:04 (GMT)
commit9f37d4b63516a557ffcda81ba467f0c6e8be5a08 (patch)
treef8a9ee54ec9774190df9bbf38a28d2c4ad39f6b1
parent4d7363037476c86fe1c170e39f8b832fcec4feb2 (diff)
parenta187f65cfd5964971d7ed52f09e18fdbb4bf51cc (diff)
downloadtcl-9f37d4b63516a557ffcda81ba467f0c6e8be5a08.zip
tcl-9f37d4b63516a557ffcda81ba467f0c6e8be5a08.tar.gz
tcl-9f37d4b63516a557ffcda81ba467f0c6e8be5a08.tar.bz2
Merge trunk
Diffstat
-rw-r--r--generic/tclTomMath.h156
-rw-r--r--libtommath/astylerc27
-rw-r--r--libtommath/bn_error.c16
-rw-r--r--libtommath/bn_fast_mp_invmod.c223
-rw-r--r--libtommath/bn_fast_mp_montgomery_reduce.c270
-rw-r--r--libtommath/bn_fast_s_mp_mul_digs.c80
-rw-r--r--libtommath/bn_fast_s_mp_mul_high_digs.c70
-rw-r--r--libtommath/bn_fast_s_mp_sqr.c80
-rw-r--r--libtommath/bn_mp_2expt.c28
-rw-r--r--libtommath/bn_mp_abs.c24
-rw-r--r--libtommath/bn_mp_add.c48
-rw-r--r--libtommath/bn_mp_add_d.c172
-rw-r--r--libtommath/bn_mp_addmod.c26
-rw-r--r--libtommath/bn_mp_and.c56
-rw-r--r--libtommath/bn_mp_clamp.c24
-rw-r--r--libtommath/bn_mp_clear.c30
-rw-r--r--libtommath/bn_mp_clear_multi.c18
-rw-r--r--libtommath/bn_mp_cmp.c34
-rw-r--r--libtommath/bn_mp_cmp_d.c34
-rw-r--r--libtommath/bn_mp_cmp_mag.c54
-rw-r--r--libtommath/bn_mp_cnt_lsb.c2
-rw-r--r--libtommath/bn_mp_copy.c66
-rw-r--r--libtommath/bn_mp_count_bits.c34
-rw-r--r--libtommath/bn_mp_div.c453
-rw-r--r--libtommath/bn_mp_div_2.c70
-rw-r--r--libtommath/bn_mp_div_2d.c100
-rw-r--r--libtommath/bn_mp_div_3.c86
-rw-r--r--libtommath/bn_mp_div_d.c124
-rw-r--r--libtommath/bn_mp_dr_is_modulus.c6
-rw-r--r--libtommath/bn_mp_dr_reduce.c84
-rw-r--r--libtommath/bn_mp_dr_setup.c4
-rw-r--r--libtommath/bn_mp_exch.c12
-rw-r--r--libtommath/bn_mp_export.c123
-rw-r--r--libtommath/bn_mp_expt_d.c4
-rw-r--r--libtommath/bn_mp_expt_d_ex.c95
-rw-r--r--libtommath/bn_mp_exptmod.c114
-rw-r--r--libtommath/bn_mp_exptmod_fast.c487
-rw-r--r--libtommath/bn_mp_exteuclid.c92
-rw-r--r--libtommath/bn_mp_fread.c18
-rw-r--r--libtommath/bn_mp_fwrite.c22
-rw-r--r--libtommath/bn_mp_gcd.c140
-rw-r--r--libtommath/bn_mp_get_int.c30
-rw-r--r--libtommath/bn_mp_get_long.c28
-rw-r--r--libtommath/bn_mp_get_long_long.c28
-rw-r--r--libtommath/bn_mp_grow.c56
-rw-r--r--libtommath/bn_mp_import.c75
-rw-r--r--libtommath/bn_mp_init.c32
-rw-r--r--libtommath/bn_mp_init_copy.c18
-rw-r--r--libtommath/bn_mp_init_multi.c58
-rw-r--r--libtommath/bn_mp_init_set.c14
-rw-r--r--libtommath/bn_mp_init_set_int.c12
-rw-r--r--libtommath/bn_mp_init_size.c36
-rw-r--r--libtommath/bn_mp_invmod.c22
-rw-r--r--libtommath/bn_mp_invmod_slow.c247
-rw-r--r--libtommath/bn_mp_is_square.c137
-rw-r--r--libtommath/bn_mp_jacobi.c152
-rw-r--r--libtommath/bn_mp_karatsuba_mul.c263
-rw-r--r--libtommath/bn_mp_karatsuba_sqr.c190
-rw-r--r--libtommath/bn_mp_lcm.c66
-rw-r--r--libtommath/bn_mp_lshd.c68
-rw-r--r--libtommath/bn_mp_mod.c36
-rw-r--r--libtommath/bn_mp_mod_2d.c50
-rw-r--r--libtommath/bn_mp_mod_d.c4
-rw-r--r--libtommath/bn_mp_montgomery_calc_normalization.c46
-rw-r--r--libtommath/bn_mp_montgomery_reduce.c178
-rw-r--r--libtommath/bn_mp_montgomery_setup.c44
-rw-r--r--libtommath/bn_mp_mul.c62
-rw-r--r--libtommath/bn_mp_mul_2.c100
-rw-r--r--libtommath/bn_mp_mul_2d.c100
-rw-r--r--libtommath/bn_mp_mul_d.c80
-rw-r--r--libtommath/bn_mp_mulmod.c26
-rw-r--r--libtommath/bn_mp_n_root.c4
-rw-r--r--libtommath/bn_mp_n_root_ex.c185
-rw-r--r--libtommath/bn_mp_neg.c26
-rw-r--r--libtommath/bn_mp_or.c48
-rw-r--r--libtommath/bn_mp_prime_fermat.c63
-rw-r--r--libtommath/bn_mp_prime_is_divisible.c36
-rw-r--r--libtommath/bn_mp_prime_is_prime.c77
-rw-r--r--libtommath/bn_mp_prime_miller_rabin.c125
-rw-r--r--libtommath/bn_mp_prime_next_prime.c86
-rw-r--r--libtommath/bn_mp_prime_rabin_miller_trials.c26
-rw-r--r--libtommath/bn_mp_prime_random_ex.c38
-rw-r--r--libtommath/bn_mp_radix_size.c84
-rw-r--r--libtommath/bn_mp_rand.c74
-rw-r--r--libtommath/bn_mp_read_radix.c110
-rw-r--r--libtommath/bn_mp_read_signed_bin.c26
-rw-r--r--libtommath/bn_mp_read_unsigned_bin.c46
-rw-r--r--libtommath/bn_mp_reduce.c112
-rw-r--r--libtommath/bn_mp_reduce_2k_setup.c8
-rw-r--r--libtommath/bn_mp_reduce_2k_setup_l.c8
-rw-r--r--libtommath/bn_mp_reduce_is_2k.c20
-rw-r--r--libtommath/bn_mp_reduce_is_2k_l.c10
-rw-r--r--libtommath/bn_mp_reduce_setup.c14
-rw-r--r--libtommath/bn_mp_rshd.c76
-rw-r--r--libtommath/bn_mp_set.c8
-rw-r--r--libtommath/bn_mp_set_int.c38
-rw-r--r--libtommath/bn_mp_shrink.c32
-rw-r--r--libtommath/bn_mp_signed_bin_size.c4
-rw-r--r--libtommath/bn_mp_sqr.c48
-rw-r--r--libtommath/bn_mp_sqrmod.c26
-rw-r--r--libtommath/bn_mp_sqrt.c164
-rw-r--r--libtommath/bn_mp_sqrtmod_prime.c184
-rw-r--r--libtommath/bn_mp_sub.c58
-rw-r--r--libtommath/bn_mp_sub_d.c114
-rw-r--r--libtommath/bn_mp_submod.c26
-rw-r--r--libtommath/bn_mp_to_signed_bin.c14
-rw-r--r--libtommath/bn_mp_to_signed_bin_n.c2
-rw-r--r--libtommath/bn_mp_to_unsigned_bin.c36
-rw-r--r--libtommath/bn_mp_to_unsigned_bin_n.c2
-rw-r--r--libtommath/bn_mp_toom_mul.c454
-rw-r--r--libtommath/bn_mp_toom_sqr.c396
-rw-r--r--libtommath/bn_mp_toradix.c82
-rw-r--r--libtommath/bn_mp_toradix_n.c104
-rw-r--r--libtommath/bn_mp_unsigned_bin_size.c6
-rw-r--r--libtommath/bn_mp_xor.c48
-rw-r--r--libtommath/bn_mp_zero.c18
-rw-r--r--libtommath/bn_prime_tab.c66
-rw-r--r--libtommath/bn_reverse.c24
-rw-r--r--libtommath/bn_s_mp_add.c158
-rw-r--r--libtommath/bn_s_mp_exptmod.c412
-rw-r--r--libtommath/bn_s_mp_mul_digs.c106
-rw-r--r--libtommath/bn_s_mp_mul_high_digs.c84
-rw-r--r--libtommath/bn_s_mp_sqr.c96
-rw-r--r--libtommath/bn_s_mp_sub.c100
-rw-r--r--libtommath/bncore.c6
-rw-r--r--libtommath/libtommath.dsp572
-rw-r--r--libtommath/libtommath.pc.in10
-rw-r--r--libtommath/libtommath_VS2005.sln20
-rw-r--r--libtommath/libtommath_VS2005.vcproj2847
-rw-r--r--libtommath/libtommath_VS2008.sln20
-rw-r--r--libtommath/libtommath_VS2008.vcproj2813
-rw-r--r--libtommath/makefile3
-rw-r--r--libtommath/tommath.h158
-rw-r--r--libtommath/tommath_class.h1315
-rw-r--r--libtommath/tommath_private.h34
-rw-r--r--libtommath/tommath_superclass.h102
136 files changed, 12193 insertions, 5783 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
diff --git a/libtommath/astylerc b/libtommath/astylerc
new file mode 100644
index 0000000..5d63f7a
--- /dev/null
+++ b/libtommath/astylerc
@@ -0,0 +1,27 @@
+# Artistic Style, see http://astyle.sourceforge.net/
+# full documentation, see: http://astyle.sourceforge.net/astyle.html
+#
+# usage:
+# astyle --options=astylerc *.[ch]
+
+## Bracket Style Options
+style=kr
+
+## Tab Options
+indent=spaces=3
+
+## Bracket Modify Options
+
+## Indentation Options
+min-conditional-indent=0
+
+## Padding Options
+pad-header
+unpad-paren
+align-pointer=name
+
+## Formatting Options
+break-after-logical
+max-code-length=120
+convert-tabs
+mode=c
diff --git a/libtommath/bn_error.c b/libtommath/bn_error.c
index 0d77411..a51d712 100644
--- a/libtommath/bn_error.c
+++ b/libtommath/bn_error.c
@@ -16,12 +16,12 @@
*/
static const struct {
- int code;
- const char *msg;
+ int code;
+ const char *msg;
} msgs[] = {
- { MP_OKAY, "Successful" },
- { MP_MEM, "Out of heap" },
- { MP_VAL, "Value out of range" }
+ { MP_OKAY, "Successful" },
+ { MP_MEM, "Out of heap" },
+ { MP_VAL, "Value out of range" }
};
/* return a char * string for a given code */
@@ -31,9 +31,9 @@ const char *mp_error_to_string(int code)
/* scan the lookup table for the given message */
for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) {
- if (msgs[x].code == code) {
- return msgs[x].msg;
- }
+ if (msgs[x].code == code) {
+ return msgs[x].msg;
+ }
}
/* generic reply for invalid code */
diff --git a/libtommath/bn_fast_mp_invmod.c b/libtommath/bn_fast_mp_invmod.c
index 12f42de..7771136 100644
--- a/libtommath/bn_fast_mp_invmod.c
+++ b/libtommath/bn_fast_mp_invmod.c
@@ -15,131 +15,132 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-/* computes the modular inverse via binary extended euclidean algorithm,
- * that is c = 1/a mod b
+/* computes the modular inverse via binary extended euclidean algorithm,
+ * that is c = 1/a mod b
*
- * Based on slow invmod except this is optimized for the case where b is
+ * Based on slow invmod except this is optimized for the case where b is
* odd as per HAC Note 14.64 on pp. 610
*/
-int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
+int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c)
{
- mp_int x, y, u, v, B, D;
- int res, neg;
-
- /* 2. [modified] b must be odd */
- if (mp_iseven (b) == MP_YES) {
- return MP_VAL;
- }
-
- /* init all our temps */
- if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
- return res;
- }
-
- /* x == modulus, y == value to invert */
- if ((res = mp_copy (b, &x)) != MP_OKAY) {
- goto LBL_ERR;
- }
-
- /* we need y = |a| */
- if ((res = mp_mod (a, b, &y)) != MP_OKAY) {
- goto LBL_ERR;
- }
-
- /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
- if ((res = mp_copy (&x, &u)) != MP_OKAY) {
- goto LBL_ERR;
- }
- if ((res = mp_copy (&y, &v)) != MP_OKAY) {
- goto LBL_ERR;
- }
- mp_set (&D, 1);
+ mp_int x, y, u, v, B, D;
+ int res, neg;
-top:
- /* 4. while u is even do */
- while (mp_iseven (&u) == MP_YES) {
- /* 4.1 u = u/2 */
- if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
- goto LBL_ERR;
- }
- /* 4.2 if B is odd then */
- if (mp_isodd (&B) == MP_YES) {
- if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
- goto LBL_ERR;
- }
- }
- /* B = B/2 */
- if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
- goto LBL_ERR;
- }
- }
+ /* 2. [modified] b must be odd */
+ if (mp_iseven(b) == MP_YES) {
+ return MP_VAL;
+ }
- /* 5. while v is even do */
- while (mp_iseven (&v) == MP_YES) {
- /* 5.1 v = v/2 */
- if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
- goto LBL_ERR;
- }
- /* 5.2 if D is odd then */
- if (mp_isodd (&D) == MP_YES) {
- /* D = (D-x)/2 */
- if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
- goto LBL_ERR;
- }
- }
- /* D = D/2 */
- if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
+ /* init all our temps */
+ if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
+ return res;
+ }
+
+ /* x == modulus, y == value to invert */
+ if ((res = mp_copy(b, &x)) != MP_OKAY) {
goto LBL_ERR;
- }
- }
+ }
- /* 6. if u >= v then */
- if (mp_cmp (&u, &v) != MP_LT) {
- /* u = u - v, B = B - D */
- if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
+ /* we need y = |a| */
+ if ((res = mp_mod(a, b, &y)) != MP_OKAY) {
goto LBL_ERR;
- }
+ }
- if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
+ /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
+ if ((res = mp_copy(&x, &u)) != MP_OKAY) {
goto LBL_ERR;
- }
- } else {
- /* v - v - u, D = D - B */
- if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
+ }
+ if ((res = mp_copy(&y, &v)) != MP_OKAY) {
goto LBL_ERR;
- }
+ }
+ mp_set(&D, 1);
- if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
- goto LBL_ERR;
- }
- }
-
- /* if not zero goto step 4 */
- if (mp_iszero (&u) == MP_NO) {
- goto top;
- }
-
- /* now a = C, b = D, gcd == g*v */
-
- /* if v != 1 then there is no inverse */
- if (mp_cmp_d (&v, 1) != MP_EQ) {
- res = MP_VAL;
- goto LBL_ERR;
- }
-
- /* b is now the inverse */
- neg = a->sign;
- while (D.sign == MP_NEG) {
- if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
+top:
+ /* 4. while u is even do */
+ while (mp_iseven(&u) == MP_YES) {
+ /* 4.1 u = u/2 */
+ if ((res = mp_div_2(&u, &u)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ /* 4.2 if B is odd then */
+ if (mp_isodd(&B) == MP_YES) {
+ if ((res = mp_sub(&B, &x, &B)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+ /* B = B/2 */
+ if ((res = mp_div_2(&B, &B)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+
+ /* 5. while v is even do */
+ while (mp_iseven(&v) == MP_YES) {
+ /* 5.1 v = v/2 */
+ if ((res = mp_div_2(&v, &v)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ /* 5.2 if D is odd then */
+ if (mp_isodd(&D) == MP_YES) {
+ /* D = (D-x)/2 */
+ if ((res = mp_sub(&D, &x, &D)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+ /* D = D/2 */
+ if ((res = mp_div_2(&D, &D)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+
+ /* 6. if u >= v then */
+ if (mp_cmp(&u, &v) != MP_LT) {
+ /* u = u - v, B = B - D */
+ if ((res = mp_sub(&u, &v, &u)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+
+ if ((res = mp_sub(&B, &D, &B)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ } else {
+ /* v - v - u, D = D - B */
+ if ((res = mp_sub(&v, &u, &v)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+
+ if ((res = mp_sub(&D, &B, &D)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+
+ /* if not zero goto step 4 */
+ if (mp_iszero(&u) == MP_NO) {
+ goto top;
+ }
+
+ /* now a = C, b = D, gcd == g*v */
+
+ /* if v != 1 then there is no inverse */
+ if (mp_cmp_d(&v, 1) != MP_EQ) {
+ res = MP_VAL;
goto LBL_ERR;
- }
- }
- mp_exch (&D, c);
- c->sign = neg;
- res = MP_OKAY;
-
-LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
- return res;
+ }
+
+ /* b is now the inverse */
+ neg = a->sign;
+ while (D.sign == MP_NEG) {
+ if ((res = mp_add(&D, b, &D)) != MP_OKAY) {
+ goto LBL_ERR;
+ }
+ }
+ mp_exch(&D, c);
+ c->sign = neg;
+ res = MP_OKAY;
+
+LBL_ERR:
+ mp_clear_multi(&x, &y, &u, &v, &B, &D, NULL);
+ return res;
}
#endif
diff --git a/libtommath/bn_fast_mp_montgomery_reduce.c b/libtommath/bn_fast_mp_montgomery_reduce.c
index 16d5ff7..f2c38bf 100644
--- a/libtommath/bn_fast_mp_montgomery_reduce.c
+++ b/libtommath/bn_fast_mp_montgomery_reduce.c
@@ -23,147 +23,147 @@
*
* Based on Algorithm 14.32 on pp.601 of HAC.
*/
-int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
+int fast_mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho)
{
- int ix, res, olduse;
- mp_word W[MP_WARRAY];
-
- /* get old used count */
- olduse = x->used;
-
- /* grow a as required */
- if (x->alloc < (n->used + 1)) {
- if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) {
- return res;
- }
- }
-
- /* first we have to get the digits of the input into
- * an array of double precision words W[...]
- */
- {
- mp_word *_W;
- mp_digit *tmpx;
-
- /* alias for the W[] array */
- _W = W;
-
- /* alias for the digits of x*/
- tmpx = x->dp;
-
- /* copy the digits of a into W[0..a->used-1] */
- for (ix = 0; ix < x->used; ix++) {
- *_W++ = *tmpx++;
- }
-
- /* zero the high words of W[a->used..m->used*2] */
- for (; ix < ((n->used * 2) + 1); ix++) {
- *_W++ = 0;
- }
- }
-
- /* now we proceed to zero successive digits
- * from the least significant upwards
- */
- for (ix = 0; ix < n->used; ix++) {
- /* mu = ai * m' mod b
- *
- * We avoid a double precision multiplication (which isn't required)
- * by casting the value down to a mp_digit. Note this requires
- * that W[ix-1] have the carry cleared (see after the inner loop)
- */
- mp_digit mu;
- mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK);
-
- /* a = a + mu * m * b**i
- *
- * This is computed in place and on the fly. The multiplication
- * by b**i is handled by offseting which columns the results
- * are added to.
- *
- * Note the comba method normally doesn't handle carries in the
- * inner loop In this case we fix the carry from the previous
- * column since the Montgomery reduction requires digits of the
- * result (so far) [see above] to work. This is
- * handled by fixing up one carry after the inner loop. The
- * carry fixups are done in order so after these loops the
- * first m->used words of W[] have the carries fixed
- */
- {
- int iy;
- mp_digit *tmpn;
+ int ix, res, olduse;
+ mp_word W[MP_WARRAY];
+
+ /* get old used count */
+ olduse = x->used;
+
+ /* grow a as required */
+ if (x->alloc < (n->used + 1)) {
+ if ((res = mp_grow(x, n->used + 1)) != MP_OKAY) {
+ return res;
+ }
+ }
+
+ /* first we have to get the digits of the input into
+ * an array of double precision words W[...]
+ */
+ {
mp_word *_W;
+ mp_digit *tmpx;
+
+ /* alias for the W[] array */
+ _W = W;
- /* alias for the digits of the modulus */
- tmpn = n->dp;
+ /* alias for the digits of x*/
+ tmpx = x->dp;
- /* Alias for the columns set by an offset of ix */
- _W = W + ix;
+ /* copy the digits of a into W[0..a->used-1] */
+ for (ix = 0; ix < x->used; ix++) {
+ *_W++ = *tmpx++;
+ }
- /* inner loop */
- for (iy = 0; iy < n->used; iy++) {
- *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++);
+ /* zero the high words of W[a->used..m->used*2] */
+ for (; ix < ((n->used * 2) + 1); ix++) {
+ *_W++ = 0;
}
- }
-
- /* now fix carry for next digit, W[ix+1] */
- W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT);
- }
-
- /* now we have to propagate the carries and
- * shift the words downward [all those least
- * significant digits we zeroed].
- */
- {
- mp_digit *tmpx;
- mp_word *_W, *_W1;
-
- /* nox fix rest of carries */
-
- /* alias for current word */
- _W1 = W + ix;
-
- /* alias for next word, where the carry goes */
- _W = W + ++ix;
-
- for (; ix <= ((n->used * 2) + 1); ix++) {
- *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
- }
-
- /* copy out, A = A/b**n
- *
- * The result is A/b**n but instead of converting from an
- * array of mp_word to mp_digit than calling mp_rshd
- * we just copy them in the right order
- */
-
- /* alias for destination word */
- tmpx = x->dp;
-
- /* alias for shifted double precision result */
- _W = W + n->used;
-
- for (ix = 0; ix < (n->used + 1); ix++) {
- *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
- }
-
- /* zero oldused digits, if the input a was larger than
- * m->used+1 we'll have to clear the digits
- */
- for (; ix < olduse; ix++) {
- *tmpx++ = 0;
- }
- }
-
- /* set the max used and clamp */
- x->used = n->used + 1;
- mp_clamp (x);
-
- /* if A >= m then A = A - m */
- if (mp_cmp_mag (x, n) != MP_LT) {
- return s_mp_sub (x, n, x);
- }
- return MP_OKAY;
+ }
+
+ /* now we proceed to zero successive digits
+ * from the least significant upwards
+ */
+ for (ix = 0; ix < n->used; ix++) {
+ /* mu = ai * m' mod b
+ *
+ * We avoid a double precision multiplication (which isn't required)
+ * by casting the value down to a mp_digit. Note this requires
+ * that W[ix-1] have the carry cleared (see after the inner loop)
+ */
+ mp_digit mu;
+ mu = (mp_digit)(((W[ix] & MP_MASK) * rho) & MP_MASK);
+
+ /* a = a + mu * m * b**i
+ *
+ * This is computed in place and on the fly. The multiplication
+ * by b**i is handled by offseting which columns the results
+ * are added to.
+ *
+ * Note the comba method normally doesn't handle carries in the
+ * inner loop In this case we fix the carry from the previous
+ * column since the Montgomery reduction requires digits of the
+ * result (so far) [see above] to work. This is
+ * handled by fixing up one carry after the inner loop. The
+ * carry fixups are done in order so after these loops the
+ * first m->used words of W[] have the carries fixed
+ */
+ {
+ int iy;
+ mp_digit *tmpn;
+ mp_word *_W;
+
+ /* alias for the digits of the modulus */
+ tmpn = n->dp;
+
+ /* Alias for the columns set by an offset of ix */
+ _W = W + ix;
+
+ /* inner loop */
+ for (iy = 0; iy < n->used; iy++) {
+ *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++);
+ }
+ }
+
+ /* now fix carry for next digit, W[ix+1] */
+ W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT);
+ }
+
+ /* now we have to propagate the carries and
+ * shift the words downward [all those least
+ * significant digits we zeroed].
+ */
+ {
+ mp_digit *tmpx;
+ mp_word *_W, *_W1;
+
+ /* nox fix rest of carries */
+
+ /* alias for current word */
+ _W1 = W + ix;
+
+ /* alias for next word, where the carry goes */
+ _W = W + ++ix;
+
+ for (; ix <= ((n->used * 2) + 1); ix++) {
+ *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
+ }
+
+ /* copy out, A = A/b**n
+ *
+ * The result is A/b**n but instead of converting from an
+ * array of mp_word to mp_digit than calling mp_rshd
+ * we just copy them in the right order
+ */
+
+ /* alias for destination word */
+ tmpx = x->dp;
+
+ /* alias for shifted double precision result */
+ _W = W + n->used;
+
+ for (ix = 0; ix < (n->used + 1); ix++) {
+ *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
+ }
+
+ /* zero oldused digits, if the input a was larger than
+ * m->used+1 we'll have to clear the digits
+ */
+ for (; ix < olduse; ix++) {
+ *tmpx++ = 0;
+ }
+ }
+
+ /* set the max used and clamp */
+ x->used = n->used + 1;
+ mp_clamp(x);
+
+ /* if A >= m then A = A - m */
+ if (mp_cmp_mag(x, n) != MP_LT) {
+ return s_mp_sub(x, n, x);
+ }
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_fast_s_mp_mul_digs.c b/libtommath/bn_fast_s_mp_mul_digs.c
index 641b574..558d151 100644
--- a/libtommath/bn_fast_s_mp_mul_digs.c
+++ b/libtommath/bn_fast_s_mp_mul_digs.c
@@ -17,39 +17,39 @@
/* Fast (comba) multiplier
*
- * This is the fast column-array [comba] multiplier. It is
- * designed to compute the columns of the product first
- * then handle the carries afterwards. This has the effect
+ * This is the fast column-array [comba] multiplier. It is
+ * designed to compute the columns of the product first
+ * then handle the carries afterwards. This has the effect
* of making the nested loops that compute the columns very
* simple and schedulable on super-scalar processors.
*
- * This has been modified to produce a variable number of
- * digits of output so if say only a half-product is required
- * you don't have to compute the upper half (a feature
+ * This has been modified to produce a variable number of
+ * digits of output so if say only a half-product is required
+ * you don't have to compute the upper half (a feature
* required for fast Barrett reduction).
*
* Based on Algorithm 14.12 on pp.595 of HAC.
*
*/
-int fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
+int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
{
- int olduse, res, pa, ix, iz;
- mp_digit W[MP_WARRAY];
- mp_word _W;
+ int olduse, res, pa, ix, iz;
+ mp_digit W[MP_WARRAY];
+ mp_word _W;
- /* grow the destination as required */
- if (c->alloc < digs) {
- if ((res = mp_grow (c, digs)) != MP_OKAY) {
- return res;
- }
- }
+ /* grow the destination as required */
+ if (c->alloc < digs) {
+ if ((res = mp_grow(c, digs)) != MP_OKAY) {
+ return res;
+ }
+ }
- /* number of output digits to produce */
- pa = MIN(digs, a->used + b->used);
+ /* number of output digits to produce */
+ pa = MIN(digs, a->used + b->used);
- /* clear the carry */
- _W = 0;
- for (ix = 0; ix < pa; ix++) {
+ /* clear the carry */
+ _W = 0;
+ for (ix = 0; ix < pa; ix++) {
int tx, ty;
int iy;
mp_digit *tmpx, *tmpy;
@@ -62,7 +62,7 @@ int fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs
tmpx = a->dp + tx;
tmpy = b->dp + ty;
- /* this is the number of times the loop will iterrate, essentially
+ /* this is the number of times the loop will iterrate, essentially
while (tx++ < a->used && ty-- >= 0) { ... }
*/
iy = MIN(a->used-tx, ty+1);
@@ -78,27 +78,27 @@ int fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs
/* make next carry */
_W = _W >> ((mp_word)DIGIT_BIT);
- }
+ }
- /* setup dest */
- olduse = c->used;
- c->used = pa;
+ /* setup dest */
+ olduse = c->used;
+ c->used = pa;
- {
- mp_digit *tmpc;
- tmpc = c->dp;
- for (ix = 0; ix < (pa + 1); ix++) {
- /* now extract the previous digit [below the carry] */
- *tmpc++ = W[ix];
- }
+ {
+ mp_digit *tmpc;
+ tmpc = c->dp;
+ for (ix = 0; ix < (pa + 1); ix++) {
+ /* now extract the previous digit [below the carry] */
+ *tmpc++ = W[ix];
+ }
- /* clear unused digits [that existed in the old copy of c] */
- for (; ix < olduse; ix++) {
- *tmpc++ = 0;
- }
- }
- mp_clamp (c);
- return MP_OKAY;
+ /* clear unused digits [that existed in the old copy of c] */
+ for (; ix < olduse; ix++) {
+ *tmpc++ = 0;
+ }
+ }
+ mp_clamp(c);
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_fast_s_mp_mul_high_digs.c b/libtommath/bn_fast_s_mp_mul_high_digs.c
index 08f0355..588d80b 100644
--- a/libtommath/bn_fast_s_mp_mul_high_digs.c
+++ b/libtommath/bn_fast_s_mp_mul_high_digs.c
@@ -24,24 +24,24 @@
*
* Based on Algorithm 14.12 on pp.595 of HAC.
*/
-int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
+int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
{
- int olduse, res, pa, ix, iz;
- mp_digit W[MP_WARRAY];
- mp_word _W;
+ int olduse, res, pa, ix, iz;
+ mp_digit W[MP_WARRAY];
+ mp_word _W;
- /* grow the destination as required */
- pa = a->used + b->used;
- if (c->alloc < pa) {
- if ((res = mp_grow (c, pa)) != MP_OKAY) {
- return res;
- }
- }
+ /* grow the destination as required */
+ pa = a->used + b->used;
+ if (c->alloc < pa) {
+ if ((res = mp_grow(c, pa)) != MP_OKAY) {
+ return res;
+ }
+ }
- /* number of output digits to produce */
- pa = a->used + b->used;
- _W = 0;
- for (ix = digs; ix < pa; ix++) {
+ /* number of output digits to produce */
+ pa = a->used + b->used;
+ _W = 0;
+ for (ix = digs; ix < pa; ix++) {
int tx, ty, iy;
mp_digit *tmpx, *tmpy;
@@ -53,7 +53,7 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
tmpx = a->dp + tx;
tmpy = b->dp + ty;
- /* this is the number of times the loop will iterrate, essentially its
+ /* this is the number of times the loop will iterrate, essentially its
while (tx++ < a->used && ty-- >= 0) { ... }
*/
iy = MIN(a->used-tx, ty+1);
@@ -68,28 +68,28 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
/* make next carry */
_W = _W >> ((mp_word)DIGIT_BIT);
- }
-
- /* setup dest */
- olduse = c->used;
- c->used = pa;
+ }
+
+ /* setup dest */
+ olduse = c->used;
+ c->used = pa;
- {
- mp_digit *tmpc;
+ {
+ mp_digit *tmpc;
- tmpc = c->dp + digs;
- for (ix = digs; ix < pa; ix++) {
- /* now extract the previous digit [below the carry] */
- *tmpc++ = W[ix];
- }
+ tmpc = c->dp + digs;
+ for (ix = digs; ix < pa; ix++) {
+ /* now extract the previous digit [below the carry] */
+ *tmpc++ = W[ix];
+ }
- /* clear unused digits [that existed in the old copy of c] */
- for (; ix < olduse; ix++) {
- *tmpc++ = 0;
- }
- }
- mp_clamp (c);
- return MP_OKAY;
+ /* clear unused digits [that existed in the old copy of c] */
+ for (; ix < olduse; ix++) {
+ *tmpc++ = 0;
+ }
+ }
+ mp_clamp(c);
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_fast_s_mp_sqr.c b/libtommath/bn_fast_s_mp_sqr.c
index 282d303..161f785 100644
--- a/libtommath/bn_fast_s_mp_sqr.c
+++ b/libtommath/bn_fast_s_mp_sqr.c
@@ -16,32 +16,32 @@
*/
/* the jist of squaring...
- * you do like mult except the offset of the tmpx [one that
- * starts closer to zero] can't equal the offset of tmpy.
+ * you do like mult except the offset of the tmpx [one that
+ * starts closer to zero] can't equal the offset of tmpy.
* So basically you set up iy like before then you min it with
- * (ty-tx) so that it never happens. You double all those
+ * (ty-tx) so that it never happens. You double all those
* you add in the inner loop
After that loop you do the squares and add them in.
*/
-int fast_s_mp_sqr (const mp_int * a, mp_int * b)
+int fast_s_mp_sqr(const mp_int *a, mp_int *b)
{
- int olduse, res, pa, ix, iz;
- mp_digit W[MP_WARRAY], *tmpx;
- mp_word W1;
-
- /* grow the destination as required */
- pa = a->used + a->used;
- if (b->alloc < pa) {
- if ((res = mp_grow (b, pa)) != MP_OKAY) {
- return res;
- }
- }
-
- /* number of output digits to produce */
- W1 = 0;
- for (ix = 0; ix < pa; ix++) {
+ int olduse, res, pa, ix, iz;
+ mp_digit W[MP_WARRAY], *tmpx;
+ mp_word W1;
+
+ /* grow the destination as required */
+ pa = a->used + a->used;
+ if (b->alloc < pa) {
+ if ((res = mp_grow(b, pa)) != MP_OKAY) {
+ return res;
+ }
+ }
+
+ /* number of output digits to produce */
+ W1 = 0;
+ for (ix = 0; ix < pa; ix++) {
int tx, ty, iy;
mp_word _W;
mp_digit *tmpy;
@@ -62,7 +62,7 @@ int fast_s_mp_sqr (const mp_int * a, mp_int * b)
*/
iy = MIN(a->used-tx, ty+1);
- /* now for squaring tx can never equal ty
+ /* now for squaring tx can never equal ty
* we halve the distance since they approach at a rate of 2x
* and we have to round because odd cases need to be executed
*/
@@ -86,26 +86,26 @@ int fast_s_mp_sqr (const mp_int * a, mp_int * b)
/* make next carry */
W1 = _W >> ((mp_word)DIGIT_BIT);
- }
-
- /* setup dest */
- olduse = b->used;
- b->used = a->used+a->used;
-
- {
- mp_digit *tmpb;
- tmpb = b->dp;
- for (ix = 0; ix < pa; ix++) {
- *tmpb++ = W[ix] & MP_MASK;
- }
-
- /* clear unused digits [that existed in the old copy of c] */
- for (; ix < olduse; ix++) {
- *tmpb++ = 0;
- }
- }
- mp_clamp (b);
- return MP_OKAY;
+ }
+
+ /* setup dest */
+ olduse = b->used;
+ b->used = a->used+a->used;
+
+ {
+ mp_digit *tmpb;
+ tmpb = b->dp;
+ for (ix = 0; ix < pa; ix++) {
+ *tmpb++ = W[ix] & MP_MASK;
+ }
+
+ /* clear unused digits [that existed in the old copy of c] */
+ for (; ix < olduse; ix++) {
+ *tmpb++ = 0;
+ }
+ }
+ mp_clamp(b);
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_mp_2expt.c b/libtommath/bn_mp_2expt.c
index 989bb9f..bdc868f 100644
--- a/libtommath/bn_mp_2expt.c
+++ b/libtommath/bn_mp_2expt.c
@@ -15,31 +15,31 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-/* computes a = 2**b
+/* computes a = 2**b
*
* Simple algorithm which zeroes the int, grows it then just sets one bit
* as required.
*/
int
-mp_2expt (mp_int * a, int b)
+mp_2expt(mp_int *a, int b)
{
- int res;
+ int res;
- /* zero a as per default */
- mp_zero (a);
+ /* zero a as per default */
+ mp_zero(a);
- /* grow a to accomodate the single bit */
- if ((res = mp_grow (a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
- return res;
- }
+ /* grow a to accomodate the single bit */
+ if ((res = mp_grow(a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
+ return res;
+ }
- /* set the used count of where the bit will go */
- a->used = (b / DIGIT_BIT) + 1;
+ /* set the used count of where the bit will go */
+ a->used = (b / DIGIT_BIT) + 1;
- /* put the single bit in its place */
- a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);
+ /* put the single bit in its place */
+ a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);
- return MP_OKAY;
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_mp_abs.c b/libtommath/bn_mp_abs.c
index e7c5e25..343a102 100644
--- a/libtommath/bn_mp_abs.c
+++ b/libtommath/bn_mp_abs.c
@@ -15,26 +15,26 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-/* b = |a|
+/* b = |a|
*
* Simple function copies the input and fixes the sign to positive
*/
int
-mp_abs (mp_int * a, mp_int * b)
+mp_abs(mp_int *a, mp_int *b)
{
- int res;
+ int res;
- /* copy a to b */
- if (a != b) {
- if ((res = mp_copy (a, b)) != MP_OKAY) {
- return res;
- }
- }
+ /* copy a to b */
+ if (a != b) {
+ if ((res = mp_copy(a, b)) != MP_OKAY) {
+ return res;
+ }
+ }
- /* force the sign of b to positive */
- b->sign = MP_ZPOS;
+ /* force the sign of b to positive */
+ b->sign = MP_ZPOS;
- return MP_OKAY;
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_mp_add.c b/libtommath/bn_mp_add.c
index a68c02e..d31d5a0 100644
--- a/libtommath/bn_mp_add.c
+++ b/libtommath/bn_mp_add.c
@@ -16,34 +16,34 @@
*/
/* high level addition (handles signs) */
-int mp_add (const mp_int * a, const mp_int * b, mp_int * c)
+int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
{
- int sa, sb, res;
+ int sa, sb, res;
- /* get sign of both inputs */
- sa = a->sign;
- sb = b->sign;
+ /* get sign of both inputs */
+ sa = a->sign;
+ sb = b->sign;
- /* handle two cases, not four */
- if (sa == sb) {
- /* both positive or both negative */
- /* add their magnitudes, copy the sign */
- c->sign = sa;
- res = s_mp_add (a, b, c);
- } else {
- /* one positive, the other negative */
- /* subtract the one with the greater magnitude from */
- /* the one of the lesser magnitude. The result gets */
- /* the sign of the one with the greater magnitude. */
- if (mp_cmp_mag (a, b) == MP_LT) {
- c->sign = sb;
- res = s_mp_sub (b, a, c);
- } else {
+ /* handle two cases, not four */
+ if (sa == sb) {
+ /* both positive or both negative */
+ /* add their magnitudes, copy the sign */
c->sign = sa;
- res = s_mp_sub (a, b, c);
- }
- }
- return res;
+ res = s_mp_add(a, b, c);
+ } else {
+ /* one positive, the other negative */
+ /* subtract the one with the greater magnitude from */
+ /* the one of the lesser magnitude. The result gets */
+ /* the sign of the one with the greater magnitude. */
+ if (mp_cmp_mag(a, b) == MP_LT) {
+ c->sign = sb;
+ res = s_mp_sub(b, a, c);
+ } else {
+ c->sign = sa;
+ res = s_mp_sub(a, b, c);
+ }
+ }
+ return res;
}
#endif
diff --git a/libtommath/bn_mp_add_d.c b/libtommath/bn_mp_add_d.c
index c2f2e0e..5270d27 100644
--- a/libtommath/bn_mp_add_d.c
+++ b/libtommath/bn_mp_add_d.c
@@ -17,93 +17,93 @@
/* single digit addition */
int
-mp_add_d (const mp_int * a, mp_digit b, mp_int * c)
+mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
{
- int res, ix, oldused;
- mp_digit *tmpa, *tmpc, mu;
-
- /* grow c as required */
- if (c->alloc < (a->used + 1)) {
- if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
- return res;
- }
- }
-
- /* if a is negative and |a| >= b, call c = |a| - b */
- if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) {
- mp_int a_ = *a;
- /* temporarily fix sign of a */
- a_.sign = MP_ZPOS;
-
- /* c = |a| - b */
- res = mp_sub_d(&a_, b, c);
-
- /* fix sign */
- c->sign = MP_NEG;
-
- /* clamp */
- mp_clamp(c);
-
- return res;
- }
-
- /* old number of used digits in c */
- oldused = c->used;
-
- /* source alias */
- tmpa = a->dp;
-
- /* destination alias */
- tmpc = c->dp;
-
- /* if a is positive */
- if (a->sign == MP_ZPOS) {
- /* add digit, after this we're propagating
- * the carry.
- */
- *tmpc = *tmpa++ + b;
- mu = *tmpc >> DIGIT_BIT;
- *tmpc++ &= MP_MASK;
-
- /* now handle rest of the digits */
- for (ix = 1; ix < a->used; ix++) {
- *tmpc = *tmpa++ + mu;
- mu = *tmpc >> DIGIT_BIT;
- *tmpc++ &= MP_MASK;
- }
- /* set final carry */
- ix++;
- *tmpc++ = mu;
-
- /* setup size */
- c->used = a->used + 1;
- } else {
- /* a was negative and |a| < b */
- c->used = 1;
-
- /* the result is a single digit */
- if (a->used == 1) {
- *tmpc++ = b - a->dp[0];
- } else {
- *tmpc++ = b;
- }
-
- /* setup count so the clearing of oldused
- * can fall through correctly
- */
- ix = 1;
- }
-
- /* sign always positive */
- c->sign = MP_ZPOS;
-
- /* now zero to oldused */
- while (ix++ < oldused) {
- *tmpc++ = 0;
- }
- mp_clamp(c);
-
- return MP_OKAY;
+ int res, ix, oldused;
+ mp_digit *tmpa, *tmpc, mu;
+
+ /* grow c as required */
+ if (c->alloc < (a->used + 1)) {
+ if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
+ return res;
+ }
+ }
+
+ /* if a is negative and |a| >= b, call c = |a| - b */
+ if ((a->sign == MP_NEG) && ((a->used > 1) || (a->dp[0] >= b))) {
+ mp_int a_ = *a;
+ /* temporarily fix sign of a */
+ a_.sign = MP_ZPOS;
+
+ /* c = |a| - b */
+ res = mp_sub_d(&a_, b, c);
+
+ /* fix sign */
+ c->sign = MP_NEG;
+
+ /* clamp */
+ mp_clamp(c);
+
+ return res;
+ }
+
+ /* old number of used digits in c */
+ oldused = c->used;
+
+ /* source alias */
+ tmpa = a->dp;
+
+ /* destination alias */
+ tmpc = c->dp;
+
+ /* if a is positive */
+ if (a->sign == MP_ZPOS) {
+ /* add digit, after this we're propagating
+ * the carry.
+ */
+ *tmpc = *tmpa++ + b;
+ mu = *tmpc >> DIGIT_BIT;
+ *tmpc++ &= MP_MASK;
+
+ /* now handle rest of the digits */
+ for (ix = 1; ix < a->used; ix++) {
+ *tmpc = *tmpa++ + mu;
+ mu = *tmpc >> DIGIT_BIT;
+ *tmpc++ &= MP_MASK;
+ }
+ /* set final carry */
+ ix++;
+ *tmpc++ = mu;
+
+ /* setup size */
+ c->used = a->used + 1;
+ } else {
+ /* a was negative and |a| < b */
+ c->used = 1;
+
+ /* the result is a single digit */
+ if (a->used == 1) {
+ *tmpc++ = b - a->dp[0];
+ } else {
+ *tmpc++ = b;
+ }
+
+ /* setup count so the clearing of oldused
+ * can fall through correctly
+ */
+ ix = 1;
+ }
+
+ /* sign always positive */
+ c->sign = MP_ZPOS;
+
+ /* now zero to oldused */
+ while (ix++ < oldused) {
+ *tmpc++ = 0;
+ }
+ mp_clamp(c);
+
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_mp_addmod.c b/libtommath/bn_mp_addmod.c
index dc06788..0521974 100644
--- a/libtommath/bn_mp_addmod.c
+++ b/libtommath/bn_mp_addmod.c
@@ -17,22 +17,22 @@
/* d = a + b (mod c) */
int
-mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
+mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d)
{
- int res;
- mp_int t;
+ int res;
+ mp_int t;
- if ((res = mp_init (&t)) != MP_OKAY) {
- return res;
- }
+ if ((res = mp_init(&t)) != MP_OKAY) {
+ return res;
+ }
- if ((res = mp_add (a, b, &t)) != MP_OKAY) {
- mp_clear (&t);
- return res;
- }
- res = mp_mod (&t, c, d);
- mp_clear (&t);
- return res;
+ if ((res = mp_add(a, b, &t)) != MP_OKAY) {
+ mp_clear(&t);
+ return res;
+ }
+ res = mp_mod(&t, c, d);
+ mp_clear(&t);
+ return res;
}
#endif
diff --git a/libtommath/bn_mp_and.c b/libtommath/bn_mp_and.c
index e90ab37..c6e8cf7 100644
--- a/libtommath/bn_mp_and.c
+++ b/libtommath/bn_mp_and.c
@@ -17,39 +17,39 @@
/* AND two ints together */
int
-mp_and (const mp_int * a, const mp_int * b, mp_int * c)
+mp_and(const mp_int *a, const mp_int *b, mp_int *c)
{
- int res, ix, px;
- mp_int t;
- const mp_int *x;
+ int res, ix, px;
+ mp_int t;
+ const mp_int *x;
- if (a->used > b->used) {
- if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
- return res;
- }
- px = b->used;
- x = b;
- } else {
- if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
- return res;
- }
- px = a->used;
- x = a;
- }
+ if (a->used > b->used) {
+ if ((res = mp_init_copy(&t, a)) != MP_OKAY) {
+ return res;
+ }
+ px = b->used;
+ x = b;
+ } else {
+ if ((res = mp_init_copy(&t, b)) != MP_OKAY) {
+ return res;
+ }
+ px = a->used;
+ x = a;
+ }
- for (ix = 0; ix < px; ix++) {
- t.dp[ix] &= x->dp[ix];
- }
+ for (ix = 0; ix < px; ix++) {
+ t.dp[ix] &= x->dp[ix];
+ }
- /* zero digits above the last from the smallest mp_int */
- for (; ix < t.used; ix++) {
- t.dp[ix] = 0;
- }
+ /* zero digits above the last from the smallest mp_int */
+ for (; ix < t.used; ix++) {
+ t.dp[ix] = 0;
+ }
- mp_clamp (&t);
- mp_exch (c, &t);
- mp_clear (&t);
- return MP_OKAY;
+ mp_clamp(&t);
+ mp_exch(c, &t);
+ mp_clear(&t);
+ return MP_OKAY;
}
#endif
diff --git a/libtommath/bn_mp_clamp.c b/libtommath/bn_mp_clamp.c
index 2c0a1a6..e5c8907 100644
--- a/libtommath/bn_mp_clamp.c
+++ b/libtommath/bn_mp_clamp.c
@@ -15,7 +15,7 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-/* trim unused digits
+/* trim unused digits
*
* This is used to ensure that leading zero digits are
* trimed and the leading "used" digit will be non-zero
@@ -23,19 +23,19 @@
* are no more leading digits
*/
void
-mp_clamp (mp_int * a)
+mp_clamp(mp_int *a)
{
- /* decrease used while the most significant digit is
- * zero.
- */
- while ((a->used > 0) && (a->dp[a->used - 1] == 0)) {
- --(a->used);
- }
+ /* decrease used while the most significant digit is
+ * zero.
+ */
+ while ((a->used > 0) && (a->dp[a->used - 1] == 0)) {
+ --(a->used);
+ }
- /* reset the sign flag if used == 0 */
- if (a->used == 0) {
- a->sign = MP_ZPOS;
- }
+ /* reset the sign flag if used == 0 */
+ if (a->used == 0) {
+ a->sign = MP_ZPOS;
+ }
}
#endif
diff --git a/libtommath/bn_mp_clear.c b/libtommath/bn_mp_clear.c