]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add our various random implementations to speedtest
authorOtto <otto.moerbeek@open-xchange.com>
Wed, 22 Sep 2021 13:10:05 +0000 (15:10 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 22 Sep 2021 13:10:05 +0000 (15:10 +0200)
pdns/Makefile.am
pdns/speedtest.cc

index d8a7cafbe076d5ca627a601033e4857806664fb1..9628a5bee20e0d4f95756b22c00b46071d1a0a0b 100644 (file)
@@ -916,9 +916,11 @@ tsig_tests_LDADD += $(P11KIT1_LIBS)
 endif
 
 speedtest_SOURCES = \
+        arguments.cc arguments.hh \
        base32.cc \
        base64.cc base64.hh \
        credentials.cc credentials.hh \
+        dns_random.cc dns_random.hh \
        dnslabeltext.cc \
        dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
index 50f40cb1199005707a4765603801dd73dc3fda53..b64dd76db3965ff56a02fa6d161fe79b7e6ccbc2 100644 (file)
@@ -12,6 +12,8 @@
 #include "uuid-utils.hh"
 #include "dnssecinfra.hh"
 #include "lock.hh"
+#include "dns_random.hh"
+#include "arguments.hh"
 
 #ifndef RECURSOR
 #include "statbag.hh"
@@ -1047,6 +1049,26 @@ private:
   const std::string d_password{"test password"};
 };
 
+struct RndSpeedTest
+{
+  explicit RndSpeedTest(std::string which) : name(which){
+    ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
+    ::arg().set("rng", "") = which;
+    dns_random_init("", true);
+  }
+  string getName() const
+  {
+    return "Random test " + name;
+  }
+
+  void operator()() const
+  {
+    dns_random(0x10000);
+  }
+
+  std::string name;
+};
+
 struct CredentialsVerifyTest
 {
   explicit CredentialsVerifyTest() {
@@ -1174,6 +1196,20 @@ try
 
   doRun(UUIDGenTest());
 
+#if defined(HAVE_RANDOMBYTES_STIR)
+  doRun(RndSpeedTest("sodium"));
+#endif
+#if defined(HAVE_RAND_BYTES)
+  doRun(RndSpeedTest("openssl"));
+#endif
+#if defined(HAVE_GETRANDOM)
+  doRun(RndSpeedTest("getrandom"));
+#endif
+#if defined(HAVE_ARC4RANDOM)
+  doRun(RndSpeedTest("arc4random"));
+#endif
+  doRun(RndSpeedTest("urandom"));
+
   doRun(NSEC3HashTest(1, "ABCD"));
   doRun(NSEC3HashTest(10, "ABCD"));
   doRun(NSEC3HashTest(50, "ABCD"));
@@ -1201,6 +1237,7 @@ try
   doRun(StatRingDNSNameQTypeTest(DNSName("example.com"), QType(1)));
 #endif
 
+
   cerr<<"Total runs: " << g_totalRuns<<endl;
 
 }
@@ -1208,3 +1245,9 @@ catch(std::exception &e)
 {
   cerr<<"Fatal: "<<e.what()<<endl;
 }
+
+ArgvMap& arg()
+{      
+  static ArgvMap theArg;
+  return theArg;
+}