Botan 3.6.0
Crypto and TLS for C&
tpm2_hash.h
Go to the documentation of this file.
1/*
2* TPM 2.0 Hash Function Wrappers
3* (C) 2024 Jack Lloyd
4* (C) 2024 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity GmbH, financed by LANCOM Systems GmbH
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_TPM2_HASH_H_
10#define BOTAN_TPM2_HASH_H_
11
12#include <botan/hash.h>
13#include <botan/tpm2_context.h>
14#include <botan/tpm2_object.h>
15#include <botan/tpm2_session.h>
16
17#include <botan/internal/tpm2_util.h>
18
19#include <tss2/tss2_tpm2_types.h>
20
21namespace Botan::TPM2 {
22
23/**
24 * Exposes the hashing capability of a TPM 2.0 device as a Botan::HashFunction.
25 * Typically this is used to obtain a TPMT_TK_HASHCHECK ticket after the hash
26 * operation has been completed. Otherwise, the HashFunction behaves like any
27 * other Botan::HashFunction.
28 */
30 public:
31 HashFunction(std::shared_ptr<Context> ctx,
32 std::string_view algorithm,
33 TPMI_RH_HIERARCHY hierarchy = ESYS_TR_RH_NULL,
34 SessionBundle sessions = {});
35
36 std::string name() const override;
37 size_t output_length() const override;
38 void clear() override;
39
40 /// @throws Not_Implemented as copying state is not supported within the TPM
41 std::unique_ptr<Botan::HashFunction> copy_state() const override;
42 std::unique_ptr<Botan::HashFunction> new_object() const override;
43
44 /// @return The hash algorithm identifier as TSS2's TPMI_ALG_HASH
45 TPMI_ALG_HASH type() const { return m_hash_type; }
46
47 /**
48 * Finalize the hash operation and return the digest and the ticket
49 * as TSS2 structures.
50 *
51 * @return A pair of TPM2B_DIGEST and TPMT_TK_HASHCHECK
52 */
53 std::pair<unique_esys_ptr<TPM2B_DIGEST>, unique_esys_ptr<TPMT_TK_HASHCHECK>> final_with_ticket();
54
55 private:
56 void lazy_setup();
57 void add_data(std::span<const uint8_t> input) override;
58 void final_result(std::span<uint8_t> output) override;
59
60 private:
61 TPMI_ALG_HASH m_hash_type;
62 TPMI_RH_HIERARCHY m_hierarchy;
63 Object m_handle;
64 SessionBundle m_sessions;
65};
66
67} // namespace Botan::TPM2
68
69#endif
TPMI_ALG_HASH type() const
Definition tpm2_hash.h:45
std::string name
int(* final)(unsigned char *, CTX *)
#define BOTAN_TEST_API
Definition compiler.h:51
std::unique_ptr< T, esys_liberator > unique_esys_ptr
A unique pointer type for ESYS handles that automatically frees the handle.
Definition tpm2_util.h:154