Skip to content

Commit e34d96f

Browse files
committed
Overhaul of the prime-tests
- Removal of the Fermat test mp_prime_fermat - Replacement of the Strong Lucas-Selfridge test with the Extra Strong Lucas test with Robert Baillie's parameters P = 3 and Q = 1 - Additional tests to check the implementations of the Miller-Rabin and Extra Strong Lucas tests
1 parent 0df542c commit e34d96f

15 files changed

+582
-118
lines changed

demo/test.c

+247-2
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);
@@ -896,6 +896,238 @@ static int test_mp_prime_rand(void)
896896
return EXIT_FAILURE;
897897
}
898898

899+
/* Some small pseudoprimes to test the individual implementations */
900+
901+
/* Miller-Rabin base 2 */
902+
static const uint32_t SPSP_2[] = {
903+
2047, 3277, 4033, 4681, 8321, 15841, 29341, 42799,
904+
49141, 52633, 65281, 74665, 80581, 85489, 88357, 90751
905+
};
906+
907+
/* Miller-Rabin base 3 */
908+
static const uint32_t SPSP_3[] = {
909+
121, 703, 1891, 3281, 8401, 8911, 10585, 12403, 16531,
910+
18721, 19345, 23521, 31621, 44287, 47197, 55969, 63139,
911+
74593, 79003, 82513, 87913, 88573, 97567
912+
};
913+
914+
/* SPSP to all bases < 100 */
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 */
928+
};
929+
930+
/* Extra strong Lucas test with Baillie's parameters Q = 1, P = 3 */
931+
static const uint32_t ESLPSP[] = {
932+
989, 3239, 5777, 10877, 27971, 29681, 30739, 31631, 39059, 72389,
933+
73919, 75077, 100127, 113573, 125249, 137549, 137801, 153931, 155819,
934+
161027, 162133, 189419, 218321, 231703, 249331, 370229, 429479, 430127,
935+
459191, 473891, 480689, 600059, 621781, 632249, 635627
936+
};
937+
938+
/*
939+
Almost extra strong Lucas test with Baillie's parameters Q = 1, P = 3
940+
Only those that are not in ESLPSP.
941+
*/
942+
static const uint32_t AESLPSP[] = {
943+
10469, 154697, 233659, 472453, 629693, 852389, 1091093, 1560437,
944+
1620673, 1813601, 1969109, 2415739, 2595329, 2756837, 3721549,
945+
4269341, 5192309, 7045433, 7226669, 7265561
946+
};
947+
948+
/* Some randomly choosen 200 decimal digit large primes (https://primes.utm.edu/lists/small/small2.html) */
949+
static const char *medium_primes[10] = {
950+
"C8Ckh0vviS3HUPdB1NSrSm+gOodw/f1aQ5+aaH1W6RMB0jVkO6lTaL54O3o7U5BSGUFGxm5gAvisbJamasuLZS8g3ZsJ2JM4Vtn9cQZRfkP6b8V",
951+
"64xDN9FqLBiovZ/9q/EPm0DONpIfn5MbJKHa+IjT0fjAzkg34FpAmad+CwhcpKaiTbZEpErut+DhpVyiQfqBFrgcGnGhhIrMF/XkyY3aVx6E96B",
952+
"8cyuMlENm0vh/eWwgHUpDKqmLyCSsRQZRWvbHpA2jHDZv1EhHkVhceg3OFRZn/aXRBnbdtsc2xO6sWh9KZ5Mo7u9rJgBJMVtDnu094MCExj1YvB",
953+
"BRFZFsYjSz45un8qptnuSqEsy9wV0BzbMpVAB1TrwImENOVIc1cASZNQ/mXG2xtazqgn/juVzFo91XLx9PtIlkcK0L2T6fBNgy8Lc7dSVoKQ+XP",
954+
"Ez/mDl+to2gm69+VdIHI9Q7vaO3DuIdLVT69myM3HYwVBE+G24KffAOUAp3FGrSOU+LtERMiIYIEtxPI7n/DRJtmL2i0+REwGpTMge2d2EpabfB",
955+
"5+Uz1gPFjZJ/nNdEOmOaMouJSGzygo42qz7xOwXn/moSUvBpPjo4twRGbK0+qaeU/RI8yYYxXr3OBP4w+/jgL3mN9GiENDM5LtEKMiQrZ9jIVEb",
956+
"AQ5nD1+G1grv41s/XlK+0YTGyZgr/88PzdQJ8QT9tavisTgyG6k8/80A4HQhnFndskHNAaB2EW5fE7KH3kk7m89s8JnVqkJyGZWSfs1+JlmHLPf",
957+
"3F19vPmM0Ih89KZ04Xmd62QB9F6E2sztT10A7Kcqc44eKvsNHh+JY6Z6gJXkbWg1Iw7xr29QAhEF/o1YAgfutQtpdzHkex06Yd71kPsaZdKXiC5",
958+
"2fIcJ1t/VYCColXGs+ji/txNMEXn2FXdowLzlo7QKqzAWHdAbwtltSO5qpSp3OUiEOGUUi3hbyw3iQRE8nFJaikJ89Wdox6vpPtIsc3QRjexMnv",
959+
"8aOicQ5gIbFCarFUgSgzh40LpuZ0jjK1u48/YT+C0h1dAQ8CIEgZjHZT+5/7cCRGmJlo+XCp7S41MSQ2ZNRSJh2texRYtvAXBAZfR8A8twl316P"
960+
};
961+
962+
const mp_digit prime_tab[] = {
963+
0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
964+
0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
965+
0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
966+
0x0061, 0x0065, 0x0067, 0x006B, 0x006D, 0x0071, 0x007F, 0x0083,
967+
0x0089, 0x008B, 0x0095, 0x0097, 0x009D, 0x00A3, 0x00A7, 0x00AD,
968+
0x00B3, 0x00B5, 0x00BF, 0x00C1, 0x00C5, 0x00C7, 0x00D3, 0x00DF,
969+
0x00E3, 0x00E5, 0x00E9, 0x00EF, 0x00F1, 0x00FB, 0x0101, 0x0107,
970+
0x010D, 0x010F, 0x0115, 0x0119, 0x011B, 0x0125, 0x0133, 0x0137,
971+
972+
0x0139, 0x013D, 0x014B, 0x0151, 0x015B, 0x015D, 0x0161, 0x0167,
973+
0x016F, 0x0175, 0x017B, 0x017F, 0x0185, 0x018D, 0x0191, 0x0199,
974+
0x01A3, 0x01A5, 0x01AF, 0x01B1, 0x01B7, 0x01BB, 0x01C1, 0x01C9,
975+
0x01CD, 0x01CF, 0x01D3, 0x01DF, 0x01E7, 0x01EB, 0x01F3, 0x01F7,
976+
0x01FD, 0x0209, 0x020B, 0x021D, 0x0223, 0x022D, 0x0233, 0x0239,
977+
0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
978+
0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
979+
0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF,
980+
981+
0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301,
982+
0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B,
983+
0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371,
984+
0x0373, 0x0377, 0x038B, 0x038F, 0x0397, 0x03A1, 0x03A9, 0x03AD,
985+
0x03B3, 0x03B9, 0x03C7, 0x03CB, 0x03D1, 0x03D7, 0x03DF, 0x03E5,
986+
0x03F1, 0x03F5, 0x03FB, 0x03FD, 0x0407, 0x0409, 0x040F, 0x0419,
987+
0x041B, 0x0425, 0x0427, 0x042D, 0x043F, 0x0443, 0x0445, 0x0449,
988+
0x044F, 0x0455, 0x045D, 0x0463, 0x0469, 0x047F, 0x0481, 0x048B,
989+
990+
0x0493, 0x049D, 0x04A3, 0x04A9, 0x04B1, 0x04BD, 0x04C1, 0x04C7,
991+
0x04CD, 0x04CF, 0x04D5, 0x04E1, 0x04EB, 0x04FD, 0x04FF, 0x0503,
992+
0x0509, 0x050B, 0x0511, 0x0515, 0x0517, 0x051B, 0x0527, 0x0529,
993+
0x052F, 0x0551, 0x0557, 0x055D, 0x0565, 0x0577, 0x0581, 0x058F,
994+
0x0593, 0x0595, 0x0599, 0x059F, 0x05A7, 0x05AB, 0x05AD, 0x05B3,
995+
0x05BF, 0x05C9, 0x05CB, 0x05CF, 0x05D1, 0x05D5, 0x05DB, 0x05E7,
996+
0x05F3, 0x05FB, 0x0607, 0x060D, 0x0611, 0x0617, 0x061F, 0x0623,
997+
0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
998+
};
999+
1000+
#define ARR_LENGTH(a) ((int)(sizeof((a))/sizeof((a)[0])))
1001+
1002+
static int test_mp_prime_miller_rabin(void)
1003+
{
1004+
mp_int a, b, c;
1005+
bool result;
1006+
int i;
1007+
mp_digit j;
1008+
DOR(mp_init_multi(&a, &b, &c, NULL));
1009+
1010+
/* SPSP to base 2 */
1011+
mp_set(&b, 2u);
1012+
for (i = 0; i < ARR_LENGTH(SPSP_2); i++) {
1013+
result = false;
1014+
mp_set_u32(&a, SPSP_2[i]);
1015+
DO(mp_prime_miller_rabin(&a, &b, &result));
1016+
EXPECT(result == true);
1017+
}
1018+
1019+
/* Some larger primes to check for false negatives */
1020+
for (i = 0; i < 10; i++) {
1021+
result = false;
1022+
DO(mp_read_radix(&a, medium_primes[i], 64));
1023+
DO(mp_prime_miller_rabin(&a, &b, &result));
1024+
EXPECT(result == true);
1025+
}
1026+
/* Some semi-primes */
1027+
for (i = 0; i < 5; i += 2) {
1028+
result = false;
1029+
DO(mp_read_radix(&a, medium_primes[i], 64));
1030+
DO(mp_read_radix(&c, medium_primes[i+1], 64));
1031+
DO(mp_mul(&a, &c, &a));
1032+
DO(mp_prime_miller_rabin(&a, &b, &result));
1033+
EXPECT(result == false);
1034+
}
1035+
1036+
/* SPSP to base 3 */
1037+
mp_set(&b, 3u);
1038+
for (i = 0; i < ARR_LENGTH(SPSP_3); i++) {
1039+
result = false;
1040+
mp_set_u32(&a, SPSP_3[i]);
1041+
DO(mp_prime_miller_rabin(&a, &b, &result));
1042+
EXPECT(result == true);
1043+
}
1044+
1045+
/* SPSP to bases 2 -- 100 */
1046+
mp_set(&b, 2u);
1047+
for (i = 0; i < 4; i++) {
1048+
DO(mp_read_radix(&a, SPSP_2_100_LARGE[i], 64));
1049+
for (j = 2u; j <= 100u; j++) {
1050+
result = false;
1051+
mp_set(&b, j);
1052+
DO(mp_prime_miller_rabin(&a, &b, &result));
1053+
EXPECT(result == true);
1054+
}
1055+
/* 107 is a prime that works */
1056+
mp_set(&b, 107u);
1057+
DO(mp_prime_miller_rabin(&a, &b, &result));
1058+
EXPECT(result == false);
1059+
}
1060+
1061+
/* SPSP to bases 2 -- 100, automatic */
1062+
mp_set(&b, 2u);
1063+
for (i = 0; i < 4; i++) {
1064+
DO(mp_read_radix(&a, SPSP_2_100_LARGE[i], 64));
1065+
for (j = 2u; j <= (mp_digit)mp_prime_rabin_miller_trials(mp_count_bits(&a)); j++) {
1066+
result = false;
1067+
mp_set(&b, (mp_digit)prime_tab[j]);
1068+
DO(mp_prime_miller_rabin(&a, &b, &result));
1069+
}
1070+
/* These numbers are not big enough for the heuristics to work */
1071+
EXPECT(result == true);
1072+
}
1073+
1074+
mp_clear_multi(&a, &b, &c, NULL);
1075+
return EXIT_SUCCESS;
1076+
LBL_ERR:
1077+
mp_clear_multi(&a, &b, &c, NULL);
1078+
return EXIT_FAILURE;
1079+
}
1080+
1081+
1082+
static int test_mp_prime_extra_strong_lucas(void)
1083+
{
1084+
mp_int a, b;
1085+
bool result;
1086+
int i;
1087+
1088+
DOR(mp_init_multi(&a, &b, NULL));
1089+
1090+
/* Check Extra Strong pseudoprimes */
1091+
for (i = 0; i < ARR_LENGTH(ESLPSP); i++) {
1092+
result = false;
1093+
mp_set_u32(&a, ESLPSP[i]);
1094+
DO(mp_prime_extra_strong_lucas(&a, &result));
1095+
EXPECT(result == true);
1096+
}
1097+
1098+
/* Check Almost Extra Strong pseudoprimes (not in ESLPSP) */
1099+
for (i = 0; i < ARR_LENGTH(AESLPSP); i++) {
1100+
result = false;
1101+
mp_set_u32(&a, AESLPSP[i]);
1102+
DO(mp_prime_extra_strong_lucas(&a, &result));
1103+
EXPECT(result == false);
1104+
}
1105+
1106+
/* Some larger primes to check for false negatives */
1107+
for (i = 0; i < 10; i++) {
1108+
result = false;
1109+
DO(mp_read_radix(&a, medium_primes[i], 64));
1110+
DO(mp_prime_extra_strong_lucas(&a, &result));
1111+
EXPECT(result == true);
1112+
}
1113+
1114+
/* Some semi-primes */
1115+
for (i = 0; i < 5; i++) {
1116+
result = false;
1117+
DO(mp_read_radix(&a, medium_primes[i], 64));
1118+
DO(mp_read_radix(&a, medium_primes[i+1], 64));
1119+
DO(mp_mul(&a, &b, &a));
1120+
DO(mp_prime_extra_strong_lucas(&a, &result));
1121+
EXPECT(result == false);
1122+
}
1123+
1124+
mp_clear_multi(&a, &b, NULL);
1125+
return EXIT_SUCCESS;
1126+
LBL_ERR:
1127+
mp_clear_multi(&a, &b, NULL);
1128+
return EXIT_FAILURE;
1129+
}
1130+
8991131
static int test_mp_prime_is_prime(void)
9001132
{
9011133
int ix;
@@ -905,6 +1137,17 @@ static int test_mp_prime_is_prime(void)
9051137
mp_int a, b;
9061138
DOR(mp_init_multi(&a, &b, NULL));
9071139

1140+
/* strong Miller-Rabin pseudoprimes to the first 100 primes (gernerated with Arnault's method) */
1141+
printf("Testing mp_prime_is_prime() with SPSPs to the first 100 primes\n");
1142+
for (ix = 0; ix < 4; ix++) {
1143+
DO(mp_read_radix(&a,SPSP_2_100_LARGE[ix],64));
1144+
DO(mp_prime_is_prime(&a, mp_prime_rabin_miller_trials(mp_count_bits(&a)), &cnt));
1145+
if (cnt) {
1146+
printf("SPSP_2_100_LARGE[%d] is not prime but mp_prime_is_prime says it is.\n", ix);
1147+
goto LBL_ERR;
1148+
}
1149+
}
1150+
9081151
/* strong Miller-Rabin pseudoprime to the first 200 primes (F. Arnault) */
9091152
printf("Testing mp_prime_is_prime() with Arnault's pseudoprime 803...901");
9101153
DO(mp_read_radix(&a,
@@ -965,7 +1208,7 @@ static int test_mp_prime_is_prime(void)
9651208
DO(mp_read_radix(&a,
9661209
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF",
9671210
16));
968-
DO(mp_prime_strong_lucas_selfridge(&a, &cnt));
1211+
DO(mp_prime_extra_strong_lucas(&a, &cnt));
9691212
/* large problem */
9701213
EXPECT(cnt);
9711214
if ((e != MP_OKAY) || !cnt) {
@@ -2465,6 +2708,8 @@ static int unit_tests(int argc, char **argv)
24652708
T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
24662709
T1(mp_root_n, MP_ROOT_N),
24672710
T1(mp_or, MP_OR),
2711+
T1(mp_prime_extra_strong_lucas, MP_PRIME_EXTRA_STRONG_LUCAS),
2712+
T1(mp_prime_miller_rabin, MP_PRIME_MILLER_RABIN),
24682713
T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
24692714
T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
24702715
T1(mp_prime_rand, MP_PRIME_RAND),

doc/bn.tex

+9-23
Original file line numberDiff line numberDiff line change
@@ -2018,15 +2018,6 @@ \subsection{Example}
20182018

20192019
\chapter{Prime Numbers}
20202020

2021-
\section{Fermat Test}
2022-
\index{mp\_prime\_fermat}
2023-
\begin{alltt}
2024-
mp_err mp_prime_fermat (const mp_int *a, const mp_int *b, int *result)
2025-
\end{alltt}
2026-
Performs a Fermat primality test to the base $b$. That is it computes $b^a \mbox{ mod }a$ and
2027-
tests whether the value is equal to $b$ or not. If the values are equal then $a$ is probably prime
2028-
and $result$ is set to one. Otherwise $result$ is set to zero.
2029-
20302021
\section{Miller--Rabin Test}
20312022
\index{mp\_prime\_miller\_rabin}
20322023
\begin{alltt}
@@ -2036,9 +2027,6 @@ \section{Miller--Rabin Test}
20362027
test and is very hard to fool (besides with Carmichael numbers). If $a$ passes the test (therefore
20372028
is probably prime) $result$ is set to one. Otherwise $result$ is set to zero.
20382029

2039-
Note that it is suggested that you use the Miller--Rabin test instead of the Fermat test since all
2040-
of the failures of Miller--Rabin are a subset of the failures of the Fermat test.
2041-
20422030
\subsection{Required Number of Tests}
20432031
Generally to ensure a number is very likely to be prime you have to perform the Miller--Rabin with
20442032
at least a half--dozen or so unique bases. However, it has been proven that the probability of
@@ -2220,9 +2208,8 @@ \subsection{Required Number of Tests}
22202208
the diagonal from $(512,2^{-80})$ downwards and to the right to gain a lower probability of getting
22212209
a composite declared a pseudoprime for the same amount of work or less.
22222210

2223-
If this version of the library has the strong Lucas--Selfridge and/or the Frobenius--Underwood test
2224-
implemented only one or two rounds of the Miller--Rabin test with a random base is necessary for
2225-
numbers larger than or equal to $1024$ bits.
2211+
If this version of the library has the extra strong Lucas test implemented only one or two rounds
2212+
of the Miller--Rabin test with a random base is necessary for numbers larger than or equal to $1024$ bits.
22262213

22272214
This function is meant for RSA. The number of rounds for DSA is $\lceil -log_2(p)/2\rceil$ with $p$
22282215
the probability which is just the half of the absolute value of $p$ if given as a power of two.
@@ -2233,12 +2220,12 @@ \subsection{Required Number of Tests}
22332220

22342221
See also table C.1 in FIPS 186-4.
22352222

2236-
\section{Strong Lucas--Selfridge Test}
2237-
\index{mp\_prime\_strong\_lucas\_selfridge}
2223+
\section{Extra Strong Lucas Test}
2224+
\index{mp\_prime\_extra\_strong\_lucas}
22382225
\begin{alltt}
2239-
mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, bool *result)
2226+
mp_err mp_prime_extra_strong_lucas(const mp_int *a, bool *result)
22402227
\end{alltt}
2241-
Performs a strong Lucas--Selfridge test. The strong Lucas--Selfridge test together with the
2228+
Performs a extra strong Lucas test. The extra strong Lucas test together with the
22422229
Rabin--Miller test with bases $2$ and $3$ resemble the BPSW test. The single internal use is a
22432230
compile--time option in \texttt{mp\_prime\_is\_prime} and can be excluded from the Libtommath build
22442231
if not needed.
@@ -2250,8 +2237,7 @@ \section{Frobenius (Underwood) Test}
22502237
\end{alltt}
22512238
Performs the variant of the Frobenius test as described by Paul Underwood. It can be included at
22522239
build--time if the preprocessor macro \texttt{LTM\_USE\_FROBENIUS\_TEST} is defined and will be
2253-
used
2254-
instead of the Lucas--Selfridge test.
2240+
used after the extra strong Lucas test.
22552241

22562242
It returns \texttt{MP\_ITER} if the number of iterations is exhausted, assumes a composite as the
22572243
input and sets \texttt{result} accordingly. This will reduce the set of available pseudoprimes by a
@@ -2272,11 +2258,11 @@ \section{Primality Testing}
22722258
mp_err mp_prime_is_prime(const mp_int *a, int t, bool *result)
22732259
\end{alltt}
22742260
This will perform a trial division followed by two rounds of Miller--Rabin with bases 2 and 3 and a
2275-
Lucas--Selfridge test. The Frobenius--Underwood is available as a compile--time option with the
2261+
extra strong Lucas test. The Frobenius--Underwood time is available as a compile--time option with the
22762262
preprocessor macro \texttt{LTM\_USE\_FROBENIUS\_TEST}. See file \texttt{bn\_mp\_prime\_is\_prime.c}
22772263
for the necessary details. It shall be noted that both functions are much slower than the
22782264
Miller--Rabin test and if speed is an essential issue, the macro \texttt{LTM\_USE\_ONLY\_MR}
2279-
switches the Frobenius--Underwood test and the Lucas--Selfridge test off and their code will not
2265+
switches the Frobenius--Underwood test and the Lucas test off and their code will not
22802266
even be compiled into the library.
22812267

22822268
If $t$ is set to a positive value $t$ additional rounds of the Miller--Rabin test with random bases

libtommath_VS2008.vcproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@
613613
>
614614
</File>
615615
<File
616-
RelativePath="mp_prime_fermat.c"
616+
RelativePath="mp_prime_extra_strong_lucas.c"
617617
>
618618
</File>
619619
<File

makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_hash.o mp_init.o mp_init_copy.o mp
3535
mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o \
3636
mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \
3737
mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \
38-
mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \
38+
mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_extra_strong_lucas.o \
3939
mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \
4040
mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \
4141
mp_radix_size_overestimate.o mp_rand.o mp_rand_source.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o \

makefile.mingw

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mp_get_mag_u64.o mp_get_mag_ul.o mp_grow.o mp_hash.o mp_init.o mp_init_copy.o mp
3737
mp_init_l.o mp_init_multi.o mp_init_set.o mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o \
3838
mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o mp_log.o mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o \
3939
mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \
40-
mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \
40+
mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_extra_strong_lucas.o \
4141
mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \
4242
mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_radix_size.o \
4343
mp_radix_size_overestimate.o mp_rand.o mp_rand_source.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o \

makefile.msvc

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mp_get_mag_u64.obj mp_get_mag_ul.obj mp_grow.obj mp_hash.obj mp_init.obj mp_init
3333
mp_init_l.obj mp_init_multi.obj mp_init_set.obj mp_init_size.obj mp_init_u32.obj mp_init_u64.obj mp_init_ul.obj \
3434
mp_invmod.obj mp_is_square.obj mp_kronecker.obj mp_lcm.obj mp_log.obj mp_log_n.obj mp_lshd.obj mp_mod.obj mp_mod_2d.obj \
3535
mp_montgomery_calc_normalization.obj mp_montgomery_reduce.obj mp_montgomery_setup.obj mp_mul.obj mp_mul_2.obj \
36-
mp_mul_2d.obj mp_mul_d.obj mp_mulmod.obj mp_neg.obj mp_or.obj mp_pack.obj mp_pack_count.obj mp_prime_fermat.obj \
36+
mp_mul_2d.obj mp_mul_d.obj mp_mulmod.obj mp_neg.obj mp_or.obj mp_pack.obj mp_pack_count.obj mp_prime_extra_strong_lucas.obj \
3737
mp_prime_frobenius_underwood.obj mp_prime_is_prime.obj mp_prime_miller_rabin.obj mp_prime_next_prime.obj \
3838
mp_prime_rabin_miller_trials.obj mp_prime_rand.obj mp_prime_strong_lucas_selfridge.obj mp_radix_size.obj \
3939
mp_radix_size_overestimate.obj mp_rand.obj mp_rand_source.obj mp_read_radix.obj mp_reduce.obj mp_reduce_2k.obj \

0 commit comments

Comments
 (0)