Commit 3b2da7a507 for openssl.org

commit 3b2da7a507f362f9d25b16e989bc7f33df2b9714
Author: Bob Beck <beck@openssl.org>
Date:   Sun Aug 16 14:44:59 2026 -0700

    Size test_mod_exp_x2 to the coverage it needs

    A defect either shows on a large fraction of random inputs or is not
    reachable by sampling in one run at all.  Twenty rounds per factor size
    covers the former.

    Drive the sizes from a table rather than a ladder of index ranges, which
    also makes the bands equal.

    On a MacBook Pro the exptest binary goes from 24.1 to 5.3 seconds.

    Reviewed-by: Andrew Dinh <andrewd@openssl.org>
    Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
    Merge-date: Tue Sep  1 14:17:18 2026
    Merged-from: https://github.com/openssl/openssl/pull/32404

diff --git a/test/exptest.c b/test/exptest.c
index ebb8284899..bf2ec8620c 100644
--- a/test/exptest.c
+++ b/test/exptest.c
@@ -236,6 +236,17 @@ err:
     return ret;
 }

+/*-
+ * The factor sizes are what matters; the rounds are repetition on fresh
+ * random inputs.  A defect showing on a fraction f of inputs is caught by
+ * N rounds with probability 1 - (1 - f) ^ N, so twenty catch anything
+ * affecting a seventh of inputs or more.  Rarer ones are not caught in a
+ * single run at any affordable count, and are left to the inputs being
+ * drawn afresh on every run.
+ */
+static const int factor_sizes[] = { 1024, 1536, 2048 };
+#define ROUNDS_PER_FACTOR_SIZE 20
+
 static int test_mod_exp_x2(int idx)
 {
     BN_CTX *ctx;
@@ -250,14 +261,7 @@ static int test_mod_exp_x2(int idx)
     BIGNUM *a2 = NULL;
     BIGNUM *b2 = NULL;
     BIGNUM *m2 = NULL;
-    int factor_size = 0;
-
-    if (idx <= 100)
-        factor_size = 1024;
-    else if (idx <= 200)
-        factor_size = 1536;
-    else if (idx <= 300)
-        factor_size = 2048;
+    int factor_size = factor_sizes[idx / ROUNDS_PER_FACTOR_SIZE];

     if (!TEST_ptr(ctx = BN_CTX_new()))
         goto err;
@@ -333,6 +337,7 @@ int setup_tests(void)
 {
     ADD_TEST(test_mod_exp_zero);
     ADD_ALL_TESTS(test_mod_exp, 200);
-    ADD_ALL_TESTS(test_mod_exp_x2, 300);
+    ADD_ALL_TESTS(test_mod_exp_x2,
+        OSSL_NELEM(factor_sizes) * ROUNDS_PER_FACTOR_SIZE);
     return 1;
 }