Add 'const' keyword in various places. Adopted from Tcl

This commit is contained in:
nijtmans 2017-09-19 13:35:15 +02:00 committed by Steffen Jaeckel
parent 5aec0c4094
commit 41de585524
13 changed files with 24 additions and 24 deletions

View File

@ -16,7 +16,7 @@
*/ */
/* compare two ints (signed)*/ /* 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 */ /* compare based on sign */
if (a->sign != b->sign) { if (a->sign != b->sign) {

View File

@ -16,7 +16,7 @@
*/ */
/* compare a digit */ /* 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 */ /* compare based on sign */
if (a->sign == MP_NEG) { if (a->sign == MP_NEG) {

View File

@ -16,7 +16,7 @@
*/ */
/* compare maginitude of two ints (unsigned) */ /* 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; int n;
mp_digit *tmpa, *tmpb; mp_digit *tmpa, *tmpb;

View File

@ -20,7 +20,7 @@ static const int lnz[16] = {
}; };
/* Counts the number of lsbs which are zero before the first zero bit */ /* 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; int x;
mp_digit q, qq; mp_digit q, qq;

View File

@ -16,7 +16,7 @@
*/ */
/* copy, b = a */ /* 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; int res, n;

View File

@ -16,7 +16,7 @@
*/ */
/* returns the number of bits in an int */ /* 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; int r;
mp_digit q; mp_digit q;

View File

@ -16,7 +16,7 @@
*/ */
/* shift right by a certain bit count (store quotient in c, optional remainder in d) */ /* 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; mp_digit D, r, rr;
int x, res; int x, res;

View File

@ -16,7 +16,7 @@
*/ */
/* creates "a" then copies b into it */ /* 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; int res;

View File

@ -16,7 +16,7 @@
*/ */
/* calc a value mod 2**b */ /* 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; int x, res;

View File

@ -16,7 +16,7 @@
*/ */
/* shift left by a certain bit count */ /* 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; mp_digit d;
int res; int res;

View File

@ -16,7 +16,7 @@
*/ */
/* b = -a */ /* b = -a */
int mp_neg(mp_int *a, mp_int *b) int mp_neg(const mp_int *a, mp_int *b)
{ {
int res; int res;
if (a != b) { if (a != b) {

View File

@ -16,7 +16,7 @@
*/ */
/* returns size of ASCII reprensentation */ /* 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; int res, digs;
mp_int t; mp_int t;

View File

@ -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); int mp_init_set_int(mp_int *a, unsigned long b);
/* copy, b = a */ /* 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 */ /* 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 */ /* trim unused digits */
void mp_clamp(mp_int *a); 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); int mp_lshd(mp_int *a, int b);
/* c = a / 2**b, implemented as c = a >> 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 */ /* b = a/2 */
int mp_div_2(mp_int *a, mp_int *b); int mp_div_2(mp_int *a, mp_int *b);
/* c = a * 2**b, implemented as c = a << 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 */ /* b = a*2 */
int mp_mul_2(mp_int *a, mp_int *b); int mp_mul_2(mp_int *a, mp_int *b);
/* c = a mod 2**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 */ /* computes a = 2**b */
int mp_2expt(mp_int *a, int b); int mp_2expt(mp_int *a, int b);
/* Counts the number of lsbs which are zero before the first zero bit */ /* 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! */ /* I Love Earth! */
@ -299,16 +299,16 @@ int mp_and(mp_int *a, mp_int *b, mp_int *c);
/* ---> Basic arithmetic <--- */ /* ---> Basic arithmetic <--- */
/* b = -a */ /* b = -a */
int mp_neg(mp_int *a, mp_int *b); int mp_neg(const mp_int *a, mp_int *b);
/* b = |a| */ /* b = |a| */
int mp_abs(mp_int *a, mp_int *b); int mp_abs(mp_int *a, mp_int *b);
/* compare a to 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| */ /* 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 */ /* c = a + b */
int mp_add(mp_int *a, mp_int *b, mp_int *c); 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 <--- */ /* ---> single digit functions <--- */
/* compare against a single digit */ /* 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 */ /* c = a + b */
int mp_add_d(mp_int *a, mp_digit b, mp_int *c); 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); int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
/* ---> radix conversion <--- */ /* ---> 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_unsigned_bin_size(mp_int *a);
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c); 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_read_radix(mp_int *a, const char *str, int radix);
int mp_toradix(mp_int *a, 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_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 #ifndef LTM_NO_FILE
int mp_fread(mp_int *a, int radix, FILE *stream); int mp_fread(mp_int *a, int radix, FILE *stream);