summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-11 10:38:07 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-11 10:38:07 (GMT)
commitb9e8eecd80020e9dc1539f6f99f121472aff3126 (patch)
tree2e262a4602582231d8ffc8cfae0ed63eae88e24f
parent72cd4c6a0763c30b3f3a4fceb1ed78ad63711cb5 (diff)
downloadtcl-b9e8eecd80020e9dc1539f6f99f121472aff3126.zip
tcl-b9e8eecd80020e9dc1539f6f99f121472aff3126.tar.gz
tcl-b9e8eecd80020e9dc1539f6f99f121472aff3126.tar.bz2
Many 'const' addtions in libtommath where it makes sense. To be submitted back to the libtommath guys.
-rw-r--r--generic/tclTomMath.decls50
-rw-r--r--generic/tclTomMath.h38
-rw-r--r--generic/tclTomMathDecls.h125
-rw-r--r--libtommath/bn_fast_s_mp_mul_digs.c2
-rw-r--r--libtommath/bn_fast_s_mp_sqr.c2
-rw-r--r--libtommath/bn_mp_add.c2
-rw-r--r--libtommath/bn_mp_and.c5
-rw-r--r--libtommath/bn_mp_div.c4
-rw-r--r--libtommath/bn_mp_div_3.c2
-rw-r--r--libtommath/bn_mp_div_d.c2
-rw-r--r--libtommath/bn_mp_expt_d.c2
-rw-r--r--libtommath/bn_mp_expt_d_ex.c2
-rw-r--r--libtommath/bn_mp_karatsuba_mul.c2
-rw-r--r--libtommath/bn_mp_karatsuba_sqr.c2
-rw-r--r--libtommath/bn_mp_mod.c2
-rw-r--r--libtommath/bn_mp_mul.c2
-rw-r--r--libtommath/bn_mp_mul_d.c2
-rw-r--r--libtommath/bn_mp_or.c5
-rw-r--r--libtommath/bn_mp_sqr.c2
-rw-r--r--libtommath/bn_mp_sqrt.c2
-rw-r--r--libtommath/bn_mp_sub.c2
-rw-r--r--libtommath/bn_mp_toom_mul.c2
-rw-r--r--libtommath/bn_mp_toom_sqr.c2
-rw-r--r--libtommath/bn_mp_xor.c5
-rw-r--r--libtommath/bn_s_mp_add.c4
-rw-r--r--libtommath/bn_s_mp_mul_digs.c2
-rw-r--r--libtommath/bn_s_mp_sqr.c2
-rw-r--r--libtommath/bn_s_mp_sub.c2
-rw-r--r--libtommath/tommath.h36
-rw-r--r--libtommath/tommath_private.h20
30 files changed, 174 insertions, 158 deletions
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index c4299d0..5d1c8e8 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -30,13 +30,13 @@ declare 1 {
}
declare 2 {
- int TclBN_mp_add(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 3 {
int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c)
}
declare 4 {
- int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 5 {
void TclBN_mp_clamp(mp_int *a)
@@ -63,10 +63,10 @@ declare 12 {
int TclBN_mp_count_bits(const mp_int *a)
}
declare 13 {
- int TclBN_mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r)
+ int TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r)
}
declare 14 {
- int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
+ int TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
}
declare 15 {
int TclBN_mp_div_2(const mp_int *a, mp_int *q)
@@ -75,13 +75,13 @@ declare 16 {
int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r)
}
declare 17 {
- int TclBN_mp_div_3(mp_int *a, mp_int *q, mp_digit *r)
+ int TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r)
}
declare 18 {
void TclBN_mp_exch(mp_int *a, mp_int *b)
}
declare 19 {
- int TclBN_mp_expt_d(mp_int *a, mp_digit b, mp_int *c)
+ int TclBN_mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
}
declare 20 {
int TclBN_mp_grow(mp_int *a, int size)
@@ -105,16 +105,16 @@ declare 26 {
int TclBN_mp_lshd(mp_int *a, int shift)
}
declare 27 {
- int TclBN_mp_mod(mp_int *a, mp_int *b, mp_int *r)
+ int TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r)
}
declare 28 {
int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r)
}
declare 29 {
- int TclBN_mp_mul(mp_int *a, mp_int *b, mp_int *p)
+ int TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p)
}
declare 30 {
- int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *p)
+ int TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p)
}
declare 31 {
int TclBN_mp_mul_2(const mp_int *a, mp_int *p)
@@ -126,7 +126,7 @@ declare 33 {
int TclBN_mp_neg(const mp_int *a, mp_int *b)
}
declare 34 {
- int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 35 {
int TclBN_mp_radix_size(const mp_int *a, int radix, int *size)
@@ -144,13 +144,13 @@ declare 39 {
void TclBN_mp_set(mp_int *a, mp_digit b)
}
declare 40 {
- int TclBN_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_sqr(const mp_int *a, mp_int *b)
}
declare 41 {
- int TclBN_mp_sqrt(mp_int *a, mp_int *b)
+ int TclBN_mp_sqrt(const mp_int *a, mp_int *b)
}
declare 42 {
- int TclBN_mp_sub(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 43 {
int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c)
@@ -169,7 +169,7 @@ declare 47 {
int TclBN_mp_unsigned_bin_size(mp_int *a)
}
declare 48 {
- int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 49 {
void TclBN_mp_zero(mp_int *a)
@@ -182,34 +182,34 @@ declare 50 {
void TclBN_reverse(unsigned char *s, int len)
}
declare 51 {
- int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
+ int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
}
declare 52 {
- int TclBN_fast_s_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
}
declare 53 {
- int TclBN_mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 54 {
- int TclBN_mp_karatsuba_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
}
declare 55 {
- int TclBN_mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 56 {
- int TclBN_mp_toom_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
}
declare 57 {
- int TclBN_s_mp_add(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 58 {
- int TclBN_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
+ int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
}
declare 59 {
- int TclBN_s_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
}
declare 60 {
- int TclBN_s_mp_sub(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 61 {
int TclBN_mp_init_set_int(mp_int *a, unsigned long i)
@@ -235,7 +235,7 @@ declare 66 {
# Added in libtommath 1.0
declare 67 {
- int TclBN_mp_expt_d_ex(mp_int *a, mp_digit b, mp_int *c, int fast)
+ int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
}
# Added in libtommath 1.0.1
declare 68 {
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index 7e3c29e..2ce8194 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -27,7 +27,7 @@ extern "C" {
#endif
/* detect 64-bit mode if possible */
-#if defined(NEVER) /* 128-bit ints fail in too many places */
+#if defined(NEVER)
#if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
#define MP_64BIT
#endif
@@ -383,17 +383,17 @@ int mp_rand(mp_int *a, int digits);
/* ---> binary operations <--- */
/* c = a XOR b */
/*
-int mp_xor(mp_int *a, mp_int *b, mp_int *c);
+int mp_xor(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a OR b */
/*
-int mp_or(mp_int *a, mp_int *b, mp_int *c);
+int mp_or(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a AND b */
/*
-int mp_and(mp_int *a, mp_int *b, mp_int *c);
+int mp_and(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* ---> Basic arithmetic <--- */
@@ -405,7 +405,7 @@ int mp_neg(const mp_int *a, mp_int *b);
/* b = |a| */
/*
-int mp_abs(mp_int *a, mp_int *b);
+int mp_abs(const mp_int *a, mp_int *b);
*/
/* compare a to b */
@@ -420,32 +420,32 @@ int mp_cmp_mag(const mp_int *a, const mp_int *b);
/* c = a + b */
/*
-int mp_add(mp_int *a, mp_int *b, mp_int *c);
+int mp_add(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a - b */
/*
-int mp_sub(mp_int *a, mp_int *b, mp_int *c);
+int mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a * b */
/*
-int mp_mul(mp_int *a, mp_int *b, mp_int *c);
+int mp_mul(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* b = a*a */
/*
-int mp_sqr(mp_int *a, mp_int *b);
+int mp_sqr(const mp_int *a, mp_int *b);
*/
/* a/b => cb + d == a */
/*
-int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);
*/
/* c = a mod b, 0 <= c < b */
/*
-int mp_mod(mp_int *a, mp_int *b, mp_int *c);
+int mp_mod(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* ---> single digit functions <--- */
@@ -457,40 +457,40 @@ int mp_cmp_d(const mp_int *a, mp_digit b);
/* c = a + b */
/*
-int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_add_d(const mp_int *a, const mp_digit b, mp_int *c);
*/
/* c = a - b */
/*
-int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* c = a * b */
/*
-int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* a/b => cb + d == a */
/*
-int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
+int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
*/
/* a/3 => 3c + d == a */
/*
-int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
+int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d);
*/
/* c = a**b */
/*
-int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_expt_d(const mp_int *a, const mp_digit b, mp_int *c);
*/
/*
-int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
+int mp_expt_d_ex (const mp_int * a, const mp_digit b, mp_int * c, int fast);
*/
/* c = a mod b, 0 <= c < b */
/*
-int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
+int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c);
*/
/* ---> number theory <--- */
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 70de3b1..9d683dc 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -151,11 +151,13 @@ EXTERN int TclBN_epoch(void);
/* 1 */
EXTERN int TclBN_revision(void);
/* 2 */
-EXTERN int TclBN_mp_add(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_add(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 3 */
EXTERN int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c);
/* 4 */
-EXTERN int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_and(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 5 */
EXTERN void TclBN_mp_clamp(mp_int *a);
/* 6 */
@@ -173,22 +175,24 @@ EXTERN int TclBN_mp_copy(const mp_int *a, mp_int *b);
/* 12 */
EXTERN int TclBN_mp_count_bits(const mp_int *a);
/* 13 */
-EXTERN int TclBN_mp_div(mp_int *a, mp_int *b, mp_int *q,
- mp_int *r);
+EXTERN int TclBN_mp_div(const mp_int *a, const mp_int *b,
+ mp_int *q, mp_int *r);
/* 14 */
-EXTERN int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *q,
- mp_digit *r);
+EXTERN int TclBN_mp_div_d(const mp_int *a, mp_digit b,
+ mp_int *q, mp_digit *r);
/* 15 */
EXTERN int TclBN_mp_div_2(const mp_int *a, mp_int *q);
/* 16 */
EXTERN int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
mp_int *r);
/* 17 */
-EXTERN int TclBN_mp_div_3(mp_int *a, mp_int *q, mp_digit *r);
+EXTERN int TclBN_mp_div_3(const mp_int *a, mp_int *q,
+ mp_digit *r);
/* 18 */
EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
/* 19 */
-EXTERN int TclBN_mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
+EXTERN int TclBN_mp_expt_d(const mp_int *a, mp_digit b,
+ mp_int *c);
/* 20 */
EXTERN int TclBN_mp_grow(mp_int *a, int size);
/* 21 */
@@ -204,13 +208,16 @@ EXTERN int TclBN_mp_init_size(mp_int *a, int size);
/* 26 */
EXTERN int TclBN_mp_lshd(mp_int *a, int shift);
/* 27 */
-EXTERN int TclBN_mp_mod(mp_int *a, mp_int *b, mp_int *r);
+EXTERN int TclBN_mp_mod(const mp_int *a, const mp_int *b,
+ mp_int *r);
/* 28 */
EXTERN int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r);
/* 29 */
-EXTERN int TclBN_mp_mul(mp_int *a, mp_int *b, mp_int *p);
+EXTERN int TclBN_mp_mul(const mp_int *a, const mp_int *b,
+ mp_int *p);
/* 30 */
-EXTERN int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *p);
+EXTERN int TclBN_mp_mul_d(const mp_int *a, mp_digit b,
+ mp_int *p);
/* 31 */
EXTERN int TclBN_mp_mul_2(const mp_int *a, mp_int *p);
/* 32 */
@@ -218,7 +225,8 @@ EXTERN int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p);
/* 33 */
EXTERN int TclBN_mp_neg(const mp_int *a, mp_int *b);
/* 34 */
-EXTERN int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_or(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 35 */
EXTERN int TclBN_mp_radix_size(const mp_int *a, int radix,
int *size);
@@ -232,11 +240,12 @@ EXTERN int TclBN_mp_shrink(mp_int *a);
/* 39 */
EXTERN void TclBN_mp_set(mp_int *a, mp_digit b);
/* 40 */
-EXTERN int TclBN_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_sqr(const mp_int *a, mp_int *b);
/* 41 */
-EXTERN int TclBN_mp_sqrt(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_sqrt(const mp_int *a, mp_int *b);
/* 42 */
-EXTERN int TclBN_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_sub(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 43 */
EXTERN int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
/* 44 */
@@ -250,34 +259,38 @@ EXTERN int TclBN_mp_toradix_n(mp_int *a, char *str, int radix,
/* 47 */
EXTERN int TclBN_mp_unsigned_bin_size(mp_int *a);
/* 48 */
-EXTERN int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_xor(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 49 */
EXTERN void TclBN_mp_zero(mp_int *a);
/* 50 */
EXTERN void TclBN_reverse(unsigned char *s, int len);
/* 51 */
-EXTERN int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b,
- mp_int *c, int digs);
+EXTERN int TclBN_fast_s_mp_mul_digs(const mp_int *a,
+ const mp_int *b, mp_int *c, int digs);
/* 52 */
-EXTERN int TclBN_fast_s_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
/* 53 */
-EXTERN int TclBN_mp_karatsuba_mul(mp_int *a, mp_int *b,
- mp_int *c);
+EXTERN int TclBN_mp_karatsuba_mul(const mp_int *a,
+ const mp_int *b, mp_int *c);
/* 54 */
-EXTERN int TclBN_mp_karatsuba_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
/* 55 */
-EXTERN int TclBN_mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 56 */
-EXTERN int TclBN_mp_toom_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
/* 57 */
-EXTERN int TclBN_s_mp_add(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_s_mp_add(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 58 */
-EXTERN int TclBN_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c,
- int digs);
+EXTERN int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
+ mp_int *c, int digs);
/* 59 */
-EXTERN int TclBN_s_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
/* 60 */
-EXTERN int TclBN_s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 61 */
EXTERN int TclBN_mp_init_set_int(mp_int *a, unsigned long i);
/* 62 */
@@ -293,8 +306,8 @@ EXTERN void TclBNInitBignumFromWideInt(mp_int *bignum,
EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum,
Tcl_WideUInt initVal);
/* 67 */
-EXTERN int TclBN_mp_expt_d_ex(mp_int *a, mp_digit b, mp_int *c,
- int fast);
+EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
+ mp_int *c, int fast);
/* 68 */
EXTERN int TclBN_mp_set_long_long(mp_int *a, Tcl_WideUInt i);
/* 69 */
@@ -306,9 +319,9 @@ typedef struct TclTomMathStubs {
int (*tclBN_epoch) (void); /* 0 */
int (*tclBN_revision) (void); /* 1 */
- int (*tclBN_mp_add) (mp_int *a, mp_int *b, mp_int *c); /* 2 */
+ int (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */
int (*tclBN_mp_add_d) (mp_int *a, mp_digit b, mp_int *c); /* 3 */
- int (*tclBN_mp_and) (mp_int *a, mp_int *b, mp_int *c); /* 4 */
+ int (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */
void (*tclBN_mp_clamp) (mp_int *a); /* 5 */
void (*tclBN_mp_clear) (mp_int *a); /* 6 */
void (*tclBN_mp_clear_multi) (mp_int *a, ...); /* 7 */
@@ -317,13 +330,13 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */
int (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */
int (*tclBN_mp_count_bits) (const mp_int *a); /* 12 */
- int (*tclBN_mp_div) (mp_int *a, mp_int *b, mp_int *q, mp_int *r); /* 13 */
- int (*tclBN_mp_div_d) (mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
+ int (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */
+ int (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
int (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */
int (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
- int (*tclBN_mp_div_3) (mp_int *a, mp_int *q, mp_digit *r); /* 17 */
+ int (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
- int (*tclBN_mp_expt_d) (mp_int *a, mp_digit b, mp_int *c); /* 19 */
+ int (*tclBN_mp_expt_d) (const mp_int *a, mp_digit b, mp_int *c); /* 19 */
int (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
int (*tclBN_mp_init) (mp_int *a); /* 21 */
int (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
@@ -331,47 +344,47 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */
int (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */
int (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */
- int (*tclBN_mp_mod) (mp_int *a, mp_int *b, mp_int *r); /* 27 */
+ int (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */
int (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */
- int (*tclBN_mp_mul) (mp_int *a, mp_int *b, mp_int *p); /* 29 */
- int (*tclBN_mp_mul_d) (mp_int *a, mp_digit b, mp_int *p); /* 30 */
+ int (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */
+ int (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */
int (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */
int (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */
int (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */
- int (*tclBN_mp_or) (mp_int *a, mp_int *b, mp_int *c); /* 34 */
+ int (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */
int (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */
int (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */
void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
int (*tclBN_mp_shrink) (mp_int *a); /* 38 */
void (*tclBN_mp_set) (mp_int *a, mp_digit b); /* 39 */
- int (*tclBN_mp_sqr) (mp_int *a, mp_int *b); /* 40 */
- int (*tclBN_mp_sqrt) (mp_int *a, mp_int *b); /* 41 */
- int (*tclBN_mp_sub) (mp_int *a, mp_int *b, mp_int *c); /* 42 */
+ int (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */
+ int (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
+ int (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
int (*tclBN_mp_sub_d) (mp_int *a, mp_digit b, mp_int *c); /* 43 */
int (*tclBN_mp_to_unsigned_bin) (mp_int *a, unsigned char *b); /* 44 */
int (*tclBN_mp_to_unsigned_bin_n) (mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
int (*tclBN_mp_toradix_n) (mp_int *a, char *str, int radix, int maxlen); /* 46 */
int (*tclBN_mp_unsigned_bin_size) (mp_int *a); /* 47 */
- int (*tclBN_mp_xor) (mp_int *a, mp_int *b, mp_int *c); /* 48 */
+ int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
void (*tclBN_mp_zero) (mp_int *a); /* 49 */
void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
- int (*tclBN_fast_s_mp_mul_digs) (mp_int *a, mp_int *b, mp_int *c, int digs); /* 51 */
- int (*tclBN_fast_s_mp_sqr) (mp_int *a, mp_int *b); /* 52 */
- int (*tclBN_mp_karatsuba_mul) (mp_int *a, mp_int *b, mp_int *c); /* 53 */
- int (*tclBN_mp_karatsuba_sqr) (mp_int *a, mp_int *b); /* 54 */
- int (*tclBN_mp_toom_mul) (mp_int *a, mp_int *b, mp_int *c); /* 55 */
- int (*tclBN_mp_toom_sqr) (mp_int *a, mp_int *b); /* 56 */
- int (*tclBN_s_mp_add) (mp_int *a, mp_int *b, mp_int *c); /* 57 */
- int (*tclBN_s_mp_mul_digs) (mp_int *a, mp_int *b, mp_int *c, int digs); /* 58 */
- int (*tclBN_s_mp_sqr) (mp_int *a, mp_int *b); /* 59 */
- int (*tclBN_s_mp_sub) (mp_int *a, mp_int *b, mp_int *c); /* 60 */
+ int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
+ int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
+ int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
+ int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
+ int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
+ int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
+ int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
+ int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
+ int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
+ int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
- int (*tclBN_mp_expt_d_ex) (mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
+ int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
int (*tclBN_mp_set_long_long) (mp_int *a, Tcl_WideUInt i); /* 68 */
Tcl_WideUInt (*tclBN_mp_get_long_long) (const mp_int *a); /* 69 */
} TclTomMathStubs;
diff --git a/libtommath/bn_fast_s_mp_mul_digs.c b/libtommath/bn_fast_s_mp_mul_digs.c
index a1015af..641b574 100644
--- a/libtommath/bn_fast_s_mp_mul_digs.c
+++ b/libtommath/bn_fast_s_mp_mul_digs.c
@@ -31,7 +31,7 @@
* Based on Algorithm 14.12 on pp.595 of HAC.
*
*/
-int fast_s_mp_mul_digs (mp_int * a, 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];
diff --git a/libtommath/bn_fast_s_mp_sqr.c b/libtommath/bn_fast_s_mp_sqr.c
index f435af9..282d303 100644
--- a/libtommath/bn_fast_s_mp_sqr.c
+++ b/libtommath/bn_fast_s_mp_sqr.c
@@ -25,7 +25,7 @@
After that loop you do the squares and add them in.
*/
-int fast_s_mp_sqr (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;
diff --git a/libtommath/bn_mp_add.c b/libtommath/bn_mp_add.c
index bdb166f..a68c02e 100644
--- a/libtommath/bn_mp_add.c
+++ b/libtommath/bn_mp_add.c
@@ -16,7 +16,7 @@
*/
/* high level addition (handles signs) */
-int mp_add (mp_int * a, mp_int * b, mp_int * c)
+int mp_add (const mp_int * a, const mp_int * b, mp_int * c)
{
int sa, sb, res;
diff --git a/libtommath/bn_mp_and.c b/libtommath/bn_mp_and.c
index 53008a5..e90ab37 100644
--- a/libtommath/bn_mp_and.c
+++ b/libtommath/bn_mp_and.c
@@ -17,10 +17,11 @@
/* AND two ints together */
int
-mp_and (mp_int * a, 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, *x;
+ mp_int t;
+ const mp_int *x;
if (a->used > b->used) {
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c
index 0890e65..30b36b6 100644
--- a/libtommath/bn_mp_div.c
+++ b/libtommath/bn_mp_div.c
@@ -18,7 +18,7 @@
#ifdef BN_MP_DIV_SMALL
/* slower bit-bang division... also smaller */
-int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
+int mp_div(const mp_int * a, const mp_int * b, mp_int * c, mp_int * d)
{
mp_int ta, tb, tq, q;
int res, n, n2;
@@ -100,7 +100,7 @@ LBL_ERR:
* The overall algorithm is as described as
* 14.20 from HAC but fixed to treat these cases.
*/
-int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
+int mp_div (const mp_int * a, const mp_int * b, mp_int * c, mp_int * d)
{
mp_int q, x, y, t1, t2;
int res, n, t, i, norm, neg;
diff --git a/libtommath/bn_mp_div_3.c b/libtommath/bn_mp_div_3.c
index e8504ea..5e75438 100644
--- a/libtommath/bn_mp_div_3.c
+++ b/libtommath/bn_mp_div_3.c
@@ -17,7 +17,7 @@
/* divide by three (based on routine from MPI and the GMP manual) */
int
-mp_div_3 (mp_int * a, mp_int *c, mp_digit * d)
+mp_div_3 (const mp_int * a, mp_int *c, mp_digit * d)
{
mp_int q;
mp_word w, t;
diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c
index d1f2774..4767565 100644
--- a/libtommath/bn_mp_div_d.c
+++ b/libtommath/bn_mp_div_d.c
@@ -33,7 +33,7 @@ static int s_is_power_of_two(mp_digit b, int *p)
}
/* single digit division (based on routine from MPI) */
-int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
+int mp_div_d (const mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
{
mp_int q;
mp_word w;
diff --git a/libtommath/bn_mp_expt_d.c b/libtommath/bn_mp_expt_d.c
index a311926..ffa3b93 100644
--- a/libtommath/bn_mp_expt_d.c
+++ b/libtommath/bn_mp_expt_d.c
@@ -16,7 +16,7 @@
*/
/* wrapper function for mp_expt_d_ex() */
-int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
+int mp_expt_d (const mp_int * a, mp_digit b, mp_int * c)
{
return mp_expt_d_ex(a, b, c, 0);
}
diff --git a/libtommath/bn_mp_expt_d_ex.c b/libtommath/bn_mp_expt_d_ex.c
index c361b27..545d156 100644
--- a/libtommath/bn_mp_expt_d_ex.c
+++ b/libtommath/bn_mp_expt_d_ex.c
@@ -16,7 +16,7 @@
*/
/* calculate c = a**b using a square-multiply algorithm */
-int mp_expt_d_ex (mp_int * a, 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)
{
int res;
unsigned int x;
diff --git a/libtommath/bn_mp_karatsuba_mul.c b/libtommath/bn_mp_karatsuba_mul.c
index 4d982c7..1e6a42b 100644
--- a/libtommath/bn_mp_karatsuba_mul.c
+++ b/libtommath/bn_mp_karatsuba_mul.c
@@ -44,7 +44,7 @@
* Generally though the overhead of this method doesn't pay off
* until a certain size (N ~ 80) is reached.
*/
-int mp_karatsuba_mul (mp_int * a, mp_int * b, mp_int * c)
+int mp_karatsuba_mul (const mp_int * a, const mp_int * b, mp_int * c)
{
mp_int x0, x1, y0, y1, t1, x0y0, x1y1;
int B, err;
diff --git a/libtommath/bn_mp_karatsuba_sqr.c b/libtommath/bn_mp_karatsuba_sqr.c
index 764e85a..90624d0 100644
--- a/libtommath/bn_mp_karatsuba_sqr.c
+++ b/libtommath/bn_mp_karatsuba_sqr.c
@@ -22,7 +22,7 @@
* is essentially the same algorithm but merely
* tuned to perform recursive squarings.
*/
-int mp_karatsuba_sqr (mp_int * a, mp_int * b)
+int mp_karatsuba_sqr (const mp_int * a, mp_int * b)
{
mp_int x0, x1, t1, t2, x0x0, x1x1;
int B, err;
diff --git a/libtommath/bn_mp_mod.c b/libtommath/bn_mp_mod.c
index 06240a0..fff0f92 100644
--- a/libtommath/bn_mp_mod.c
+++ b/libtommath/bn_mp_mod.c
@@ -17,7 +17,7 @@
/* c = a mod b, 0 <= c < b if b > 0, b < c <= 0 if b < 0 */
int
-mp_mod (mp_int * a, mp_int * b, mp_int * c)
+mp_mod (const mp_int * a, const mp_int * b, mp_int * c)
{
mp_int t;
int res;
diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c
index cc3b9c8..b8b85c8 100644
--- a/libtommath/bn_mp_mul.c
+++ b/libtommath/bn_mp_mul.c
@@ -16,7 +16,7 @@
*/
/* high level multiplication (handles sign) */
-int mp_mul (mp_int * a, mp_int * b, mp_int * c)
+int mp_mul (const mp_int * a, const mp_int * b, mp_int * c)
{
int res, neg;
neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
diff --git a/libtommath/bn_mp_mul_d.c b/libtommath/bn_mp_mul_d.c
index 6954ed3..266b082 100644
--- a/libtommath/bn_mp_mul_d.c
+++ b/libtommath/bn_mp_mul_d.c
@@ -17,7 +17,7 @@
/* multiply by a digit */
int
-mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
+mp_mul_d (const mp_int * a, mp_digit b, mp_int * c)
{
mp_digit u, *tmpa, *tmpc;
mp_word r;
diff --git a/libtommath/bn_mp_or.c b/libtommath/bn_mp_or.c
index b9775ce..afe8467 100644
--- a/libtommath/bn_mp_or.c
+++ b/libtommath/bn_mp_or.c
@@ -16,10 +16,11 @@
*/
/* OR two ints together */
-int mp_or (mp_int * a, mp_int * b, mp_int * c)
+int mp_or (const mp_int * a, const mp_int * b, mp_int * c)
{
int res, ix, px;
- mp_int t, *x;
+ mp_int t;
+ const mp_int *x;
if (a->used > b->used) {
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
diff --git a/libtommath/bn_mp_sqr.c b/libtommath/bn_mp_sqr.c
index ffe94e2..a61f506 100644
--- a/libtommath/bn_mp_sqr.c
+++ b/libtommath/bn_mp_sqr.c
@@ -17,7 +17,7 @@
/* computes b = a*a */
int
-mp_sqr (mp_int * a, mp_int * b)
+mp_sqr (const mp_int * a, mp_int * b)
{
int res;
diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c
index 775e85f..ce8bd0e 100644
--- a/libtommath/bn_mp_sqrt.c
+++ b/libtommath/bn_mp_sqrt.c
@@ -20,7 +20,7 @@
#endif
/* this function is less generic than mp_n_root, simpler and faster */
-int mp_sqrt(mp_int *arg, mp_int *ret)
+int mp_sqrt(const mp_int *arg, mp_int *ret)
{
int res;
mp_int t1,t2;
diff --git a/libtommath/bn_mp_sub.c b/libtommath/bn_mp_sub.c
index 2f73faa..9ff03d5 100644
--- a/libtommath/bn_mp_sub.c
+++ b/libtommath/bn_mp_sub.c
@@ -17,7 +17,7 @@
/* high level subtraction (handles signs) */
int
-mp_sub (mp_int * a, mp_int * b, mp_int * c)
+mp_sub (const mp_int * a, const mp_int * b, mp_int * c)
{
int sa, sb, res;
diff --git a/libtommath/bn_mp_toom_mul.c b/libtommath/bn_mp_toom_mul.c
index 4a574fc..0bf940d 100644
--- a/libtommath/bn_mp_toom_mul.c
+++ b/libtommath/bn_mp_toom_mul.c
@@ -22,7 +22,7 @@
* only particularly useful on VERY large inputs
* (we're talking 1000s of digits here...).
*/
-int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
+int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
{
mp_int w0, w1, w2, w3, w4, tmp1, tmp2, a0, a1, a2, b0, b1, b2;
int res, B;
diff --git a/libtommath/bn_mp_toom_sqr.c b/libtommath/bn_mp_toom_sqr.c
index 0a38192..842ae47 100644
--- a/libtommath/bn_mp_toom_sqr.c
+++ b/libtommath/bn_mp_toom_sqr.c
@@ -17,7 +17,7 @@
/* squaring using Toom-Cook 3-way algorithm */
int
-mp_toom_sqr(mp_int *a, mp_int *b)
+mp_toom_sqr(const mp_int *a, mp_int *b)
{
mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2;
int res, B;
diff --git a/libtommath/bn_mp_xor.c b/libtommath/bn_mp_xor.c
index f51fc8e..9f7b086 100644
--- a/libtommath/bn_mp_xor.c
+++ b/libtommath/bn_mp_xor.c
@@ -17,10 +17,11 @@
/* XOR two ints together */
int
-mp_xor (mp_int * a, mp_int * b, mp_int * c)
+mp_xor (const mp_int * a, const mp_int * b, mp_int * c)
{
int res, ix, px;
- mp_int t, *x;
+ mp_int t;
+ const mp_int *x;
if (a->used > b->used) {
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
diff --git a/libtommath/bn_s_mp_add.c b/libtommath/bn_s_mp_add.c
index 7a100e8..432e3b4 100644
--- a/libtommath/bn_s_mp_add.c
+++ b/libtommath/bn_s_mp_add.c
@@ -17,9 +17,9 @@
/* low level addition, based on HAC pp.594, Algorithm 14.7 */
int
-s_mp_add (mp_int * a, mp_int * b, mp_int * c)
+s_mp_add (const mp_int * a, const mp_int * b, mp_int * c)
{
- mp_int *x;
+ const mp_int *x;
int olduse, res, min, max;
/* find sizes, we let |a| <= |b| which means we have to sort
diff --git a/libtommath/bn_s_mp_mul_digs.c b/libtommath/bn_s_mp_mul_digs.c
index 8f1bf97..d32bf15 100644
--- a/libtommath/bn_s_mp_mul_digs.c
+++ b/libtommath/bn_s_mp_mul_digs.c
@@ -19,7 +19,7 @@
* HAC pp. 595, Algorithm 14.12 Modified so you can control how
* many digits of output are created.
*/
-int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
+int s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs)
{
mp_int t;
int res, pa, pb, ix, iy;
diff --git a/libtommath/bn_s_mp_sqr.c b/libtommath/bn_s_mp_sqr.c
index ac0e157..de6a3ea 100644
--- a/libtommath/bn_s_mp_sqr.c
+++ b/libtommath/bn_s_mp_sqr.c
@@ -16,7 +16,7 @@
*/
/* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
-int s_mp_sqr (mp_int * a, mp_int * b)
+int s_mp_sqr (const mp_int * a, mp_int * b)
{
mp_int t;
int res, ix, iy, pa;
diff --git a/libtommath/bn_s_mp_sub.c b/libtommath/bn_s_mp_sub.c
index 8091f4a..7f49d66 100644
--- a/libtommath/bn_s_mp_sub.c
+++ b/libtommath/bn_s_mp_sub.c
@@ -17,7 +17,7 @@
/* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
int
-s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
+s_mp_sub (const mp_int * a, const mp_int * b, mp_int * c)
{
int olduse, res, min, max;
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index a8c9e21..b183b8a 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -288,13 +288,13 @@ int mp_rand(mp_int *a, int digits);
/* ---> binary operations <--- */
/* c = a XOR b */
-int mp_xor(mp_int *a, mp_int *b, mp_int *c);
+int mp_xor(const mp_int *a, const mp_int *b, mp_int *c);
/* c = a OR b */
-int mp_or(mp_int *a, mp_int *b, mp_int *c);
+int mp_or(const mp_int *a, const mp_int *b, mp_int *c);
/* c = a AND b */
-int mp_and(mp_int *a, mp_int *b, mp_int *c);
+int mp_and(const mp_int *a, const mp_int *b, mp_int *c);
/* ---> Basic arithmetic <--- */
@@ -302,7 +302,7 @@ int mp_and(mp_int *a, mp_int *b, mp_int *c);
int mp_neg(const mp_int *a, mp_int *b);
/* b = |a| */
-int mp_abs(mp_int *a, mp_int *b);
+int mp_abs(const mp_int *a, mp_int *b);
/* compare a to b */
int mp_cmp(const mp_int *a, const mp_int *b);
@@ -311,22 +311,22 @@ int mp_cmp(const mp_int *a, const mp_int *b);
int mp_cmp_mag(const mp_int *a, const mp_int *b);
/* c = a + b */
-int mp_add(mp_int *a, mp_int *b, mp_int *c);
+int mp_add(const mp_int *a, const mp_int *b, mp_int *c);
/* c = a - b */
-int mp_sub(mp_int *a, mp_int *b, mp_int *c);
+int mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
/* c = a * b */
-int mp_mul(mp_int *a, mp_int *b, mp_int *c);
+int mp_mul(const mp_int *a, const mp_int *b, mp_int *c);
/* b = a*a */
-int mp_sqr(mp_int *a, mp_int *b);
+int mp_sqr(const mp_int *a, mp_int *b);
/* a/b => cb + d == a */
-int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);
/* c = a mod b, 0 <= c < b */
-int mp_mod(mp_int *a, mp_int *b, mp_int *c);
+int mp_mod(const mp_int *a, const mp_int *b, mp_int *c);
/* ---> single digit functions <--- */
@@ -334,26 +334,26 @@ int mp_mod(mp_int *a, mp_int *b, mp_int *c);
int mp_cmp_d(const mp_int *a, mp_digit b);
/* c = a + b */
-int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_add_d(const mp_int *a, const mp_digit b, mp_int *c);
/* c = a - b */
int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
/* c = a * b */
-int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c);
/* a/b => cb + d == a */
-int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
+int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
/* a/3 => 3c + d == a */
-int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
+int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d);
/* c = a**b */
-int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
-int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
+int mp_expt_d(const mp_int *a, const mp_digit b, mp_int *c);
+int mp_expt_d_ex (const mp_int * a, const mp_digit b, mp_int * c, int fast);
/* c = a mod b, 0 <= c < b */
-int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
+int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c);
/* ---> number theory <--- */
@@ -389,7 +389,7 @@ 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);
/* 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) */
int mp_sqrtmod_prime(mp_int *arg, mp_int *prime, mp_int *ret);
diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h
index 3217ee7..07607a8 100644
--- a/libtommath/tommath_private.h
+++ b/libtommath/tommath_private.h
@@ -57,19 +57,19 @@ extern "C" {
#endif
/* lowlevel functions, do not call! */
-int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
-int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c);
+int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
-int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int s_mp_mul_digs(mp_int *a, 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 s_mp_mul_digs(const mp_int *a, const 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 s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int fast_s_mp_sqr(mp_int *a, mp_int *b);
-int s_mp_sqr(mp_int *a, mp_int *b);
-int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
-int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
-int mp_karatsuba_sqr(mp_int *a, mp_int *b);
-int mp_toom_sqr(mp_int *a, mp_int *b);
+int fast_s_mp_sqr(const mp_int *a, mp_int *b);
+int s_mp_sqr(const mp_int *a, mp_int *b);
+int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c);
+int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c);
+int mp_karatsuba_sqr(const mp_int *a, mp_int *b);
+int mp_toom_sqr(const mp_int *a, mp_int *b);
int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
int fast_mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho);