Botan 3.13.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 size_t security_level() const override;
39 void clear() override;
40
41 /// @throws Not_Implemented as copying state is not supported within the TPM
42 std::unique_ptr<Botan::HashFunction> copy_state() const override;
43 std::unique_ptr<Botan::HashFunction> new_object() const override;
44
45 /// @return The hash algorithm identifier as TSS2's TPMI_ALG_HASH
46 TPMI_ALG_HASH type() const { return m_hash_type; }
47
48 /**
49 * Finalize the hash operation and return the digest and the ticket
50 * as TSS2 structures.
51 *
52 * @return A pair of TPM2B_DIGEST and TPMT_TK_HASHCHECK
53 */
54 std::pair<unique_esys_ptr<TPM2B_DIGEST>, unique_esys_ptr<TPMT_TK_HASHCHECK>> final_with_ticket();
55
56 private:
57 void lazy_setup();
58 void add_data(std::span<const uint8_t> input) override;
59 void final_result(std::span<uint8_t> output) override;
60
61 private:
62 TPMI_ALG_HASH m_hash_type;
63 TPMI_RH_HIERARCHY m_hierarchy;
64 Object m_handle;
65 SessionBundle m_sessions;
66};
67
68} // namespace Botan::TPM2
69
70#endif
#define BOTAN_TEST_API
Definition api.h:41
void final(uint8_t out[])
Definition buf_comp.h:97
void clear() override
Definition tpm2_hash.cpp:66
size_t security_level() const override
Definition tpm2_hash.cpp:56
size_t output_length() const override
Definition tpm2_hash.cpp:37
std::string name() const override
Definition tpm2_hash.cpp:33
HashFunction(std::shared_ptr< Context > ctx, std::string_view algorithm, TPMI_RH_HIERARCHY hierarchy=ESYS_TR_RH_NULL, SessionBundle sessions={})
Definition tpm2_hash.cpp:20
std::unique_ptr< Botan::HashFunction > new_object() const override
Definition tpm2_hash.cpp:74
std::unique_ptr< Botan::HashFunction > copy_state() const override
Definition tpm2_hash.cpp:70
TPMI_ALG_HASH type() const
Definition tpm2_hash.h:46
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:163