Skip to content

Commit

Permalink
FIX: multiple c'tor calls
Browse files Browse the repository at this point in the history
  • Loading branch information
reneme authored and solemnwarning committed Aug 12, 2024
1 parent 390a93c commit cce2b6d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 75 deletions.
9 changes: 0 additions & 9 deletions src/lib/pubkey/dh/dh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ DH_PrivateKey::DH_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const
m_public_key = m_private_key->public_key();
}

DH_PrivateKey& DH_PrivateKey::operator=(DH_PrivateKey&& other) noexcept {
if(this != &other) {
static_cast<DH_PublicKey&>(*this) = static_cast<DH_PublicKey&&>(other);
m_private_key = std::move(other.m_private_key);
}

return *this;
}

std::unique_ptr<Public_Key> DH_PrivateKey::public_key() const {
return std::unique_ptr<DH_PublicKey>(new DH_PublicKey(m_public_key));
}
Expand Down
15 changes: 1 addition & 14 deletions src/lib/pubkey/dh/dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(2, 0) DH_PrivateKey final : public DH_PublicKey,
public PK_Key_Agreement_Key,
public virtual PK_Key_Agreement_Key,
public virtual Private_Key {
public:
/**
Expand All @@ -102,19 +102,6 @@ class BOTAN_PUBLIC_API(2, 0) DH_PrivateKey final : public DH_PublicKey,
*/
DH_PrivateKey(RandomNumberGenerator& rng, const DL_Group& group);

/* Work around a bug/oddity in clang-cl on Windows - the default move assignment operator
* generates multiple calls to Public_Key(Public_Key&&) as a technically-valid-but-dangerous
* side-effect of the class having the dllexport attribute. In the cast of the Public_Key
* class, this isn't actually a problem since its just an interface and has no data members,
* but Clang still raises a warning for it.
*
* We implement an explicit move assignment operator to silence this warning.
*/
DH_PrivateKey(const DH_PrivateKey&) = default;
DH_PrivateKey& operator=(const DH_PrivateKey&) = default;
DH_PrivateKey(DH_PrivateKey&&) = default;
DH_PrivateKey& operator=(DH_PrivateKey&& other) noexcept;

std::unique_ptr<Public_Key> public_key() const override;

std::vector<uint8_t> public_value() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pubkey/ecdh/ecdh.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(2, 0) ECDH_PrivateKey final : public ECDH_PublicKey,
public EC_PrivateKey,
public PK_Key_Agreement_Key {
public virtual EC_PrivateKey,
public virtual PK_Key_Agreement_Key {
public:
/**
* Load a private key.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/pubkey/ecies/ecies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace {
BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class ECIES_PrivateKey final : public EC_PrivateKey,
public PK_Key_Agreement_Key {
class ECIES_PrivateKey final : public virtual EC_PrivateKey,
public virtual PK_Key_Agreement_Key {
public:
explicit ECIES_PrivateKey(const ECDH_PrivateKey& private_key) :
EC_PublicKey(private_key), EC_PrivateKey(private_key), PK_Key_Agreement_Key(), m_key(private_key) {}
Expand Down
9 changes: 0 additions & 9 deletions src/lib/pubkey/rsa/rsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,6 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng, size_t bits, size_t e
RSA_PrivateKey::init(std::move(d), std::move(p), std::move(q), std::move(d1), std::move(d2), std::move(c));
}

RSA_PrivateKey& RSA_PrivateKey::operator=(RSA_PrivateKey&& other) noexcept {
if(this != &other) {
static_cast<RSA_PublicKey&>(*this) = static_cast<RSA_PublicKey&&>(other);
m_private = std::move(other.m_private);
}

return *this;
}

const BigInt& RSA_PrivateKey::get_int_field(std::string_view field) const {
if(field == "p") {
return m_private->get_p();
Expand Down
17 changes: 2 additions & 15 deletions src/lib/pubkey/rsa/rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class BOTAN_PUBLIC_API(2, 0) RSA_PublicKey : public virtual Public_Key {
BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(2, 0) RSA_PrivateKey final : public Private_Key,
public RSA_PublicKey {
class BOTAN_PUBLIC_API(2, 0) RSA_PrivateKey final : public virtual Private_Key,
public virtual RSA_PublicKey {
public:
/**
* Load a private key.
Expand Down Expand Up @@ -133,19 +133,6 @@ class BOTAN_PUBLIC_API(2, 0) RSA_PrivateKey final : public Private_Key,
*/
RSA_PrivateKey(RandomNumberGenerator& rng, size_t bits, size_t exp = 65537);

/* Work around a bug/oddity in clang-cl on Windows - the default move assignment operator
* generates multiple calls to Public_Key(Public_Key&&) as a technically-valid-but-dangerous
* side-effect of the class having the dllexport attribute. In the cast of the Public_Key
* class, this isn't actually a problem since its just an interface and has no data members,
* but Clang still raises a warning for it.
*
* We implement an explicit move assignment operator to silence this warning.
*/
RSA_PrivateKey(const RSA_PrivateKey&) = default;
RSA_PrivateKey& operator=(const RSA_PrivateKey&) = default;
RSA_PrivateKey(RSA_PrivateKey&&) = default;
RSA_PrivateKey& operator=(RSA_PrivateKey&&) noexcept;

std::unique_ptr<Public_Key> public_key() const override;

bool check_key(RandomNumberGenerator& rng, bool) const override;
Expand Down
9 changes: 0 additions & 9 deletions src/lib/tls/tls13_pqc/hybrid_public_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,6 @@ Hybrid_KEM_PrivateKey::Hybrid_KEM_PrivateKey(std::vector<std::unique_ptr<Private
});
}

Hybrid_KEM_PrivateKey& Hybrid_KEM_PrivateKey::operator=(Hybrid_KEM_PrivateKey&& other) noexcept {
if(this != &other) {
static_cast<Hybrid_KEM_PublicKey&>(*this) = static_cast<Hybrid_KEM_PublicKey&&>(other);
m_private_keys = std::move(other.m_private_keys);
}

return *this;
}

secure_vector<uint8_t> Hybrid_KEM_PrivateKey::private_key_bits() const {
throw Not_Implemented("Hybrid private keys cannot be serialized");
}
Expand Down
17 changes: 2 additions & 15 deletions src/lib/tls/tls13_pqc/hybrid_public_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
* Composes a number of private keys for hybrid key agreement as defined in this
* IETF draft: https://datatracker.ietf.org/doc/html/draft-ietf-tls-hybrid-design-04
*/
class BOTAN_TEST_API Hybrid_KEM_PrivateKey final : public Private_Key,
public Hybrid_KEM_PublicKey {
class BOTAN_TEST_API Hybrid_KEM_PrivateKey final : public virtual Private_Key,
public virtual Hybrid_KEM_PublicKey {
public:
/**
* Generate a hybrid private key for the given TLS code point.
Expand All @@ -93,19 +93,6 @@ class BOTAN_TEST_API Hybrid_KEM_PrivateKey final : public Private_Key,
public:
Hybrid_KEM_PrivateKey(std::vector<std::unique_ptr<Private_Key>> private_keys);

/* Work around a bug/oddity in clang-cl on Windows - the default move assignment operator
* generates multiple calls to Public_Key(Public_Key&&) as a technically-valid-but-dangerous
* side-effect of the class having the dllexport attribute. In the cast of the Public_Key
* class, this isn't actually a problem since its just an interface and has no data members,
* but Clang still raises a warning for it.
*
* We implement an explicit move assignment operator to silence this warning.
*/
Hybrid_KEM_PrivateKey(const Hybrid_KEM_PublicKey&) = delete;
Hybrid_KEM_PrivateKey& operator=(const Hybrid_KEM_PrivateKey&) = delete;
Hybrid_KEM_PrivateKey(Hybrid_KEM_PrivateKey&&) = default;
Hybrid_KEM_PrivateKey& operator=(Hybrid_KEM_PrivateKey&& other) noexcept;

secure_vector<uint8_t> private_key_bits() const override;

std::unique_ptr<Public_Key> public_key() const override;
Expand Down

0 comments on commit cce2b6d

Please sign in to comment.