Botan 3.14.1
Crypto and TLS for C&
Botan::TPM2::Context Class Referencefinal

#include <tpm2_context.h>

Inheritance diagram for Botan::TPM2::Context:

Public Member Functions

 Context (const Context &)=delete
 Context (Context &&) noexcept
ESYS_CONTEXT * esys_context () noexcept
void evict (std::unique_ptr< TPM2::PrivateKey > key, const SessionBundle &sessions)
 Evicts a persistent key from the TPM. The key cannot be used after.
std::optional< TPM2_HANDLE > find_free_persistent_handle () const
std::string manufacturer () const
size_t max_random_bytes_per_request () const
 operator ESYS_CONTEXT * () noexcept
Context & operator= (const Context &)=delete
Context & operator= (Context &&) noexcept
TPM2_HANDLE persist (TPM2::PrivateKey &key, const SessionBundle &sessions, std::span< const uint8_t > auth_value={}, std::optional< TPM2_HANDLE > persistent_handle=std::nullopt)
 Makes key persistent at location persistent_handle or any free.
std::vector< TPM2_HANDLE > persistent_handles () const
std::unique_ptr< TPM2::PrivateKey > storage_root_key (std::span< const uint8_t > auth_value, const SessionBundle &sessions)
bool supports_algorithm (std::string_view algo_name) const
std::vector< ESYS_TR > transient_handles () const
void use_botan_crypto_backend (const std::shared_ptr< Botan::RandomNumberGenerator > &rng)
bool uses_botan_crypto_backend () const noexcept
std::string vendor () const
 ~Context ()

Static Public Member Functions

static std::shared_ptr< Context > create (const std::string &tcti_nameconf)
static std::shared_ptr< Context > create (ESYS_CONTEXT *ctx)
static std::shared_ptr< Context > create (std::optional< std::string > tcti={}, std::optional< std::string > conf={})
static bool supports_botan_crypto_backend () noexcept

Detailed Description

Central class for interacting with a TPM2. Additional to managing the connection to the TPM, this provides authoritative information about the TPM's capabilities. Also, it allows to persist and evict keys generated by the TPM.

Definition at line 38 of file tpm2_context.h.

Constructor & Destructor Documentation

◆ Context() [1/2]

Botan::TPM2::Context::Context ( const Context & )
delete

◆ Context() [2/2]

Botan::TPM2::Context::Context ( Context && )
defaultnoexcept

References Context().

◆ ~Context()

Botan::TPM2::Context::~Context ( )

Definition at line 412 of file tpm2_context.cpp.

412 {
413 if(!m_impl) {
414 return;
415 }
416
417#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
418 // If this object manages a crypto backend state object and the ESYS context
419 // will live on, because it was externally provided, we have to de-register
420 // this state object from the crypto callbacks.
421 //
422 // This will prevent the crypto backend callbacks from using a dangling
423 // pointer and cause graceful errors if the externally provided ESYS context
424 // is used for any action that would still need the crypto backend state.
425 //
426 // We deliberately do not just disable the crypto backend silently, as that
427 // might give users the false impression that they continue to benefit from
428 // the crypto backend while in fact they're back to the TSS' default.
429 if(m_impl->m_external && uses_botan_crypto_backend()) {
430 try {
431 set_crypto_callbacks(esys_context(), nullptr /* reset callback state */);
432 } catch(...) {
433 // ignore errors in destructor
434 }
435 m_impl->m_crypto_callback_state.reset();
436 }
437#endif
438
439 // We don't finalize contexts that were provided externally. Those are
440 // expected to be handled by the library users' applications.
441 if(!m_impl->m_external) {
442 // If the TCTI context was initialized explicitly, Esys_GetTcti() will
443 // return a pointer to the TCTI context that then has to be finalized
444 // explicitly. See ESAPI Specification Section 6.3 "Esys_GetTcti".
445 TSS2_TCTI_CONTEXT* tcti_ctx = nullptr; // NOLINT(*-const-correctness) bug in clang-tidy
446 Esys_GetTcti(m_impl->m_ctx, &tcti_ctx); // ignore error in destructor
447 if(tcti_ctx != nullptr) {
448 Tss2_TctiLdr_Finalize(&tcti_ctx);
449 }
450
451 Esys_Finalize(&m_impl->m_ctx);
452 }
453}
ESYS_CONTEXT * esys_context() noexcept
bool uses_botan_crypto_backend() const noexcept
void set_crypto_callbacks(ESYS_CONTEXT *ctx, void *callback_state)

