Skip to content

Commit 89eb918

Browse files
committed
Additional tests with large SPSPs to multiple bases.
1 parent 9b841e7 commit 89eb918

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

demo/test.c

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ static int test_mp_prime_rand(void)
883883

884884
/* test for size */
885885
for (ix = 10; ix < 128; ix++) {
886-
printf("Testing (not safe-prime): %9d bits \n", ix);
886+
printf("\rTesting (not safe-prime): %9d bits ", ix);
887887
fflush(stdout);
888888
DO(mp_prime_rand(&a, 8, ix, (rand_int() & 1) ? 0 : MP_PRIME_2MSB_ON));
889889
EXPECT(mp_count_bits(&a) == ix);
@@ -912,15 +912,20 @@ static const uint32_t SPSP_3[] = {
912912
};
913913

914914
/* SPSP to all bases < 100 */
915-
/* still needs computing
916-
static const char *SPSP_2_100_LARGE[] = {
917-
"",
918-
"",
919-
"",
920-
"",
921-
""
915+
static const char *SPSP_2_100_LARGE[4] = {
916+
"3L2x7YRmz7g4q+DwxESBacAClxrNiuspLCf8BUEphtky+5VNHLAb2ZZLLI0bu6cAOtNkUXenakBCCL"
917+
"Vn7gqOpkcrQ/ptxZdk+4gnI99wFjgcfM512N71ZzbwvLe+5Pzat2k+nHIjE0w/WbQvzk4a2/syAY8S"
918+
"i1B5XRjXYVAQOLyNWhsFpXeWXUgqiNzv7avfwBA3ZOXt", /* bases 2 - 100 */
919+
"JOcSIwxGqGEjeQ2GsdlnFMwhc+xY7EtZo5Kf4BglOuakxTJaP8qrdZyduXaAZUdzyPgQLf7B8vqvVE"
920+
"VLJwH7dLkLEiw19tfu3naT6DgQWzk+b5WuwWJzsTMdgWWH86M1h/Gjt2J/qABtTTH26C8bS4v/q9Fh"
921+
"R8jqHNOiufUgHkDQdW9Z+BLlf6OVVh2VwPIOGVc7kFF", /* bases 2 - 107 */
922+
"1ZCddPKHO7yeqI5ZeKG5ssTnzJeIDpWElJEZnHwejl4tsyly44JgwdiRmXgsi9FQfYhMzFZMgV6qWZZ"
923+
"sIJl4RNgpD/PDb3nam++ECkzMBuNIXVpmZzw+Gj5xQmpKK+OX8pFSy2IQiKyKAOfSaivXEb2/dga2J/"
924+
"Pc2d23lw+eP3WtBbfHc7TAQGgNI/6Xmcpl1G64eXCrJ", /* bases 2 - 103 */
925+
"cCax282DurA+2Z54W3VLKSC2mwgpilQpGydCDHvXHNRKbJQRa5NtLLfa3sXvCmUWZ9okP2ZSsPDnw0X"
926+
"dUQLzaz59vnw0rKbfsoA4nDBjMXR78Q889+KS4HFKfXkzxsiIKYo0kSfwPKYxFUi4Zj185kwwAPTAr2"
927+
"IjegdWjQLeX1ZQM0HVUUF3WEVhHXcFzF0sMiJU5hl" /* bases 2 - 101 */
922928
};
923-
*/
924929

