bugfix in bn_mp_kronecker.c, cleanup and formatting in div. files

This commit is contained in:
czurnieden 2018-12-12 00:14:05 +01:00 committed by Steffen Jaeckel
parent e6f353b48d
commit 3ec93dab9e
7 changed files with 46 additions and 13 deletions

View File

@ -49,3 +49,7 @@ int mp_get_bit(const mp_int *a, int b)
}
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */

View File

@ -131,11 +131,15 @@ int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
LBL_KRON:
mp_clear(&r);
LBL_KRON_1:
mp_clear(&a1);
LBL_KRON_0:
mp_clear(&p1);
LBL_KRON_0:
mp_clear(&a1);
return e;
}
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */

View File

@ -190,3 +190,7 @@ LBL_FU_ERR:
#endif
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */

View File

@ -14,7 +14,7 @@
*/
/* portable integer log of two with small footprint */
static unsigned int floor_ilog2(int value)
static unsigned int s_floor_ilog2(int value)
{
unsigned int r = 0;
while ((value >>= 1) != 0) {
@ -214,7 +214,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
}
}
// for compatibility with the current API (well, compatible within a sign's width)
/* for compatibility with the current API (well, compatible within a sign's width) */
if (p_max < t) {
p_max = t;
}
@ -252,8 +252,8 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
/*
Assuming the General Rieman hypothesis (never thought to write that in a
comment) the upper bound can be lowered to 2*(log a)^2.
E. Bach, Explicit bounds for primality testing and related problems,
Math. Comp. 55 (1990), 355380.
E. Bach, "Explicit bounds for primality testing and related problems,"
Math. Comp. 55 (1990), 355-380.
size_a = (size_a/10) * 7;
len = 2 * (size_a * size_a);
@ -262,7 +262,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
floor(2048/10)*7 = 1428
2 * 1428^2 = 4078368
(would have been ~4030331.9962 with floats and natural log instead)
That number is smaller than 2^28, the default bit-size of mp_digit.
*/
@ -288,7 +288,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
if ((err = mp_rand(&b, 1)) != MP_OKAY) {
goto LBL_B;
}
/*
/*
* Reduce digit before casting because mp_digit might be bigger than
* an unsigned int and "mask" on the other side is most probably not.
*/

View File

@ -29,7 +29,7 @@
* multiply bigint a with int d and put the result in c
* Like mp_mul_d() but with a signed long as the small input
*/
static int mp_mul_si(const mp_int *a, long d, mp_int *c)
static int s_mp_mul_si(const mp_int *a, long d, mp_int *c)
{
mp_int t;
int err, neg = 0;
@ -407,3 +407,7 @@ LBL_LS_ERR:
#endif
#endif
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */

View File

@ -124,7 +124,7 @@ struct mp_kronecker_st {
int c[21];
};
static struct mp_kronecker_st kronecker[] = {
//-10, -9, -8, -7,-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
/*-10, -9, -8, -7,-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10*/
{ -10, { 0, -1, 0, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, -1, 0, 0, 0, 1, 0, 1, 0 } },
{ -9, { -1, 0, -1, 1, 0, -1, -1, 0, -1, -1, 0, 1, 1, 0, 1, 1, 0, -1, 1, 0, 1 } },
{ -8, { 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 1, 0 } },
@ -674,7 +674,7 @@ int main(void)
printf("\n");
// strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault)
/* strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault) */
puts("Testing mp_prime_is_prime() with Arnault's pseudoprime 803...901 \n");
mp_read_radix(&a,"91xLNF3roobhzgTzoFIG6P13ZqhOVYSN60Fa7Cj2jVR1g0k89zdahO9/kAiRprpfO1VAp1aBHucLFV/qLKLFb+zonV7R2Vxp1K13ClwUXStpV0oxTNQVjwybmFb5NBEHImZ6V7P6+udRJuH8VbMEnS0H8/pSqQrg82OoQQ2fPpAk6G1hkjqoCv5s/Yr",64);
mp_prime_is_prime(&a, 8, &cnt);
@ -682,7 +682,7 @@ int main(void)
printf("Arnault's pseudoprime is not prime but mp_prime_is_prime says it is.\n");
return EXIT_FAILURE;
}
// About the same size as Arnault's pseudoprime
/* About the same size as Arnault's pseudoprime */
puts("Testing mp_prime_is_prime() with certified prime 2^1119 + 53\n");
mp_set(&a,1u);
mp_mul_2d(&a,1119,&a);

View File

@ -1,3 +1,16 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
* integer arithmetic as well as number theoretic functionality.
*
* The library was designed directly after the MPI library by
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
#if defined(LTM2)
# define LTM3
@ -1206,3 +1219,7 @@
#else
# define LTM_LAST
#endif
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */