summaryrefslogtreecommitdiffstats
path: root/libtommath
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath')
-rw-r--r--libtommath/bn_mp_add_d.c9
-rw-r--r--libtommath/bn_mp_fwrite.c2
-rw-r--r--libtommath/bn_mp_signed_bin_size.c2
-rw-r--r--libtommath/bn_mp_sub_d.c9
-rw-r--r--libtommath/bn_mp_to_signed_bin.c2
-rw-r--r--libtommath/bn_mp_to_signed_bin_n.c2
-rw-r--r--libtommath/bn_mp_to_unsigned_bin.c2
-rw-r--r--libtommath/bn_mp_to_unsigned_bin_n.c2
-rw-r--r--libtommath/bn_mp_toradix.c2
-rw-r--r--libtommath/bn_mp_toradix_n.c2
-rw-r--r--libtommath/bn_mp_unsigned_bin_size.c2
-rw-r--r--libtommath/tommath.h20
12 files changed, 29 insertions, 27 deletions
diff --git a/libtommath/bn_mp_add_d.c b/libtommath/bn_mp_add_d.c
index fd1a186..c2f2e0e 100644
--- a/libtommath/bn_mp_add_d.c
+++ b/libtommath/bn_mp_add_d.c
@@ -17,7 +17,7 @@
/* single digit addition */
int
-mp_add_d (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;
@@ -31,14 +31,15 @@ mp_add_d (mp_int * a, mp_digit b, mp_int * c)
/* 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;
+ a_.sign = MP_ZPOS;
/* c = |a| - b */
- res = mp_sub_d(a, b, c);
+ res = mp_sub_d(&a_, b, c);
/* fix sign */
- a->sign = c->sign = MP_NEG;
+ c->sign = MP_NEG;
/* clamp */
mp_clamp(c);
diff --git a/libtommath/bn_mp_fwrite.c b/libtommath/bn_mp_fwrite.c
index 23b5f64..e2b5ec2 100644
--- a/libtommath/bn_mp_fwrite.c
+++ b/libtommath/bn_mp_fwrite.c
@@ -16,7 +16,7 @@
*/
#ifndef LTM_NO_FILE
-int mp_fwrite(mp_int *a, int radix, FILE *stream)
+int mp_fwrite(const mp_int *a, int radix, FILE *stream)
{
char *buf;
int err, len, x;
diff --git a/libtommath/bn_mp_signed_bin_size.c b/libtommath/bn_mp_signed_bin_size.c
index 0910333..6b57bed 100644
--- a/libtommath/bn_mp_signed_bin_size.c
+++ b/libtommath/bn_mp_signed_bin_size.c
@@ -16,7 +16,7 @@
*/
/* get the size for an signed equivalent */
-int mp_signed_bin_size (mp_int * a)
+int mp_signed_bin_size (const mp_int * a)
{
return 1 + mp_unsigned_bin_size (a);
}
diff --git a/libtommath/bn_mp_sub_d.c b/libtommath/bn_mp_sub_d.c
index 5e96030..2d24899 100644
--- a/libtommath/bn_mp_sub_d.c
+++ b/libtommath/bn_mp_sub_d.c
@@ -17,7 +17,7 @@
/* single digit subtraction */
int
-mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
+mp_sub_d (const mp_int * a, mp_digit b, mp_int * c)
{
mp_digit *tmpa, *tmpc, mu;
int res, ix, oldused;
@@ -33,9 +33,10 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
* addition [with fudged signs]
*/
if (a->sign == MP_NEG) {
- a->sign = MP_ZPOS;
- res = mp_add_d(a, b, c);
- a->sign = c->sign = MP_NEG;
+ mp_int a_ = *a;
+ a_.sign = MP_ZPOS;
+ res = mp_add_d(&a_, b, c);
+ c->sign = MP_NEG;
/* clamp */
mp_clamp(c);
diff --git a/libtommath/bn_mp_to_signed_bin.c b/libtommath/bn_mp_to_signed_bin.c
index c49c87d..69f6423 100644
--- a/libtommath/bn_mp_to_signed_bin.c
+++ b/libtommath/bn_mp_to_signed_bin.c
@@ -16,7 +16,7 @@
*/
/* store in signed [big endian] format */
-int mp_to_signed_bin (mp_int * a, unsigned char *b)
+int mp_to_signed_bin (const mp_int * a, unsigned char *b)
{
int res;
diff --git a/libtommath/bn_mp_to_signed_bin_n.c b/libtommath/bn_mp_to_signed_bin_n.c
index dc5ec26..fc0e822 100644
--- a/libtommath/bn_mp_to_signed_bin_n.c
+++ b/libtommath/bn_mp_to_signed_bin_n.c
@@ -16,7 +16,7 @@
*/
/* store in signed [big endian] format */
-int mp_to_signed_bin_n (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)
{
if (*outlen < (unsigned long)mp_signed_bin_size(a)) {
return MP_VAL;
diff --git a/libtommath/bn_mp_to_unsigned_bin.c b/libtommath/bn_mp_to_unsigned_bin.c
index d249359..e8d9c4f 100644
--- a/libtommath/bn_mp_to_unsigned_bin.c
+++ b/libtommath/bn_mp_to_unsigned_bin.c
@@ -16,7 +16,7 @@
*/
/* store in unsigned [big endian] format */
-int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
+int mp_to_unsigned_bin (const mp_int * a, unsigned char *b)
{
int x, res;
mp_int t;
diff --git a/libtommath/bn_mp_to_unsigned_bin_n.c b/libtommath/bn_mp_to_unsigned_bin_n.c
index f671621..9e9eef5 100644
--- a/libtommath/bn_mp_to_unsigned_bin_n.c
+++ b/libtommath/bn_mp_to_unsigned_bin_n.c
@@ -16,7 +16,7 @@
*/
/* store in unsigned [big endian] format */
-int mp_to_unsigned_bin_n (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)
{
if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) {
return MP_VAL;
diff --git a/libtommath/bn_mp_toradix.c b/libtommath/bn_mp_toradix.c
index 3337765..59676a7 100644
--- a/libtommath/bn_mp_toradix.c
+++ b/libtommath/bn_mp_toradix.c
@@ -16,7 +16,7 @@
*/
/* stores a bignum as a ASCII string in a given radix (2..64) */
-int mp_toradix (mp_int * a, char *str, int radix)
+int mp_toradix (const mp_int * a, char *str, int radix)
{
int res, digs;
mp_int t;
diff --git a/libtommath/bn_mp_toradix_n.c b/libtommath/bn_mp_toradix_n.c
index ae24ada..c0079c8 100644
--- a/libtommath/bn_mp_toradix_n.c
+++ b/libtommath/bn_mp_toradix_n.c
@@ -19,7 +19,7 @@
*
* Stores upto maxlen-1 chars and always a NULL byte
*/
-int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
+int mp_toradix_n(const mp_int * a, char *str, int radix, int maxlen)
{
int res, digs;
mp_int t;
diff --git a/libtommath/bn_mp_unsigned_bin_size.c b/libtommath/bn_mp_unsigned_bin_size.c
index f46d0ba..74655e7 100644
--- a/libtommath/bn_mp_unsigned_bin_size.c
+++ b/libtommath/bn_mp_unsigned_bin_size.c
@@ -16,7 +16,7 @@
*/
/* get the size for an unsigned equivalent */
-int mp_unsigned_bin_size (mp_int * a)
+int mp_unsigned_bin_size (const mp_int * a)
{
int size = mp_count_bits (a);
return (size / 8) + (((size & 7) != 0) ? 1 : 0);
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index b183b8a..527f316 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -337,7 +337,7 @@ int mp_cmp_d(const mp_int *a, mp_digit b);
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(const mp_int *a, mp_digit b, mp_int *c);
@@ -526,24 +526,24 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
/* ---> radix conversion <--- */
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);
-int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
-int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
+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_signed_bin_size(mp_int *a);
+int mp_signed_bin_size(const mp_int *a);
int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
-int mp_to_signed_bin(mp_int *a, unsigned char *b);
-int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
+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_read_radix(mp_int *a, const char *str, int radix);
-int mp_toradix(mp_int *a, char *str, int radix);
-int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
+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_radix_size(const mp_int *a, int radix, int *size);
#ifndef LTM_NO_FILE
int mp_fread(mp_int *a, int radix, FILE *stream);
-int mp_fwrite(mp_int *a, int radix, FILE *stream);
+int mp_fwrite(const mp_int *a, int radix, FILE *stream);
#endif
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))