@@ -186,15 +186,15 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, bool *result)
186186
187187 This holds for a while. Next SPRPs < 2^35 to check for {2, 3, 1459}:
188188
189- n factors log_2(n) has a factor < 2^28
190- 6770862367: 41143 164569 32.65669244751501848078 y
191- 15579919981: 88261 176521 33.85896877256133553111 y
192- 16149644101: 63541 254161 33.91078332064236217721 y
193- 17849326081: 50497 353473 34.05515055377487005769 y
194- 23510118061: 108421 216841 34.45256273267917105145 y
195- 24988416967: 79039 316153 34.54054045749318459634 y
196- 27031263841: 116257 232513 34.65390991522339129949 y
197- 28448982721: 97381 292141 34.72765801442453753728 y
189+ n factors log_2(n) has a factor < 2^28
190+ 6770862367: 41143 164569 32.6567 y
191+ 15579919981: 88261 176521 33.859 y
192+ 16149644101: 63541 254161 33.9108 y
193+ 17849326081: 50497 353473 34.0556 y
194+ 23510118061: 108421 216841 34.4526 y
195+ 24988416967: 79039 316153 34.5405 y
196+ 27031263841: 116257 232513 34.6539 y
197+ 28448982721: 97381 292141 34.7276 y
198198
199199 */
200200#if ((defined S_MP_PRIME_IS_DIVISIBLE_C ) && (MP_PRIME_TAB_SIZE >= 256 ))
@@ -216,38 +216,66 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, bool *result)
216216 * result = res ;
217217 goto LBL_B ;
218218 }
219- }
220219#else
221220 /* 2, 7, 61 found by Gerhard Jaeschke 1993 */
221+ /*
222+ Because we already have 2 and 3 at this point all four bases are good up to
223+
224+ 33717240721: 129841 259681 34.9728 y
225+
226+ This is the single SPRP up to 51706044253 (~2^35.5896). Next are
227+
228+ 163204128181: 285661 571321 37.2479 y
229+ 501086407781: 288989 1733929 38.8663 y
230+ ... 23588 others skipped ...
231+ 18441334942415579101: 876577981 21037871521 63.9996 n
232+ 18444384017352327673: 1920644893 9603224461 63.9998 n
233+
234+ Adding base 5 brings us to
235+
236+ 10087771603687: 1588063 6352249 43.1977 y
237+
238+ The record for five bases is at 7999252175582851 for now, about 2^52.8288 bit large
239+ but hase bases larger than 32 bit and none of the known 5-base records has bases
240+ smaller than 28 bit.
241+
242+ Adding base 63803 (already > 2^15) brings us to
243+
244+ 849491953715047: 14573023 58292089 49.5936 y
245+
246+ Record for 6 bases is at 585226005592931977 ~2^59.0217 but one base is over 60 bit
247+ large.
248+
249+ */
222250 mp_digit bases32 = {7u , 61u };
223251#endif
224- /* 2, 325, 9375, 28178, 450775, 9780504, 1795265022 found by Jim Sinclair 2011 */
225- mp_word bases64 = {325ull , 9375ull , 28178ull , 450775ull , 9780504ull , 1795265022ull };
226- if (bits < 32 ) {
227- for (ix = 0 ; ix < 2 ; ix ++ ) {
228- mp_set (& b , bases32 [ix ]);
229- if ((err = mp_prime_miller_rabin (a , & b , & res )) != MP_OKAY ) {
230- goto LBL_B ;
231- }
232- if (!res ) {
233- goto LBL_B ;
234- }
235- }
236- * result = true;
237- goto LBL_B ;
238- } else if ((bits >= 32 ) && (bits < 64 )) {
239- for (ix = 0 ; ix < 6 ; ix ++ ) {
240- mp_set_u32 (& b , bases64 [ix ]);
241- if ((err = mp_prime_miller_rabin (a , & b , & res )) != MP_OKAY ) {
242- goto LBL_B ;
252+ /* 2, 325, 9375, 28178, 450775, 9780504, 1795265022 found by Jim Sinclair 2011 */
253+ mp_word bases64 = {325ull , 9375ull , 28178ull , 450775ull , 9780504ull , 1795265022ull };
254+ if (bits < 32 ) {
255+ for (ix = 0 ; ix < 2 ; ix ++ ) {
256+ mp_set (& b , bases32 [ix ]);
257+ if ((err = mp_prime_miller_rabin (a , & b , & res )) != MP_OKAY ) {
258+ goto LBL_B ;
259+ }
260+ if (!res ) {
261+ goto LBL_B ;
262+ }
243263 }
244- if (!res ) {
245- goto LBL_B ;
264+ * result = true;
265+ goto LBL_B ;
266+ } else if ((bits >= 32 ) && (bits < 64 )) {
267+ for (ix = 0 ; ix < 6 ; ix ++ ) {
268+ mp_set_u32 (& b , bases64 [ix ]);
269+ if ((err = mp_prime_miller_rabin (a , & b , & res )) != MP_OKAY ) {
270+ goto LBL_B ;
271+ }
272+ if (!res ) {
273+ goto LBL_B ;
274+ }
246275 }
276+ * result = true;
277+ goto LBL_B ;
247278 }
248- * result = true;
249- goto LBL_B ;
250- }
251279#endif
252280 /*
253281 Sorenson, Jonathan; Webster, Jonathan, "Strong Pseudoprimes to Twelve Prime Bases". (2015) https://arxiv.org/abs/1509.00864
@@ -301,8 +329,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, bool *result)
301329 Do "t" M-R tests with random bases between 3 and "a".
302330 See Fips 186.4 p. 126ff
303331 */
304- if (t > 0 )
305- {
332+ if (t > 0 ) {
306333 unsigned int mask ;
307334 /*
308335 * The mp_digit's have a defined bit-size but the size of the
0 commit comments