add missing space after comma
This commit is contained in:
parent
0135749e44
commit
378be117a3
@ -20,7 +20,7 @@
|
||||
*/
|
||||
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;
|
||||
|
||||
if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
|
||||
|
@ -26,13 +26,13 @@ unsigned long mp_get_int(mp_int * a)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
res = DIGIT(a,i);
|
||||
res = DIGIT(a, i);
|
||||
|
||||
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 */
|
||||
|
@ -26,14 +26,14 @@ unsigned long mp_get_long(mp_int * a)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
res = DIGIT(a,i);
|
||||
res = DIGIT(a, i);
|
||||
|
||||
#if (ULONG_MAX != 0xffffffffuL) || (DIGIT_BIT < 32)
|
||||
while (--i >= 0) {
|
||||
res = (res << DIGIT_BIT) | DIGIT(a,i);
|
||||
res = (res << DIGIT_BIT) | DIGIT(a, i);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
|
@ -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 */
|
||||
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 */
|
||||
res = DIGIT(a,i);
|
||||
res = DIGIT(a, i);
|
||||
|
||||
#if DIGIT_BIT < 64
|
||||
while (--i >= 0) {
|
||||
res = (res << DIGIT_BIT) | DIGIT(a,i);
|
||||
res = (res << DIGIT_BIT) | DIGIT(a, i);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
|
@ -38,7 +38,7 @@ static const char rem_105[105] = {
|
||||
};
|
||||
|
||||
/* 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;
|
||||
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) */
|
||||
if (rem_128[127 & DIGIT(arg,0)] == 1) {
|
||||
if (rem_128[127 & DIGIT(arg, 0)] == 1) {
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if ((res = mp_mod(arg,&t,&t)) != MP_OKAY) {
|
||||
if ((res = mp_mod(arg, &t, &t)) != MP_OKAY) {
|
||||
goto ERR;
|
||||
}
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if ((res = mp_sqr(&t,&t)) != MP_OKAY) {
|
||||
if ((res = mp_sqr(&t, &t)) != MP_OKAY) {
|
||||
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);
|
||||
return res;
|
||||
}
|
||||
|
20
bn_mp_sqrt.c
20
bn_mp_sqrt.c
@ -19,7 +19,7 @@
|
||||
int mp_sqrt(mp_int *arg, mp_int *ret)
|
||||
{
|
||||
int res;
|
||||
mp_int t1,t2;
|
||||
mp_int t1, t2;
|
||||
|
||||
/* must be positive */
|
||||
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) */
|
||||
mp_rshd (&t1,t1.used/2);
|
||||
mp_rshd (&t1, t1.used/2);
|
||||
|
||||
/* t1 > 0 */
|
||||
if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
|
||||
if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
|
||||
if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
|
||||
if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
/* And now t1 > sqrt(arg) */
|
||||
do {
|
||||
if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
|
||||
if ((res = mp_div(arg, &t1, &t2, NULL)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
|
||||
if ((res = mp_add(&t1, &t2, &t1)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
|
||||
if ((res = mp_div_2(&t1, &t1)) != MP_OKAY) {
|
||||
goto E1;
|
||||
}
|
||||
/* 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);
|
||||
E2: mp_clear(&t1);
|
||||
|
@ -169,9 +169,9 @@ typedef struct {
|
||||
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m, k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
|
||||
/* error code to char* string */
|
||||
const char *mp_error_to_string(int code);
|
||||
|
@ -19,11 +19,11 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user