10#include <botan/assert.h>
11#include <botan/internal/ffi_rng.h>
12#include <botan/internal/ffi_util.h>
14#if defined(BOTAN_HAS_TPM2)
15 #include <botan/tpm2_context.h>
16 #include <botan/tpm2_rng.h>
17 #include <botan/tpm2_session.h>
19 #if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
20 #include <botan/tpm2_crypto_backend.h>
28#if defined(BOTAN_HAS_TPM2)
33 #if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
54#if defined(BOTAN_HAS_TPM2)
62#if defined(BOTAN_HAS_TPM2)
64 if(ctx_out ==
nullptr) {
79#if defined(BOTAN_HAS_TPM2)
81 if(ctx_out ==
nullptr) {
85 auto tcti_name_str = [=]() -> std::optional<std::string> {
86 if(tcti_name ==
nullptr) {
89 return std::string(tcti_name);
93 auto tcti_conf_str = [=]() -> std::optional<std::string> {
94 if(tcti_conf ==
nullptr) {
97 return std::string(tcti_conf);
111#if defined(BOTAN_HAS_TPM2)
127#if defined(BOTAN_HAS_TPM2)
141#if defined(BOTAN_HAS_TPM2)
150 ESYS_CONTEXT* esys_ctx,
152#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
167#if defined(BOTAN_HAS_TPM2_CRYPTO_BACKEND)
180#if defined(BOTAN_HAS_TPM2)
181 return BOTAN_FFI_VISIT(ctx, [=](
const std::shared_ptr<Botan::TPM2::Context>& tpm2_ctx) ->
int {
182 if(rng_out ==
nullptr) {
187 std::make_unique<Botan::TPM2::RandomNumberGenerator>(tpm2_ctx, sessions(s1, s2, s3)));
196#if defined(BOTAN_HAS_TPM2)
197 return BOTAN_FFI_VISIT(ctx, [=](
const std::shared_ptr<Botan::TPM2::Context>& tpm2_ctx) ->
int {
198 if(session_out ==
nullptr) {
211#if defined(BOTAN_HAS_TPM2)
static bool supports_botan_crypto_backend() noexcept
static std::shared_ptr< Context > create(const std::string &tcti_nameconf)
static std::shared_ptr< Session > unauthenticated_session(const std::shared_ptr< Context > &ctx, std::string_view sym_algo="CFB(AES-256)", std::string_view hash_algo="SHA-256")
struct botan_tpm2_session_struct * botan_tpm2_session_t
struct botan_tpm2_ctx_struct * botan_tpm2_ctx_t
struct botan_rng_struct * botan_rng_t
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_ERROR_NULL_POINTER
struct botan_tpm2_crypto_backend_state_struct * botan_tpm2_crypto_backend_state_t
int botan_tpm2_ctx_enable_crypto_backend(botan_tpm2_ctx_t ctx, botan_rng_t rng)
int botan_tpm2_ctx_init_ex(botan_tpm2_ctx_t *ctx_out, const char *tcti_name, const char *tcti_conf)
int botan_tpm2_ctx_init(botan_tpm2_ctx_t *ctx_out, const char *tcti_nameconf)
int botan_tpm2_rng_init(botan_rng_t *rng_out, botan_tpm2_ctx_t ctx, botan_tpm2_session_t s1, botan_tpm2_session_t s2, botan_tpm2_session_t s3)
int botan_tpm2_ctx_from_esys(botan_tpm2_ctx_t *ctx_out, ESYS_CONTEXT *esys_ctx)
int botan_tpm2_ctx_destroy(botan_tpm2_ctx_t ctx)
int botan_tpm2_unauthenticated_session_init(botan_tpm2_session_t *session_out, botan_tpm2_ctx_t ctx)
int botan_tpm2_crypto_backend_state_destroy(botan_tpm2_crypto_backend_state_t cbs)
int botan_tpm2_session_destroy(botan_tpm2_session_t session)
int botan_tpm2_enable_crypto_backend(botan_tpm2_crypto_backend_state_t *cbs_out, ESYS_CONTEXT *esys_ctx, botan_rng_t rng)
int botan_tpm2_supports_crypto_backend()
#define BOTAN_FFI_VISIT(obj, lambda)
#define BOTAN_FFI_DECLARE_SHARED_STRUCT(NAME, TYPE, MAGIC)
#define BOTAN_FFI_CHECKED_DELETE(o)
#define BOTAN_FFI_DECLARE_UNIQUE_STRUCT(NAME, TYPE, MAGIC)
std::unique_ptr< CryptoCallbackState > use_botan_crypto_backend(ESYS_CONTEXT *context, const std::shared_ptr< Botan::RandomNumberGenerator > &rng)
auto safe_get_sp(T *p) -> const typename T::smart_pointer_type &
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
int ffi_guard_thunk(const char *func_name, T thunk)
bool any_null_pointers(Ptrs... ptr)