References esys_context(), Botan::TPM2::set_crypto_callbacks(), and uses_botan_crypto_backend().

Member Function Documentation

◆ create() [1/3]

std::shared_ptr< Context > Botan::TPM2::Context::create ( const std::string & tcti_nameconf)
static
Parameters
tcti_nameconfthis is passed to Tss2_TctiLdr_Initialize verbatim

Definition at line 56 of file tpm2_context.cpp.

56 {
57 TSS2_TCTI_CONTEXT* tcti_ctx = nullptr;
58 ESYS_CONTEXT* esys_ctx = nullptr;
59 check_rc("TCTI Initialization", Tss2_TctiLdr_Initialize(tcti_nameconf.c_str(), &tcti_ctx));
60 BOTAN_ASSERT_NONNULL(tcti_ctx);
61 check_rc("TPM2 Initialization", Esys_Initialize(&esys_ctx, tcti_ctx, nullptr /* ABI version */));
62 BOTAN_ASSERT_NONNULL(esys_ctx);
63
64 // We cannot std::make_shared as the constructor is private
65 return std::shared_ptr<Context>(new Context(esys_ctx, false /* context is managed by us */));
66}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:121
Context(const Context &)=delete
constexpr void check_rc(std::string_view location, TSS2_RC rc)
Definition tpm2_util.h:53

References BOTAN_ASSERT_NONNULL, Botan::TPM2::check_rc(), and Context().

Referenced by botan_tpm2_ctx_from_esys(), botan_tpm2_ctx_init(), and botan_tpm2_ctx_init_ex().

◆ create() [2/3]

std::shared_ptr< Context > Botan::TPM2::Context::create ( ESYS_CONTEXT * ctx)
static

Create a TPM2::Context from an externally sourced TPM2-TSS ESYS Context. Note that the input contexts need to remain alive for the lifetime of the entire TPM2::Context! This allows to use Botan's TPM2 functionality within an existing ESAPI application.

Note that Botan won't finalize an externally provided ESYS context, this responsibility remains with the caller in this case.

Parameters
ctxthe already set up ESYS_CONTEXT*

Definition at line 83 of file tpm2_context.cpp.

83 {
84 BOTAN_ARG_CHECK(esys_ctx != nullptr, "provided esys_ctx must not be null");
85
86 // We cannot std::make_shared as the constructor is private
87 return std::shared_ptr<Context>(new Context(esys_ctx, true /* context is managed externally */));
88}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and Context().

◆ create() [3/3]

std::shared_ptr< Context > Botan::TPM2::Context::create ( std::optional< std::string > tcti = {},
std::optional< std::string > conf = {} )
static
Parameters
tctiif set this is passed to Tss2_TctiLdr_Initialize_Ex verbatim otherwise a nullptr is passed.
confif set this is passed to Tss2_TctiLdr_Initialize_Ex verbatim otherwise a nullptr is passed.

Definition at line 68 of file tpm2_context.cpp.

68 {
69 const char* const tcti_ptr = tcti.has_value() ? tcti->c_str() : nullptr;
70 const char* const conf_ptr = conf.has_value() ? conf->c_str() : nullptr;
71
72 TSS2_TCTI_CONTEXT* tcti_ctx = nullptr;
73 ESYS_CONTEXT* esys_ctx = nullptr;
74 check_rc("TCTI Initialization", Tss2_TctiLdr_Initialize_Ex(tcti_ptr, conf_ptr, &tcti_ctx));
75 BOTAN_ASSERT_NONNULL(tcti_ctx);
76 check_rc("TPM2 Initialization", Esys_Initialize(&esys_ctx, tcti_ctx, nullptr /* ABI version */));
77 BOTAN_ASSERT_NONNULL(esys_ctx);
78
79 // We cannot std::make_shared as the constructor is private
80 return std::shared_ptr<Context>(new Context(esys_ctx, false /* context is managed by us */));
81}

References BOTAN_ASSERT_NONNULL, Botan::TPM2::check_rc(), and Context().

◆ esys_context()

ESYS_CONTEXT * Botan::TPM2::Context::esys_context ( )
noexcept
Returns
an ESYS_CONTEXT* for use in other TPM2 functions.

Definition at line 124 of file tpm2_context.cpp.

124 {
125 return m_impl->m_ctx;
126}

Referenced by operator ESYS_CONTEXT *(), operator=(), use_botan_crypto_backend(), and ~Context().

◆ evict()

void Botan::TPM2::Context::evict ( std::unique_ptr< TPM2::PrivateKey > key,
const SessionBundle & sessions )

Evicts a persistent key from the TPM. The key cannot be used after.

Definition at line 386 of file tpm2_context.cpp.

386 {
388
389 auto& handles = key->handles();
390 BOTAN_ARG_CHECK(handles.has_persistent_handle(), "Key does not have a persistent handle assigned");
391
392 // 1. Evict the key from the TPM's NV storage
393 // This will free the persistent handle, but the transient handle will
394 // still be valid.
395 ESYS_TR no_new_handle = ESYS_TR_NONE;
396 check_rc("Esys_EvictControl",
397 Esys_EvictControl(m_impl->m_ctx,
398 ESYS_TR_RH_OWNER /*TODO: hierarchy*/,
399 handles.transient_handle(),
400 sessions[0],
401 sessions[1],
402 sessions[2],
403 0,
404 &no_new_handle));
405 BOTAN_ASSERT(no_new_handle == ESYS_TR_NONE, "When deleting a key, no new handle is returned");
406
407 // 2. The persistent key was deleted and the transient key was flushed by
408 // Esys_EvictControl().
409 handles._disengage();
410}
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:69
uint32_t ESYS_TR
Forward declaration of TSS2 type for convenience.

References BOTAN_ARG_CHECK, BOTAN_ASSERT, BOTAN_ASSERT_NONNULL, and Botan::TPM2::check_rc().

◆ find_free_persistent_handle()

std::optional< TPM2_HANDLE > Botan::TPM2::Context::find_free_persistent_handle ( ) const
Returns
a persistent handle that is currently not in use or std::nullopt if no such handle is available

Definition at line 306 of file tpm2_context.cpp.

306 {
307 const auto occupied_handles = persistent_handles();
308
309 // This is modeled after the implementation in tpm2-tools, which also takes
310 // "platform persistent" handles into account. We don't do that here, but
311 // we might need to in the future.
312 //
313 // See: https://github.com/tpm2-software/tpm2-tools/blob/bd832d3f79/lib/tpm2_capability.c#L143-L196
314
315 // all persistent handles are occupied
316 if(occupied_handles.size() >= TPM2_MAX_CAP_HANDLES) {
317 return std::nullopt;
318 }
319
320 // find the lowest handle that is not occupied
321 for(TPM2_HANDLE i = TPM2_PERSISTENT_FIRST; i < TPM2_PERSISTENT_LAST; ++i) {
322 if(!value_exists(occupied_handles, i)) {
323 return i;
324 }
325 }
326
328}
#define BOTAN_ASSERT_UNREACHABLE()
Definition assert.h:173
std::vector< TPM2_HANDLE > persistent_handles() const
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:44
uint32_t TPM2_HANDLE
Forward declaration of TSS2 type for convenience.

References BOTAN_ASSERT_UNREACHABLE, persistent_handles(), and Botan::value_exists().

Referenced by persist().

◆ manufacturer()

std::string Botan::TPM2::Context::manufacturer ( ) const
Returns
the Manufacturer of the TPM2

Definition at line 225 of file tpm2_context.cpp.

225 {
226 std::array<uint8_t, 4 + 1 /* ensure zero termination */> manufacturer_data{};
227 store_be(std::span{manufacturer_data}.first<4>(), get_tpm_property(m_impl->m_ctx, TPM2_PT_MANUFACTURER));
228 return std::string(cast_uint8_ptr_to_char(manufacturer_data.data()));
229}
const char * cast_uint8_ptr_to_char(const uint8_t *b)
Definition mem_ops.h:323
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References Botan::cast_uint8_ptr_to_char(), and Botan::store_be().

◆ max_random_bytes_per_request()

size_t Botan::TPM2::Context::max_random_bytes_per_request ( ) const
Returns
the maximum number of random bytes to be requested at once

Definition at line 293 of file tpm2_context.cpp.

293 {
294 return get_tpm_property(m_impl->m_ctx, TPM2_PT_MAX_DIGEST);
295}

◆ operator ESYS_CONTEXT *()

Botan::TPM2::Context::operator ESYS_CONTEXT * ( )
inlinenoexcept

Definition at line 104 of file tpm2_context.h.

104{ return esys_context(); }

References esys_context().

◆ operator=() [1/2]

Context & Botan::TPM2::Context::operator= ( const Context & )
delete

References Context().

◆ operator=() [2/2]

Context & Botan::TPM2::Context::operator= ( Context && )
defaultnoexcept

◆ persist()

TPM2_HANDLE Botan::TPM2::Context::persist ( TPM2::PrivateKey & key,
const SessionBundle & sessions,
std::span< const uint8_t > auth_value = {},
std::optional< TPM2_HANDLE > persistent_handle = std::nullopt )

Makes key persistent at location persistent_handle or any free.

Definition at line 335 of file tpm2_context.cpp.

338 {
339 auto& handles = key.handles();
340
341 BOTAN_ARG_CHECK(!persistent_handle || !value_exists(persistent_handles(), persistent_handle.value()),
342 "Persistent handle already in use");
343 BOTAN_ARG_CHECK(!handles.has_persistent_handle(), "Key already has a persistent handle assigned");
344
345 // 1. Decide on the location to persist the key to.
346 // This uses either the handle provided by the caller or a free handle.
347 const std::optional<TPMI_DH_PERSISTENT> new_persistent_handle =
348 persistent_handle.has_value() ? persistent_handle : find_free_persistent_handle();
349
350 BOTAN_STATE_CHECK(new_persistent_handle.has_value());
351
352 // 2. Persist the transient key in the TPM's NV storage
353 // This will flush the transient key handle and replace it with a new
354 // transient handle that references the persisted key.
355 check_rc("Esys_EvictControl",
356 Esys_EvictControl(m_impl->m_ctx,
357 ESYS_TR_RH_OWNER /*TODO: hierarchy*/,
358 handles.transient_handle(),
359 sessions[0],
360 sessions[1],
361 sessions[2],
362 *new_persistent_handle,
363 out_transient_handle(handles)));
364 BOTAN_ASSERT_NOMSG(handles.has_transient_handle());
365
366 // 3. Reset the auth value of the key object
367 // This is necessary to ensure that the key object remains usable after
368 // the transient handle was recreated inside Esys_EvictControl().
369 if(!auth_value.empty()) {
370 const auto user_auth = copy_into<TPM2B_AUTH>(auth_value);
371 check_rc("Esys_TR_SetAuth", Esys_TR_SetAuth(m_impl->m_ctx, handles.transient_handle(), &user_auth));
372 }
373
374 // 4. Update the key object with the new persistent handle
375 // This double-checks that the key was persisted at the correct location,
376 // but also brings the key object into a consistent state.
377 check_rc("Esys_TR_GetTpmHandle",
378 Esys_TR_GetTpmHandle(m_impl->m_ctx, handles.transient_handle(), out_persistent_handle(handles)));
379
380 BOTAN_ASSERT_NOMSG(handles.has_persistent_handle());
381 BOTAN_ASSERT_EQUAL(*new_persistent_handle, handles.persistent_handle(), "key was persisted at the correct location");
382
383 return *new_persistent_handle;
384}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:95
std::optional< TPM2_HANDLE > find_free_persistent_handle() const
constexpr auto out_persistent_handle(Object &object)
Definition tpm2_util.h:223
constexpr auto out_transient_handle(Object &object)
Definition tpm2_util.h:217
constexpr void copy_into(T &dest, std::span< const uint8_t > data)
Definition tpm2_util.h:116

References BOTAN_ARG_CHECK, BOTAN_ASSERT_EQUAL, BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, Botan::TPM2::check_rc(), Botan::TPM2::copy_into(), find_free_persistent_handle(), Botan::TPM2::PrivateKey::handles(), Botan::TPM2::out_persistent_handle(), Botan::TPM2::out_transient_handle(), persistent_handles(), and Botan::value_exists().

◆ persistent_handles()

std::vector< TPM2_HANDLE > Botan::TPM2::Context::persistent_handles ( ) const

Definition at line 330 of file tpm2_context.cpp.

330 {
331 return get_tpm_property_list<TPM2_CAP_HANDLES, TPM2_HANDLE>(
332 m_impl->m_ctx, TPM2_PERSISTENT_FIRST, TPM2_MAX_CAP_HANDLES);
333}

Referenced by find_free_persistent_handle(), and persist().

◆ storage_root_key()

std::unique_ptr< TPM2::PrivateKey > Botan::TPM2::Context::storage_root_key ( std::span< const uint8_t > auth_value,
const SessionBundle & sessions )

Definition at line 297 of file tpm2_context.cpp.

298 {
299 return TPM2::PrivateKey::load_persistent(shared_from_this(), storage_root_key_handle, auth_value, sessions);
300}
static std::unique_ptr< PrivateKey > load_persistent(const std::shared_ptr< Context > &ctx, TPM2_HANDLE persistent_object_handle, std::span< const uint8_t > auth_value, const SessionBundle &sessions)
Definition tpm2_key.cpp:184

References Botan::TPM2::PrivateKey::load_persistent().

◆ supports_algorithm()

bool Botan::TPM2::Context::supports_algorithm ( std::string_view algo_name) const

The algo_name can be any of the string algorithm specifiers used elsewhere. For example, "RSA", "AES-128", "SHA-1", "CTR(3DES)", etc.

Returns
true if the specified algorithm is supported by the TPM

Definition at line 231 of file tpm2_context.cpp.

231 {
232 // Go through all the string mappings we have available and check if we
233 // can find the algorithm name in any of them. If we do, we can check if
234 // the TPM supports the required algorithms.
235 const auto required_alg_ids = [&]() -> std::vector<TPM2_ALG_ID> {
236 std::vector<TPM2_ALG_ID> result;
237 if(auto algo_id = asymmetric_algorithm_botan_to_tss2(algo_name)) {
238 result.push_back(algo_id.value());
239 }
240
241 if(auto hash_id = hash_algo_botan_to_tss2(algo_name)) {
242 result.push_back(hash_id.value());
243 }
244
245 if(auto block_id = block_cipher_botan_to_tss2(algo_name)) {
246 result.push_back(block_id->first);
247 }
248
249 if(auto cipher_mode_id = cipher_mode_botan_to_tss2(algo_name)) {
250 result.push_back(cipher_mode_id.value());
251 }
252
253 if(auto cipher_spec = cipher_botan_to_tss2(algo_name)) {
254 result.push_back(cipher_spec->algorithm);
255 result.push_back(cipher_spec->mode.sym);
256 }
257
258 if(auto sig_padding = rsa_signature_padding_botan_to_tss2(algo_name)) {
259 result.push_back(sig_padding.value());
260 }
261
262 if(auto sig = rsa_signature_scheme_botan_to_tss2(algo_name)) {
263 result.push_back(sig->scheme);
264 result.push_back(sig->details.any.hashAlg);
265 }
266
267 if(auto enc_scheme = rsa_encryption_scheme_botan_to_tss2(algo_name)) {
268 result.push_back(enc_scheme->scheme);
269 if(enc_scheme->scheme == TPM2_ALG_OAEP) {
270 result.push_back(enc_scheme->details.oaep.hashAlg);
271 }
272 }
273
274 if(auto enc_id = rsa_encryption_padding_botan_to_tss2(algo_name)) {
275 result.push_back(enc_id.value());
276 }
277
278 return result;
279 }();
280
281 if(required_alg_ids.empty()) {
282 // The algorithm name is not known to us, so we cannot check for support.
283 return false;
284 }
285
286 const auto algo_caps =
287 get_tpm_property_list<TPM2_CAP_ALGS, TPM2_ALG_ID>(m_impl->m_ctx, TPM2_ALG_FIRST, TPM2_MAX_CAP_ALGS);
288
289 return std::all_of(
290 required_alg_ids.begin(), required_alg_ids.end(), [&](TPM2_ALG_ID id) { return value_exists(algo_caps, id); });
291}
std::optional< TPMT_SIG_SCHEME > rsa_signature_scheme_botan_to_tss2(std::string_view name)
std::optional< TPMI_ALG_SIG_SCHEME > rsa_signature_padding_botan_to_tss2(std::string_view padding_name) noexcept
std::optional< TPMI_ALG_ASYM_SCHEME > rsa_encryption_padding_botan_to_tss2(std::string_view name) noexcept
std::optional< std::pair< TPMI_ALG_SYM, TPM2_KEY_BITS > > block_cipher_botan_to_tss2(std::string_view cipher_name) noexcept
std::optional< TPMT_SYM_DEF > cipher_botan_to_tss2(std::string_view algo_name)
std::optional< TPMT_RSA_DECRYPT > rsa_encryption_scheme_botan_to_tss2(std::string_view padding)
std::optional< TPMI_ALG_HASH > hash_algo_botan_to_tss2(std::string_view hash_name) noexcept
std::optional< TPM2_ALG_ID > asymmetric_algorithm_botan_to_tss2(std::string_view algo_name) noexcept
std::optional< TPMI_ALG_SYM_MODE > cipher_mode_botan_to_tss2(std::string_view mode_name) noexcept

References Botan::TPM2::asymmetric_algorithm_botan_to_tss2(), Botan::TPM2::block_cipher_botan_to_tss2(), Botan::TPM2::cipher_botan_to_tss2(), Botan::TPM2::cipher_mode_botan_to_tss2(), Botan::TPM2::hash_algo_botan_to_tss2(), Botan::TPM2::rsa_encryption_padding_botan_to_tss2(), Botan::TPM2::rsa_encryption_scheme_botan_to_tss2(), Botan::TPM2::rsa_signature_padding_botan_to_tss2(), and Botan::TPM2::rsa_signature_scheme_botan_to_tss2().

◆ supports_botan_crypto_backend()

bool Botan::TPM2::Context::supports_botan_crypto_backend ( )
staticnoexcept

Checks if the TSS2 supports registering Botan's crypto backend at runtime. Older versions of the TSS2 do not support this feature ( 4.0.0), also Botan may be compiled without support for TSS' crypto backend.

Returns
true if the TSS2 supports Botan's crypto backend

Definition at line 48 of file tpm2_context.cpp.

48 {
49#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
51#else
52 return false;
53#endif
54}
bool supports_botan_crypto_backend() noexcept

References Botan::TPM2::supports_botan_crypto_backend().

Referenced by botan_tpm2_supports_crypto_backend(), and operator=().

◆ transient_handles()

std::vector< ESYS_TR > Botan::TPM2::Context::transient_handles ( ) const

Definition at line 302 of file tpm2_context.cpp.

302 {
303 return get_tpm_property_list<TPM2_CAP_HANDLES, ESYS_TR>(m_impl->m_ctx, TPM2_TRANSIENT_FIRST, TPM2_MAX_CAP_HANDLES);
304}

◆ use_botan_crypto_backend()

void Botan::TPM2::Context::use_botan_crypto_backend ( const std::shared_ptr< Botan::RandomNumberGenerator > & rng)

Overrides the TSS2's crypto callbacks with Botan's functionality.

This replaces all cryptographic functionality required for the communication with the TPM by botan's implementations. The TSS2 would otherwise use OpenSSL or mbedTLS.

Note that the provided rng should not be dependent on the TPM.

Parameters
Random Number Generatorsthe RNG to use for the crypto operations
Exceptions
Not_Implementedif the TPM2-TSS does not support crypto callbacks
See also
supports_botan_crypto_backend()

Definition at line 99 of file tpm2_context.cpp.

99 {
100#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
102 m_impl->m_crypto_callback_state = Botan::TPM2::use_botan_crypto_backend(esys_context(), rng);
103#else
104 BOTAN_UNUSED(rng);
105 throw Not_Implemented("This build of botan does not provide the TPM2 crypto backend");
106#endif
107}
#define BOTAN_UNUSED
Definition assert.h:151
std::unique_ptr< CryptoCallbackState > use_botan_crypto_backend(ESYS_CONTEXT *context, const std::shared_ptr< Botan::RandomNumberGenerator > &rng)

References BOTAN_STATE_CHECK, BOTAN_UNUSED, Context(), esys_context(), use_botan_crypto_backend(), Botan::TPM2::use_botan_crypto_backend(), and uses_botan_crypto_backend().

Referenced by operator=(), and use_botan_crypto_backend().

◆ uses_botan_crypto_backend()

bool Botan::TPM2::Context::uses_botan_crypto_backend ( ) const
noexcept
Returns
true if botan is used for the TSS' crypto functions

Definition at line 109 of file tpm2_context.cpp.

109 {
110#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
111 return m_impl->m_crypto_callback_state != nullptr;
112#else
113 return false;
114#endif
115}

Referenced by operator=(), use_botan_crypto_backend(), and ~Context().

◆ vendor()

std::string Botan::TPM2::Context::vendor ( ) const
Returns
the Vendor of the TPM2

Definition at line 208 of file tpm2_context.cpp.

208 {
209 constexpr std::array properties = {
210 TPM2_PT_VENDOR_STRING_1, TPM2_PT_VENDOR_STRING_2, TPM2_PT_VENDOR_STRING_3, TPM2_PT_VENDOR_STRING_4};
211 std::array<uint8_t, properties.size() * 4 + 1 /* ensure zero-termination */> vendor_string{};
212
213 BufferStuffer bs(vendor_string);
214
215 // The vendor name is transported in several uint32_t fields that are
216 // loaded as big-endian bytes and concatenated to form the vendor string.
217 for(const auto prop : properties) {
218 bs.append(store_be(get_tpm_property(m_impl->m_ctx, prop)));
219 }
220
221 BOTAN_ASSERT_NOMSG(bs.remaining_capacity() == 1); // the ensured zero-termination
222 return std::string(cast_uint8_ptr_to_char(vendor_string.data()));
223}

References Botan::BufferStuffer::append(), BOTAN_ASSERT_NOMSG, Botan::cast_uint8_ptr_to_char(), Botan::BufferStuffer::remaining_capacity(), and Botan::store_be().


The documentation for this class was generated from the following files: