[PATCH 01/10] bench-slope: add option to disable quick random generation

Jussi Kivilinna <[email protected]> Sun, 2 Aug 2026 12:55:06 +0300
Newsgroups gmane.comp.encryption.gpg.libgcrypt.devel
Message-ID <[email protected]>
* tests/bench-slope.c (print_help): Add '--no-quick-rng'.
(main): Add '--no-quick-rng' option and initialize RNG before
benchmarking.
--

Quick random skips entropy gathering, which hides cost of
GCRY_VERY_STRONG_RANDOM requests. Such request takes about 2 ms and
dominates ECC key generation, so measuring what applications actually
get needs a way to turn quick random off. Default stays as before, since
otherwise entropy gathering swamps the algorithms.

Random pool is initialized up front because fast random poll done on
handle creation is no-operation until pool exists, which would make
first measurements differ from rest.

Signed-off-by: Jussi Kivilinna <[email protected]>
---
 tests/bench-slope.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tests/bench-slope.c b/tests/bench-slope.c
index 4b14541b..831fe545 100644
--- a/tests/bench-slope.c
+++ b/tests/bench-slope.c
@@ -3265,6 +3265,7 @@ print_help (void)
     "   --repetitions <n>         Use N repetitions (default "
                                      STR2(NUM_MEASUREMENT_REPETITIONS) ")",
     "   --unaligned               Use unaligned input buffers.",
+    "   --no-quick-rng            Use default random number generation",
     "   --csv                     Use CSV output format",
     NULL
   };
@@ -3297,6 +3298,8 @@ int
 main (int argc, char **argv)
 {
   int last_argc = -1;
+  int no_quick_rng = 0;
+  char tmp[4];
 
   if (argc)
     {
@@ -3351,6 +3354,12 @@ main (int argc, char **argv)
 	  argc--;
 	  argv++;
 	}
+      else if (!strcmp (*argv, "--no-quick-rng"))
+	{
+	  no_quick_rng = 1;
+	  argc--;
+	  argv++;
+	}
       else if (!strcmp (*argv, "--unaligned"))
 	{
 	  unaligned_mode = 1;
@@ -3427,7 +3436,12 @@ main (int argc, char **argv)
 
   xgcry_control ((GCRYCTL_DISABLE_SECMEM, 0));
   xgcry_control ((GCRYCTL_INITIALIZATION_FINISHED, 0));
-  xgcry_control ((GCRYCTL_ENABLE_QUICK_RANDOM, 0));
+
+  if (!no_quick_rng)
+    xgcry_control ((GCRYCTL_ENABLE_QUICK_RANDOM, 0));
+
+  /* Fill random pool so that first measurement is not different. */
+  gcry_randomize (tmp, sizeof(tmp), GCRY_STRONG_RANDOM);
 
   if (gcry_fips_mode_active ())
     in_fips_mode = 1;
-- 
2.53.0