nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: randombit/botan
Pull request #2893 (2022-02-01 10:48:10)

Text_Policy ignores 25519 if unsupported by build
While introducing a new `key_exchange_groups_to_offer` field to TLS policies, we discovered an inconsistency when `Text_Policy` deals with groups that aren't supported by the Botan build.

Previously, curve25519 would end up in the policy's `supported_groups` list, even if the module was not enabled. Using a text policy that includes x25519, this could lead to TLS clients offering this group, even if it isn't compiled into the library.

We changed the Text_Policy's behavior to (quietly) ignore such groups.

This also removes the need for a hack in the `tls_policy_text` test.


Patch:
diff --git a/src/lib/tls/tls_text_policy.cpp b/src/lib/tls/tls_text_policy.cpp
index 675d74ca0..1a072433b 100644
--- a/src/lib/tls/tls_text_policy.cpp
+++ b/src/lib/tls/tls_text_policy.cpp
@@ -115,6 +115,11 @@ std::vector<Group_Params> Text_Policy::key_exchange_groups() const
       {
       Group_Params group_id = group_param_from_string(group_name);
 
+#if !defined(BOTAN_HAS_CURVE_25519)
+      if(group_id == Group_Params::X25519)
+         continue;
+#endif
+
       if(group_id == Group_Params::NONE)
          {
          try


Test patch:
diff --git a/src/tests/test_tls.cpp b/src/tests/test_tls.cpp
index c6be40325..daaacbe7f 100644
--- a/src/tests/test_tls.cpp
+++ b/src/tests/test_tls.cpp
@@ -326,12 +326,6 @@ class Test_TLS_Policy_Text : public Test
             const std::string from_policy_obj = tls_policy_string(policy);
             std::string from_file = read_tls_policy(policy);
 
-#if !defined(BOTAN_HAS_CURVE_25519)
-            auto pos = from_file.find("x25519 ");
-            if(pos != std::string::npos)
-               from_file = from_file.replace(pos, 7, "");
-#endif
-
             result.test_eq("Values for TLS " + policy + " policy", from_file, from_policy_obj);
             }
Repository: randombit/botan
Pull request #2894 (2022-02-01 14:13:04)

Text_Policy ignores 25519 if unsupported by build
Backporting #2893


Patch:
diff --git a/src/lib/tls/tls_text_policy.cpp b/src/lib/tls/tls_text_policy.cpp
index 1b83f0dbd..d05b332f0 100644
--- a/src/lib/tls/tls_text_policy.cpp
+++ b/src/lib/tls/tls_text_policy.cpp
@@ -130,6 +130,11 @@ std::vector<Group_Params> Text_Policy::key_exchange_groups() const
       {
       Group_Params group_id = group_param_from_string(group_name);
 
+#if !defined(BOTAN_HAS_CURVE_25519)
+      if(group_id == Group_Params::X25519)
+         continue;
+#endif
+
       if(group_id == Group_Params::NONE)
          {
          try


Test patch:
diff --git a/src/tests/test_tls.cpp b/src/tests/test_tls.cpp
index 7cc22a1d5..b03f26c99 100644
--- a/src/tests/test_tls.cpp
+++ b/src/tests/test_tls.cpp
@@ -301,12 +301,6 @@ class Test_TLS_Policy_Text : public Test
             const std::string from_policy_obj = tls_policy_string(policy);
             std::string from_file = read_tls_policy(policy);
 
-#if !defined(BOTAN_HAS_CURVE_25519)
-            auto pos = from_file.find("x25519 ");
-            if(pos != std::string::npos)
-               from_file = from_file.replace(pos, 7, "");
-#endif
-
             result.test_eq("Values for TLS " + policy + " policy", from_file, from_policy_obj);
             }
Repository: randombit/botan
Pull request #3426 (2023-03-25 14:21:39)

In DH bound the exponent size by the private key size
This leaks the length of the private key to side channels but this is not a problem, and doing so improves the performance by ~5-16 times.


Patch:
diff --git a/src/lib/pubkey/dh/dh.cpp b/src/lib/pubkey/dh/dh.cpp
index e38148d93..690603e69 100644
--- a/src/lib/pubkey/dh/dh.cpp
+++ b/src/lib/pubkey/dh/dh.cpp
@@ -115,6 +115,7 @@ class DH_KA_Operation final : public PK_Ops::Key_Agreement_with_KDF
                       RandomNumberGenerator& rng) :
          PK_Ops::Key_Agreement_with_KDF(kdf),
          m_key(key),
+         m_key_bits(m_key->private_key().bits()),
          m_blinder(m_key->group().get_p(),
                    rng,
                    [](const BigInt& k) { return k; },
@@ -136,11 +137,12 @@ class DH_KA_Operation final : public PK_Ops::Key_Agreement_with_KDF
 
       BigInt powermod_x_p(const BigInt& v) const
          {
-         return group().power_b_p(v, m_key->private_key());
+         return group().power_b_p(v, m_key->private_key(), m_key_bits);
          }
 
       std::shared_ptr<const DL_PrivateKey> m_key;
       std::shared_ptr<const Montgomery_Params> m_monty_p;
+      const size_t m_key_bits;
       Blinder m_blinder;
    };
 
diff --git a/src/lib/pubkey/dl_algo/dl_scheme.cpp b/src/lib/pubkey/dl_algo/dl_scheme.cpp
index a411497dc..1092938ab 100644
--- a/src/lib/pubkey/dl_algo/dl_scheme.cpp
+++ b/src/lib/pubkey/dl_algo/dl_scheme.cpp
@@ -90,7 +90,7 @@ DL_PrivateKey::DL_PrivateKey(const DL_Group& group,
                              const BigInt& private_key) :
    m_group(group),
    m_private_key(check_dl_private_key_input(private_key, m_group)),
-   m_public_key(m_group.power_g_p(m_private_key, m_group.p_bits()))
+   m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits()))
    {
    }
 
@@ -98,7 +98,7 @@ DL_PrivateKey::DL_PrivateKey(const DL_Group& group,
                              RandomNumberGenerator& rng) :
    m_group(group),
    m_private_key(generate_private_dl_key(group, rng)),
-   m_public_key(m_group.power_g_p(m_private_key, m_group.p_bits()))
+   m_public_key(m_group.power_g_p(m_private_key, m_private_key.bits()))
    {
    }
 


Test patch:
diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py
index 1864649b0..739221edd 100755
--- a/src/scripts/test_cli.py
+++ b/src/scripts/test_cli.py
@@ -1089,7 +1089,7 @@ def cli_tls_proxy_tests(tmp_dir):
     rc = tls_proxy.wait(5)
 
     if rc != 0:
-        logging.error('Unexpected return code %d', rc)
+        logging.error('Unexpected return code from tls_proxy %d', rc)
 
 def cli_trust_root_tests(tmp_dir):
     pem_file = os.path.join(tmp_dir, 'pems')
Repository: randombit/botan
Pull request #3521 (2023-04-25 15:03:57)

Prefer clear to resize(0) with std::vector


Patch:
diff --git a/src/lib/pk_pad/raw_hash/raw_hash.cpp b/src/lib/pk_pad/raw_hash/raw_hash.cpp
index 3e72ce93c..06dbb71f1 100644
--- a/src/lib/pk_pad/raw_hash/raw_hash.cpp
+++ b/src/lib/pk_pad/raw_hash/raw_hash.cpp
@@ -19,7 +19,7 @@ void RawHashFunction::final_result(uint8_t out[])
    {
    if(m_output_length > 0 && m_bits.size() != m_output_length)
       {
-      m_bits.resize(0);
+      m_bits.clear();
       throw Invalid_Argument("Raw padding was configured to use a " +
                              std::to_string(m_output_length) +
                              " byte hash but instead was used for a " +
@@ -27,12 +27,12 @@ void RawHashFunction::final_result(uint8_t out[])
       }
 
    copy_mem(out, m_bits.data(), m_bits.size());
-   m_bits.resize(0);
+   m_bits.clear();
    }
 
 void RawHashFunction::clear()
    {
-   m_bits.resize(0);
+   m_bits.clear();
    }
 
 std::unique_ptr<HashFunction> RawHashFunction::copy_state() const
diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp
index c9cacc9cd..4eefabf67 100644
--- a/src/lib/pubkey/mce/code_based_key_gen.cpp
+++ b/src/lib/pubkey/mce/code_based_key_gen.cpp
@@ -112,7 +112,7 @@ secure_vector<size_t> binary_matrix::row_reduced_echelon_form()
          failcnt++;
          if(!max)
             {
-            perm.resize(0);
+            perm.clear();
             }
          i--;
          }


Test patch:
diff --git a/src/tests/test_bufcomp.cpp b/src/tests/test_bufcomp.cpp
index 00776030f..fae2c29b0 100644
--- a/src/tests/test_bufcomp.cpp
+++ b/src/tests/test_bufcomp.cpp
@@ -108,7 +108,7 @@ Test::Result test_buffered_computation_convenience_api()
    check(result, out_strong_type, 6);
 
    // test resizing of final out param
-   out_vec.resize(0);
+   out_vec.clear();
    t.final(out_vec);
    out_vec.resize(t.output_length()*2);
    t.final(out_vec);
Repository: randombit/botan
Pull request #3667 (2023-08-10 19:32:49)

Add an argon2 specific Python wrapper
#3633 

coveralls: 
[![Coverage Status](https://coveralls.io/builds/61918433/badge)](https://coveralls.io/builds/61918433)

coverage: 91.703% (+0.03%) from 91.676% when pulling **c61c342a50ffc1efcfedb62c3b584d5f8b5dc9e3 on jack/python-argon2** into **ee20e4a4052d0df1fa2a54258cf7a53363749f76 on master**.


Patch:
diff --git a/src/python/botan3.py b/src/python/botan3.py
index 392a43c3a..c7ac481ff 100755
--- a/src/python/botan3.py
+++ b/src/python/botan3.py
@@ -984,6 +984,27 @@ def scrypt(out_len, password, salt, n=1024, r=8, p=8):
 
     return out_buf.raw
 
+# Argon2
+#
+# The variant param should be "Argon2i", "Argon2d", or "Argon2id"
+#
+# m specifies megabytes of memory used during processing
+# t specifies the number of passes
+# p specifies the parallelism
+#
+# returns an output of out_len bytes
+def argon2(variant, out_len, password, salt, m=256, t=1, p=1):
+    out_buf = create_string_buffer(out_len)
+    passbits = _ctype_str(password)
+    saltbits = _ctype_bits(salt)
+
+    _DLL.botan_pwdhash(_ctype_str(variant), m, t, p,
+                       out_buf, out_len,
+                       passbits, len(passbits),
+                       saltbits, len(saltbits))
+
+    return out_buf.raw
+
 #
 # KDF
 #


Test patch:
diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py
index a15f0f6a4..9dd12cb2a 100644
--- a/src/scripts/test_python.py
+++ b/src/scripts/test_python.py
@@ -96,6 +96,19 @@ class BotanPythonTests(unittest.TestCase):
 
         self.assertEqual(pbkdf, cmp_pbkdf)
 
+    def test_argon2i(self):
+        m = 8
+        p = 1
+        passphrase = 'pass'
+        salt = hex_decode('6161616161616161')
+        out_len = 16
+
+        output = botan.argon2('Argon2id', out_len, passphrase, salt, m, 1, p)
+        self.assertEqual(hex_encode(output), '39cc496a60824ddea31a83b0aecdb7a1')
+
+        output = botan.argon2('Argon2id', out_len, passphrase, salt, m, 2, p)
+        self.assertEqual(hex_encode(output), 'dfc6f1993cb9f0090c1c6e25629e607b')
+
     def test_scrypt(self):
         scrypt = botan.scrypt(10, '', '', 16, 1, 1)
         self.assertEqual(hex_encode(scrypt), "77d6576238657b203b19")