Skip to content

Commit

Permalink
Merge pull request #4478 from weberph2/fix-msvc-warnings
Browse files Browse the repository at this point in the history
Fix MSVC warnings in TPM2
  • Loading branch information
randombit authored Dec 17, 2024
2 parents 6943449 + b307ce8 commit eadd6b1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/lib/prov/tpm2/tpm2_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <botan/tpm2_session.h>

#include <botan/internal/fmt.h>
#include <botan/internal/int_utils.h>
#include <botan/internal/loadstor.h>
#include <botan/internal/stl_util.h>
#include <botan/internal/tpm2_algo_mappings.h>
Expand Down Expand Up @@ -93,6 +94,9 @@ Context::Context(ESYS_CONTEXT* ctx, bool external) : m_impl(std::make_unique<Imp
BOTAN_ASSERT_NONNULL(m_impl->m_ctx);
}

Context::Context(Context&&) noexcept = default;
Context& Context::operator=(Context&&) noexcept = default;

void Context::use_botan_crypto_backend(const std::shared_ptr<Botan::RandomNumberGenerator>& rng) {
#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
BOTAN_STATE_CHECK(!uses_botan_crypto_backend());
Expand Down Expand Up @@ -194,7 +198,7 @@ template <TPM2_CAP capability, typename ReturnT>
const auto new_properties = extract(capability_data->data, count);
BOTAN_ASSERT_NOMSG(new_properties.size() <= count);
properties.insert(properties.end(), new_properties.begin(), new_properties.end());
count -= new_properties.size();
count -= checked_cast_to<uint32_t>(new_properties.size());
}

return properties;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/prov/tpm2/tpm2_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class BOTAN_PUBLIC_API(3, 6) Context final : public std::enable_shared_from_this
static std::shared_ptr<Context> create(ESYS_CONTEXT* ctx);

Context(const Context&) = delete;
Context(Context&& ctx) noexcept = default;
Context(Context&&) noexcept;
~Context();

Context& operator=(const Context&) = delete;
Context& operator=(Context&& ctx) noexcept = default;
Context& operator=(Context&&) noexcept;

/**
* Overrides the TSS2's crypto callbacks with Botan's functionality.
Expand Down
6 changes: 3 additions & 3 deletions src/lib/prov/tpm2/tpm2_ecc/tpm2_ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace Botan::TPM2 {

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(3, 6) EC_PublicKey final : public virtual Botan::TPM2::PublicKey,
public virtual Botan::EC_PublicKey {
public:
Expand Down Expand Up @@ -44,9 +47,6 @@ class BOTAN_PUBLIC_API(3, 6) EC_PublicKey final : public virtual Botan::TPM2::Pu
EC_PublicKey(Object handle, SessionBundle sessions, std::pair<EC_Group, EC_AffinePoint> public_key);
};

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(3, 6) EC_PrivateKey final : public virtual Botan::TPM2::PrivateKey,
public virtual Botan::EC_PublicKey {
public:
Expand Down
1 change: 0 additions & 1 deletion src/lib/prov/tpm2/tpm2_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ size_t HashFunction::output_length() const {
case TPM2_ALG_SHA512:
case TPM2_ALG_SHA3_512:
return 64;
return 64;
default:
throw Invalid_State("TPM 2.0 hash object with unexpected hash type");
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/prov/tpm2/tpm2_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ TPM2B_TEMPLATE marshal_template(const TPMT_PUBLIC& key_template) {
size_t offset = 0;
check_rc("Tss2_MU_TPMT_PUBLIC_Marshal",
Tss2_MU_TPMT_PUBLIC_Marshal(&key_template, result.buffer, sizeof(TPMT_PUBLIC), &offset));
result.size = offset;
BOTAN_ASSERT_NOMSG(offset <= sizeof(result.buffer));
result.size = static_cast<uint16_t>(offset);
return result;
}

Expand Down
7 changes: 6 additions & 1 deletion src/lib/prov/tpm2/tpm2_rng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ void RandomNumberGenerator::fill_bytes_with_input(std::span<uint8_t> output, std
unique_esys_ptr<TPM2B_DIGEST> digest = nullptr;
const auto requested_bytes = std::min(out.remaining_capacity(), m_max_tpm2_rng_bytes);
check_rc("Esys_GetRandom",
Esys_GetRandom(*m_ctx, m_sessions[0], m_sessions[1], m_sessions[2], requested_bytes, out_ptr(digest)));
Esys_GetRandom(*m_ctx,
m_sessions[0],
m_sessions[1],
m_sessions[2],
static_cast<uint16_t>(requested_bytes),
out_ptr(digest)));

BOTAN_ASSERT_NOMSG(digest->size == requested_bytes);
out.append(as_span(*digest));
Expand Down
7 changes: 4 additions & 3 deletions src/lib/prov/tpm2/tpm2_rsa/tpm2_rsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <botan/tpm2_key.h>

namespace Botan::TPM2 {

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(3, 6) RSA_PublicKey final : public virtual Botan::TPM2::PublicKey,
public virtual Botan::RSA_PublicKey {
public:
Expand Down Expand Up @@ -39,9 +43,6 @@ class BOTAN_PUBLIC_API(3, 6) RSA_PublicKey final : public virtual Botan::TPM2::P
RSA_PublicKey(Object handle, SessionBundle sessions, const TPM2B_PUBLIC* public_blob);
};

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

class BOTAN_PUBLIC_API(3, 6) RSA_PrivateKey final : public virtual Botan::TPM2::PrivateKey,
public virtual Botan::RSA_PublicKey {
public:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/prov/tpm2/tpm2_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ template <tpm2_buffer T>
constexpr T init_with_size(size_t length) {
T result;
BOTAN_ASSERT_NOMSG(length <= sizeof(result.buffer));
result.size = length;
result.size = static_cast<decltype(result.size)>(length);
clear_bytes(result.buffer, length);
return result;
}
Expand Down

0 comments on commit eadd6b1

Please sign in to comment.