Repository: randombit/botan
Pull request #3198 (2023-01-19 22:19:23)

Speed up sanitizer builds


Patch:
diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp
index 66efe7456..2d8cc1cd4 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.cpp
+++ b/src/lib/pubkey/dl_algo/dl_algo.cpp
@@ -69,7 +69,10 @@ DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
 bool DL_Scheme_PublicKey::check_key(RandomNumberGenerator& rng,
                                     bool strong) const
    {
-   return m_group.verify_group(rng, strong) && m_group.verify_public_element(m_y);
+   if(!m_group.verify_public_element(m_y))
+      return false;
+
+   return m_group.verify_group(rng, strong);
    }
 
 /*
diff --git a/src/lib/utils/safeint.h b/src/lib/utils/safeint.h
index abd1648f0..33e58c156 100644
--- a/src/lib/utils/safeint.h
+++ b/src/lib/utils/safeint.h
@@ -25,14 +25,9 @@ class Integer_Overflow_Detected final : public Exception
 
 inline size_t checked_add(size_t x, size_t y, const char* file, int line)
    {
-#if BOTAN_COMPILER_HAS_BUILTIN(__builtin_add_overflow)
-   size_t z;
-   if(__builtin_add_overflow(x, y, &z)) [[unlikely]]
-#else
-   // (Possible) TODO Windows supports SizeTAdd (intsafe.h) but unsure it is really a win.
+   // TODO: use __builtin_x_overflow on GCC and Clang
    size_t z = x + y;
    if(z < x) [[unlikely]]
-#endif
       {
       throw Integer_Overflow_Detected(file, line);
       }
diff --git a/src/scripts/ci/setup_gh_actions_after_vcvars.ps1 b/src/scripts/ci/setup_gh_actions_after_vcvars.ps1
index 503974dd5..06dd072ab 100644
--- a/src/scripts/ci/setup_gh_actions_after_vcvars.ps1
+++ b/src/scripts/ci/setup_gh_actions_after_vcvars.ps1
@@ -6,7 +6,7 @@
 #
 # Botan is released under the Simplified BSD License (see license.txt)
 
-if ($args[0] -in @('shared','sanitizer')) {
+if ($args[0] -in @('shared')) {
     nuget install -NonInteractive -OutputDirectory $env:DEPENDENCIES_LOCATION -Version 1.79.0 boost
 
     $boostincdir = Join-Path -Path $env:DEPENDENCIES_LOCATION -ChildPath "boost.1.79.0/lib/native/include"
diff --git a/src/scripts/ci_build.py b/src/scripts/ci_build.py
index 59941afd1..89a6fa27c 100755
--- a/src/scripts/ci_build.py
+++ b/src/scripts/ci_build.py
@@ -112,7 +112,9 @@ def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache,
 
     make_prefix = []
     test_prefix = []
-    test_cmd = [os.path.join(build_dir, 'botan-test'), '--data-dir=%s' % os.path.join(root_dir, 'src', 'tests', 'data'), '--run-memory-intensive-tests']
+    test_cmd = [os.path.join(build_dir, 'botan-test'),
+                '--data-dir=%s' % os.path.join(root_dir, 'src', 'tests', 'data'),
+                '--run-memory-intensive-tests']
 
     # generate JUnit test report
     if test_results_dir:
@@ -321,10 +323,16 @@ def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache,
         if target_os in ['osx', 'ios']:
             flags += ['--with-commoncrypto']
 
-        add_boost_support = target in ['coverage', 'sanitizer', 'shared'] \
-            and not (target_os == 'osx' and target_cc == 'gcc')
+        def add_boost_support(target, target_os):
+            if target in ['coverage', 'shared']:
+                return True
+
+            if target == 'sanitizer' and target_os == 'linux':
+                return True
+
+            return False
 
-        if add_boost_support:
+        if add_boost_support(target, target_os):
             flags += ['--with-boost']
             if target_cc == 'clang':
                 # make sure clang ignores warnings in boost headers
@@ -350,14 +358,16 @@ def determine_flags(target, target_os, target_cpu, target_cc, cc_bin, ccache,
                 test_cmd += ['--pkcs11-lib=%s' % (pkcs11_lib)]
 
     if target in ['coverage', 'sanitizer']:
+        test_cmd += ['--run-long-tests']
+
         if target_os == 'windows' and target == 'sanitizer':
             # GitHub Actions worker intermittently ran out of memory when
             # asked to allocate multi-gigabyte buffers under MSVC's ASan.
-            try:
-                test_cmd.remove('--run-memory-intensive-tests')
-            except ValueError:
-                pass
-        test_cmd += ['--run-long-tests']
+            test_cmd.remove('--run-memory-intensive-tests')
+
+            # MSVC sanitizer produces very slow code causing some of the
+            # slower tests to take as long as 5 minutes
+            test_cmd.remove('--run-long-tests')
 
     flags += ['--cc-bin=%s' % (cc_bin)]
 


Test patch:
diff --git a/src/tests/test_dl_group.cpp b/src/tests/test_dl_group.cpp
index 453645751..22f6c2e33 100644
--- a/src/tests/test_dl_group.cpp
+++ b/src/tests/test_dl_group.cpp
@@ -99,19 +99,20 @@ class DL_Generate_Group_Tests final : public Test
          result.test_eq("DH p size", dh1050.get_p().bits(), 1050);
          result.test_eq("DH q size", dh1050.get_q().bits(), 175);
          result.test_lte("DH g size", dh1050.get_g().bits(), 1050);
-         result.test_eq("DH group verifies", dh1050.verify_group(rng, true), true);
+         result.test_eq("DH group verifies", dh1050.verify_group(rng, false), true);
 
          Botan::DL_Group dh_implicit_q(rng, Botan::DL_Group::Prime_Subgroup, 1040);
          result.test_eq("DH p size", dh_implicit_q.get_p().bits(), 1040);
          result.test_eq("DH q size", dh_implicit_q.get_q().bits(), Botan::dl_exponent_size(1040));
-         result.test_eq("DH group verifies", dh_implicit_q.verify_group(rng, true), true);
+         result.test_lte("DH g size", dh_implicit_q.get_g().bits(), 1040);
+         result.test_eq("DH group verifies", dh_implicit_q.verify_group(rng, false), true);
 
          if(Test::run_long_tests())
             {
             Botan::DL_Group dh_strong(rng, Botan::DL_Group::Strong, 1025);
             result.test_eq("DH p size", dh_strong.get_p().bits(), 1025);
             result.test_eq("DH q size", dh_strong.get_q().bits(), 1024);
-            result.test_eq("DH group verifies", dh_strong.verify_group(rng, true), true);
+            result.test_eq("DH group verifies", dh_strong.verify_group(rng, false), true);
             }
 
 #if defined(BOTAN_HAS_SHA1)
@@ -119,7 +120,7 @@ class DL_Generate_Group_Tests final : public Test
          result.test_eq("DSA p size", dsa1024.get_p().bits(), 1024);
          result.test_eq("DSA q size", dsa1024.get_q().bits(), 160);
          result.test_lte("DSA g size", dsa1024.get_g().bits(), 1024);
-         result.test_eq("DSA group verifies", dsa1024.verify_group(rng, true), true);
+         result.test_eq("DSA group verifies", dsa1024.verify_group(rng, false), true);
 
          const std::vector<uint8_t> short_seed(16);
          const std::vector<uint8_t> invalid_seed(20);
@@ -148,7 +149,7 @@ class DL_Generate_Group_Tests final : public Test
          // Modulo just to avoid embedding entire 1024-bit P in src file
          result.test_eq("DSA p from seed", static_cast<size_t>(dsa_from_seed.get_p() % 4294967291), size_t(2513712339));
 
-         result.test_eq("DSA group from seed verifies", dsa_from_seed.verify_group(rng, true), true);
+         result.test_eq("DSA group from seed verifies", dsa_from_seed.verify_group(rng, false), true);
 #endif
 
          result.end_timer();
@@ -222,7 +223,7 @@ class DL_Named_Group_Tests final : public Test
 
             if(group.p_bits() <= 1536 || Test::run_long_tests())
                {
-               result.test_eq(name + " strong verifies", group.verify_group(Test::rng(), true), true);
+               result.test_eq(name + " verifies", group.verify_group(Test::rng()), true);
                }
 
             }