add missing space after comma

This commit is contained in:
Francois Perrad 2017-08-28 21:40:10 +02:00
parent 0135749e44
commit 378be117a3
8 changed files with 33 additions and 33 deletions

View File

@ -20,7 +20,7 @@
*/ */
int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3) int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
{ {
mp_int u1,u2,u3,v1,v2,v3,t1,t2,t3,q,tmp; mp_int u1, u2, u3, v1, v2, v3, t1, t2, t3, q, tmp;
int err; int err;
if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) { if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {

View File

@ -26,13 +26,13 @@ unsigned long mp_get_int(mp_int * a)
} }
/* get number of digits of the lsb we have to read */ /* get number of digits of the lsb we have to read */
i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */ /* get most significant digit of result */
res = DIGIT(a,i); res = DIGIT(a, i);
while (--i >= 0) { while (--i >= 0) {
res = (res << DIGIT_BIT) | DIGIT(a,i); res = (res << DIGIT_BIT) | DIGIT(a, i);
} }
/* force result to 32-bits always so it is consistent on non 32-bit platforms */ /* force result to 32-bits always so it is consistent on non 32-bit platforms */

View File

@ -26,14 +26,14 @@ unsigned long mp_get_long(mp_int * a)
} }
/* get number of digits of the lsb we have to read */ /* get number of digits of the lsb we have to read */
i = MIN(a->used,(int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; i = MIN(a->used, (int)(((sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */ /* get most significant digit of result */
res = DIGIT(a,i); res = DIGIT(a, i);
#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32) #if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32)
while (--i >= 0) { while (--i >= 0) {
res = (res << DIGIT_BIT) | DIGIT(a,i); res = (res << DIGIT_BIT) | DIGIT(a, i);
} }
#endif #endif
return res; return res;

View File

@ -26,14 +26,14 @@ unsigned long long mp_get_long_long (mp_int * a)
} }
/* get number of digits of the lsb we have to read */ /* get number of digits of the lsb we have to read */
i = MIN(a->used,(int)(((sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; i = MIN(a->used, (int)(((sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
/* get most significant digit of result */ /* get most significant digit of result */
res = DIGIT(a,i); res = DIGIT(a, i);
#if DIGIT_BIT < 64 #if DIGIT_BIT < 64
while (--i >= 0) { while (--i >= 0) {
res = (res << DIGIT_BIT) | DIGIT(a,i); res = (res << DIGIT_BIT) | DIGIT(a, i);
} }
#endif #endif
return res; return res;

View File

@ -38,7 +38,7 @@ static const char rem_105[105] = {
}; };
/* Store non-zero to ret if arg is square, and zero if not */ /* Store non-zero to ret if arg is square, and zero if not */
int mp_is_square(mp_int *arg,int *ret) int mp_is_square(mp_int *arg, int *ret)
{ {
int res; int res;
mp_digit c; mp_digit c;
@ -58,12 +58,12 @@ int mp_is_square(mp_int *arg,int *ret)
} }
/* First check mod 128 (suppose that DIGIT_BIT is at least 7) */ /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
if (rem_128[127 & DIGIT(arg,0)] == 1) { if (rem_128[127 & DIGIT(arg, 0)] == 1) {
return MP_OKAY; return MP_OKAY;
} }
/* Next check mod 105 (3*5*7) */ /* Next check mod 105 (3*5*7) */
if ((res = mp_mod_d(arg,105,&c)) != MP_OKAY) { if ((res = mp_mod_d(arg, 105, &c)) != MP_OKAY) {
return res; return res;
} }
if (rem_105[c] == 1) { if (rem_105[c] == 1) {
@ -71,10 +71,10 @@ int mp_is_square(mp_int *arg,int *ret)
} }
if ((res = mp_init_set_int(&t,11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) { if ((res = mp_init_set_int(&t, 11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
return res; return res;
} }
if ((res = mp_mod(arg,&t,&t)) != MP_OKAY) { if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) {
goto ERR; goto ERR;
} }
r = mp_get_int(&t); r = mp_get_int(&t);
@ -91,14 +91,14 @@ int mp_is_square(mp_int *arg,int *ret)
if (((1L<<(r%31)) & 0x6DE2B848L) != 0L) goto ERR; if (((1L<<(r%31)) & 0x6DE2B848L) != 0L) goto ERR;
/* Final check - is sqr(sqrt(arg)) == arg ? */ /* Final check - is sqr(sqrt(arg)) == arg ? */
if ((res = mp_sqrt(arg,&t)) != MP_OKAY) { if ((res = mp_sqrt(arg, &t)) != MP_OKAY) {
goto ERR; goto ERR;
} }
if ((res = mp_sqr(&t,&t)) != MP_OKAY) { if ((res = mp_sqr(&t, &t)) != MP_OKAY) {
goto ERR; goto ERR;
} }
*ret = (mp_cmp_mag(&t,arg) == MP_EQ) ? MP_YES : MP_NO; *ret = (mp_cmp_mag(&t, arg) == MP_EQ) ? MP_YES : MP_NO;
ERR:mp_clear(&t); ERR:mp_clear(&t);
return res; return res;
} }

View File

@ -19,7 +19,7 @@
int mp_sqrt(mp_int *arg, mp_int *ret) int mp_sqrt(mp_int *arg, mp_int *ret)
{ {
int res; int res;
mp_int t1,t2; mp_int t1, t2;
/* must be positive */ /* must be positive */
if (arg->sign == MP_NEG) { if (arg->sign == MP_NEG) {
@ -41,33 +41,33 @@ int mp_sqrt(mp_int *arg, mp_int *ret)
} }
/* First approx. (not very bad for large arg) */ /* First approx. (not very bad for large arg) */
mp_rshd (&t1,t1.used/2); mp_rshd (&t1, t1.used/2);
/* t1 > 0 */ /* t1 > 0 */
if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) { if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
goto E1; goto E1;
} }
if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) { if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
goto E1; goto E1;
} }
if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) { if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) {
goto E1; goto E1;
} }
/* And now t1 > sqrt(arg) */ /* And now t1 > sqrt(arg) */
do { do {
if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) { if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
goto E1; goto E1;
} }
if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) { if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
goto E1; goto E1;
} }
if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) { if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) {
goto E1; goto E1;
} }
/* t1 >= sqrt(arg) >= t2 at this point */ /* t1 >= sqrt(arg) >= t2 at this point */
} while (mp_cmp_mag(&t1,&t2) == MP_GT); } while (mp_cmp_mag(&t1, &t2) == MP_GT);
mp_exch(&t1,ret); mp_exch(&t1, ret);
E1: mp_clear(&t2); E1: mp_clear(&t2);
E2: mp_clear(&t1); E2: mp_clear(&t1);

View File

@ -169,9 +169,9 @@ typedef struct {
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
#define USED(m) ((m)->used) #define USED(m) ((m)->used)
#define DIGIT(m,k) ((m)->dp[(k)]) #define DIGIT(m, k) ((m)->dp[(k)])
#define SIGN(m) ((m)->sign) #define SIGN(m) ((m)->sign)
/* error code to char* string */ /* error code to char* string */
const char *mp_error_to_string(int code); const char *mp_error_to_string(int code);

View File

@ -19,11 +19,11 @@
#include <ctype.h> #include <ctype.h>
#ifndef MIN #ifndef MIN
#define MIN(x,y) (((x) < (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif #endif
#ifndef MAX #ifndef MAX
#define MAX(x,y) (((x) > (y)) ? (x) : (y)) #define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus