Repository: randombit/botan
Pull request #3586 (2023-06-15 14:10:08)

FIX: minor quirks in DL Scheme implementation
This fixes a few typos and inconsistency that surfaced while reviewing #3210.

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

coverage: 91.71% (-0.005%) from 91.715% when pulling **b958a7c6ded9b02179d6ffda6f81558bb9ed0145 on fix/minor_dl_scheme_quirks** into **96fe3b96d88a24eaceb6c5e14f15b77f816b339f on master**.


Patch:
diff --git a/doc/migration_guide.rst b/doc/migration_guide.rst
index b94df2deb..5bcc0b3fa 100644
--- a/doc/migration_guide.rst
+++ b/doc/migration_guide.rst
@@ -362,7 +362,7 @@ EMSA1 indicates that effectively the plain hash is signed, with no other
 padding. It is typically used for algorithms like ECSDA, but was allowed for
 RSA. This is now no longer implemented.
 
-If you must generates such signatures for some horrible reason, you can pre-hash
+If you must generate such signatures for some horrible reason, you can pre-hash
 the message using a hash function as usual, and then sign using a "Raw" padding,
 which will allow you to sign any arbitrary bits with no preprocessing.
 
@@ -405,7 +405,7 @@ Keys based on the discrete logarithm problem no longer derive from the
 DL_Scheme_PrivateKey and DL_Scheme_PublicKey classes; these classes
 have been removed.
 
-Functions to access DL algorithm interal fields (such as the integer value of
+Functions to access DL algorithm internal fields (such as the integer value of
 the private key using ``get_x``) have been removed. If you need access to this
 information you can use the new ``get_int_field`` function.
 
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp
index 3695afa1d..cd498405e 100644
--- a/src/lib/pubkey/dsa/dsa.cpp
+++ b/src/lib/pubkey/dsa/dsa.cpp
@@ -61,11 +61,15 @@ DSA_PublicKey::DSA_PublicKey(const DL_Group& group, const BigInt& y) {
 }
 
 DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, const DL_Group& group) {
+   BOTAN_ARG_CHECK(group.has_q(), "Q parameter must be set for DSA");
+
    m_private_key = std::make_shared<DL_PrivateKey>(group, rng);
    m_public_key = m_private_key->public_key();
 }
 
 DSA_PrivateKey::DSA_PrivateKey(const DL_Group& group, const BigInt& x) {
+   BOTAN_ARG_CHECK(group.has_q(), "Q parameter must be set for DSA");
+
    m_private_key = std::make_shared<DL_PrivateKey>(group, x);
    m_public_key = m_private_key->public_key();
 }
@@ -73,6 +77,8 @@ DSA_PrivateKey::DSA_PrivateKey(const DL_Group& group, const BigInt& x) {
 DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits) {
    m_private_key = std::make_shared<DL_PrivateKey>(alg_id, key_bits, DL_Group_Format::ANSI_X9_57);
    m_public_key = m_private_key->public_key();
+
+   BOTAN_ARG_CHECK(m_private_key->group().has_q(), "Q parameter must be set for DSA");
 }
 
 bool DSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const {
diff --git a/src/lib/pubkey/pk_algs.cpp b/src/lib/pubkey/pk_algs.cpp
index d4fd19c38..33ca1442e 100644
--- a/src/lib/pubkey/pk_algs.cpp
+++ b/src/lib/pubkey/pk_algs.cpp
@@ -297,7 +297,7 @@ std::unique_ptr<Private_Key> load_private_key(const AlgorithmIdentifier& alg_id,
 std::unique_ptr<Private_Key> create_ec_private_key(std::string_view alg_name,
                                                    const EC_Group& ec_group,
                                                    RandomNumberGenerator& rng) {
-   // Potentially unused if all EC algorthms are disabled
+   // Potentially unused if all EC algorithms are disabled
    BOTAN_UNUSED(alg_name, ec_group, rng);
 
 #if defined(BOTAN_HAS_ECDSA)


Test patch:
diff --git a/src/tests/test_tls_rfc8448.cpp b/src/tests/test_tls_rfc8448.cpp
index d4e08c70f..45435788f 100644
--- a/src/tests/test_tls_rfc8448.cpp
+++ b/src/tests/test_tls_rfc8448.cpp
@@ -1270,7 +1270,6 @@ class Test_TLS_RFC8448_Client : public Test_TLS_RFC8448 {
 
             Botan_Tests::CHECK("Server Hello",
                                [&](auto& result) {
-                                  result.require("ctx is available", ctx != nullptr);
                                   ctx->client.received_data(vars.get_req_bin("Record_ServerHello"));
 
                                   ctx->check_callback_invocations(result,
@@ -1284,7 +1283,6 @@ class Test_TLS_RFC8448_Client : public Test_TLS_RFC8448 {
 
             Botan_Tests::CHECK("other handshake messages and client auth",
                                [&](Test::Result& result) {
-                                  result.require("ctx is available", ctx != nullptr);
                                   ctx->client.received_data(vars.get_req_bin("Record_ServerHandshakeMessages"));
 
                                   ctx->check_callback_invocations(result,
@@ -1318,7 +1316,6 @@ class Test_TLS_RFC8448_Client : public Test_TLS_RFC8448 {
             Botan_Tests::CHECK(
                "Close Connection",
                [&](Test::Result& result) {
-                  result.require("ctx is available", ctx != nullptr);
                   ctx->client.close();
                   result.test_eq(
                      "Client close_notify", ctx->pull_send_buffer(), vars.get_req_bin("Record_Client_CloseNotify"));