Add 'const' keyword in various places. Adopted from Tcl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
diff --git a/bn_mp_cmp.c b/bn_mp_cmp.c
index 9047060..a505746 100644
--- a/bn_mp_cmp.c
+++ b/bn_mp_cmp.c
@@ -16,7 +16,7 @@
*/
/* compare two ints (signed)*/
-int mp_cmp(mp_int *a, mp_int *b)
+int mp_cmp(const mp_int *a, mp_int *b)
{
/* compare based on sign */
if (a->sign != b->sign) {
diff --git a/bn_mp_cmp_d.c b/bn_mp_cmp_d.c
index 27a546d..576a073 100644
--- a/bn_mp_cmp_d.c
+++ b/bn_mp_cmp_d.c
@@ -16,7 +16,7 @@
*/
/* compare a digit */
-int mp_cmp_d(mp_int *a, mp_digit b)
+int mp_cmp_d(const mp_int *a, mp_digit b)
{
/* compare based on sign */
if (a->sign == MP_NEG) {
diff --git a/bn_mp_cmp_mag.c b/bn_mp_cmp_mag.c
index ca2bc88..0066ca0 100644
--- a/bn_mp_cmp_mag.c
+++ b/bn_mp_cmp_mag.c
@@ -16,7 +16,7 @@
*/
/* compare maginitude of two ints (unsigned) */
-int mp_cmp_mag(mp_int *a, mp_int *b)
+int mp_cmp_mag(const mp_int *a, mp_int *b)
{
int n;
mp_digit *tmpa, *tmpb;
diff --git a/bn_mp_cnt_lsb.c b/bn_mp_cnt_lsb.c
index 7273655..9a94d3d 100644
--- a/bn_mp_cnt_lsb.c
+++ b/bn_mp_cnt_lsb.c
@@ -20,7 +20,7 @@ static const int lnz[16] = {
};
/* Counts the number of lsbs which are zero before the first zero bit */
-int mp_cnt_lsb(mp_int *a)
+int mp_cnt_lsb(const mp_int *a)
{
int x;
mp_digit q, qq;
diff --git a/bn_mp_copy.c b/bn_mp_copy.c
index bed03b2..17816e8 100644
--- a/bn_mp_copy.c
+++ b/bn_mp_copy.c
@@ -16,7 +16,7 @@
*/
/* copy, b = a */
-int mp_copy(mp_int *a, mp_int *b)
+int mp_copy(const mp_int *a, mp_int *b)
{
int res, n;
diff --git a/bn_mp_count_bits.c b/bn_mp_count_bits.c
index dea364f..7424581 100644
--- a/bn_mp_count_bits.c
+++ b/bn_mp_count_bits.c
@@ -16,7 +16,7 @@
*/
/* returns the number of bits in an int */
-int mp_count_bits(mp_int *a)
+int mp_count_bits(const mp_int *a)
{
int r;
mp_digit q;
diff --git a/bn_mp_div_2d.c b/bn_mp_div_2d.c
index d6723ee..eae3498 100644
--- a/bn_mp_div_2d.c
+++ b/bn_mp_div_2d.c
@@ -16,7 +16,7 @@
*/
/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
-int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d)
+int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
{
mp_digit D, r, rr;
int x, res;
diff --git a/bn_mp_init_copy.c b/bn_mp_init_copy.c
index c711e06..5681015 100644
--- a/bn_mp_init_copy.c
+++ b/bn_mp_init_copy.c
@@ -16,7 +16,7 @@
*/
/* creates "a" then copies b into it */
-int mp_init_copy(mp_int *a, mp_int *b)
+int mp_init_copy(mp_int *a, const mp_int *b)
{
int res;
diff --git a/bn_mp_mod_2d.c b/bn_mp_mod_2d.c
index 59270b9..8e69757 100644
--- a/bn_mp_mod_2d.c
+++ b/bn_mp_mod_2d.c
@@ -16,7 +16,7 @@
*/
/* calc a value mod 2**b */
-int mp_mod_2d(mp_int *a, int b, mp_int *c)
+int mp_mod_2d(const mp_int *a, int b, mp_int *c)
{
int x, res;
diff --git a/bn_mp_mul_2d.c b/bn_mp_mul_2d.c
index b3d92a9..4938e57 100644
--- a/bn_mp_mul_2d.c
+++ b/bn_mp_mul_2d.c
@@ -16,7 +16,7 @@
*/
/* shift left by a certain bit count */
-int mp_mul_2d(mp_int *a, int b, mp_int *c)
+int mp_mul_2d(const mp_int *a, int b, mp_int *c)
{
mp_digit d;
int res;
diff --git a/bn_mp_neg.c b/bn_mp_neg.c
index b30d044..75f8bbd 100644
--- a/bn_mp_neg.c
+++ b/bn_mp_neg.c
@@ -16,7 +16,7 @@
*/
/* b = -a */
-int mp_neg(mp_int *a, mp_int *b)
+int mp_neg(const mp_int *a, mp_int *b)
{
int res;
if (a != b) {
diff --git a/bn_mp_radix_size.c b/bn_mp_radix_size.c
index a6e2f04..29355cb 100644
--- a/bn_mp_radix_size.c
+++ b/bn_mp_radix_size.c
@@ -16,7 +16,7 @@
*/
/* returns size of ASCII reprensentation */
-int mp_radix_size(mp_int *a, int radix, int *size)
+int mp_radix_size(const mp_int *a, int radix, int *size)
{
int res, digs;
mp_int t;
diff --git a/tommath.h b/tommath.h
index 2aaea5b..3f49767 100644
--- a/tommath.h
+++ b/tommath.h
@@ -238,10 +238,10 @@ int mp_init_set(mp_int *a, mp_digit b);
int mp_init_set_int(mp_int *a, unsigned long b);
/* copy, b = a */
-int mp_copy(mp_int *a, mp_int *b);
+int mp_copy(const mp_int *a, mp_int *b);
/* inits and copies, a = b */
-int mp_init_copy(mp_int *a, mp_int *b);
+int mp_init_copy(mp_int *a, const mp_int *b);
/* trim unused digits */
void mp_clamp(mp_int *a);
@@ -261,25 +261,25 @@ void mp_rshd(mp_int *a, int b);
int mp_lshd(mp_int *a, int b);
/* c = a / 2**b, implemented as c = a >> b */
-int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
+int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d);
/* b = a/2 */
int mp_div_2(mp_int *a, mp_int *b);
/* c = a * 2**b, implemented as c = a << b */
-int mp_mul_2d(mp_int *a, int b, mp_int *c);
+int mp_mul_2d(const mp_int *a, int b, mp_int *c);
/* b = a*2 */
int mp_mul_2(mp_int *a, mp_int *b);
/* c = a mod 2**b */
-int mp_mod_2d(mp_int *a, int b, mp_int *c);
+int mp_mod_2d(const mp_int *a, int b, mp_int *c);
/* computes a = 2**b */
int mp_2expt(mp_int *a, int b);
/* Counts the number of lsbs which are zero before the first zero bit */
-int mp_cnt_lsb(mp_int *a);
+int mp_cnt_lsb(const mp_int *a);
/* I Love Earth! */
@@ -299,16 +299,16 @@ int mp_and(mp_int *a, mp_int *b, mp_int *c);
/* ---> Basic arithmetic <--- */
/* b = -a */
-int mp_neg(mp_int *a, mp_int *b);
+int mp_neg(const mp_int *a, mp_int *b);
/* b = |a| */
int mp_abs(mp_int *a, mp_int *b);
/* compare a to b */
-int mp_cmp(mp_int *a, mp_int *b);
+int mp_cmp(const mp_int *a, const mp_int *b);
/* compare |a| to |b| */
-int mp_cmp_mag(mp_int *a, 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);
@@ -331,7 +331,7 @@ int mp_mod(mp_int *a, mp_int *b, mp_int *c);
/* ---> single digit functions <--- */
/* compare against a single digit */
-int mp_cmp_d(mp_int *a, mp_digit b);
+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);
@@ -524,7 +524,7 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
/* ---> radix conversion <--- */
-int mp_count_bits(mp_int *a);
+int mp_count_bits(const mp_int *a);
int mp_unsigned_bin_size(mp_int *a);
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
@@ -539,7 +539,7 @@ int mp_to_signed_bin_n(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_radix_size(mp_int *a, int radix, int *size);
+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);