925930
/* Extra strong Lucas test with Baillie's parameters Q = 1, P = 3 */
926931
static const uint32_t ESLPSP[] = {
@@ -940,7 +945,7 @@ static const uint32_t AESLPSP[] = {
940945
4269341, 5192309, 7045433, 7226669, 7265561
941946
};
942947

943-
/* Some randomly choosen 200 decimal digits large primes (https://primes.utm.edu/lists/small/small2.html) */
948+
/* Some randomly choosen 200 decimal digit large primes (https://primes.utm.edu/lists/small/small2.html) */
944949
static const char *medium_primes[10] = {
945950
"C8Ckh0vviS3HUPdB1NSrSm+gOodw/f1aQ5+aaH1W6RMB0jVkO6lTaL54O3o7U5BSGUFGxm5gAvisbJamasuLZS8g3ZsJ2JM4Vtn9cQZRfkP6b8V",
946951
"64xDN9FqLBiovZ/9q/EPm0DONpIfn5MbJKHa+IjT0fjAzkg34FpAmad+CwhcpKaiTbZEpErut+DhpVyiQfqBFrgcGnGhhIrMF/XkyY3aVx6E96B",
@@ -961,6 +966,7 @@ static int test_mp_prime_miller_rabin(void)
961966
mp_int a, b, c;
962967
bool result;
963968
int i;
969+
mp_digit j;
964970
DOR(mp_init_multi(&a, &b, &c, NULL));
965971

966972
/* SPSP to base 2 */
@@ -998,6 +1004,35 @@ static int test_mp_prime_miller_rabin(void)
9981004
EXPECT(result == true);
9991005
}
10001006

1007+
/* SPSP to bases 2 -- 100 */
1008+
mp_set(&b, 2u);
1009+
for (i = 0; i < 4; i++) {
1010+
DO(mp_read_radix(&a, SPSP_2_100_LARGE[i], 64));
1011+
for (j = 2u; j <= 100u; j++) {
1012+
result = false;
1013+
mp_set(&b, j);
1014+
DO(mp_prime_miller_rabin(&a, &b, &result));
1015+
EXPECT(result == true);
1016+
}
1017+
/* 107 is a prime that works */
1018+
mp_set(&b, 107u);
1019+
DO(mp_prime_miller_rabin(&a, &b, &result));
1020+
EXPECT(result == false);
1021+
}
1022+
1023+
/* SPSP to bases 2 -- 100, automatic */
1024+
mp_set(&b, 2u);
1025+
for (i = 0; i < 4; i++) {
1026+
DO(mp_read_radix(&a, SPSP_2_100_LARGE[i], 64));
1027+
for (j = 2u; j <= (mp_digit)mp_prime_rabin_miller_trials(mp_count_bits(&a)); j++) {
1028+
result = false;
1029+
mp_set(&b, (mp_digit)s_mp_prime_tab[j]);
1030+
DO(mp_prime_miller_rabin(&a, &b, &result));
1031+
}
1032+
/* These numbers are not big enough for the heuristics to work */
1033+
EXPECT(result == true);
1034+
}
1035+
10011036
mp_clear_multi(&a, &b, &c, NULL);
10021037
return EXIT_SUCCESS;
10031038
LBL_ERR:
@@ -1064,6 +1099,17 @@ static int test_mp_prime_is_prime(void)
10641099
mp_int a, b;
10651100
DOR(mp_init_multi(&a, &b, NULL));
10661101

1102+
/* strong Miller-Rabin pseudoprimes to the first 100 primes (gernerated with Arnault's method) */
1103+
printf("Testing mp_prime_is_prime() with SPSPs to the first 100 primes\n");
1104+
for (ix = 0; ix < 4; ix++) {
1105+
DO(mp_read_radix(&a,SPSP_2_100_LARGE[ix],64));
1106+
DO(mp_prime_is_prime(&a, mp_prime_rabin_miller_trials(mp_count_bits(&a)), &cnt));
1107+
if (cnt) {
1108+
printf("SPSP_2_100_LARGE[%d] is not prime but mp_prime_is_prime says it is.\n", ix);
1109+
goto LBL_ERR;
1110+
}
1111+
}
1112+
10671113
/* strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault) */
10681114
printf("Testing mp_prime_is_prime() with Arnault's pseudoprime 803...901");
10691115
DO(mp_read_radix(&a,

0 commit comments

Comments
 (0)