Botan 3.14.1
Crypto and TLS for C&
Botan::TPM2::Signature_Operation Class Referenceabstract

#include <tpm2_pkops.h>

Inheritance diagram for Botan::TPM2::Signature_Operation:
Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature > Botan::PK_Ops::Signature

Public Member Functions

virtual AlgorithmIdentifier algorithm_identifier () const
std::string hash_function () const override
std::vector< uint8_t > sign (Botan::RandomNumberGenerator &rng) override
virtual size_t signature_length () const =0
 Signature_Operation (const Object &object, const SessionBundle &sessions, const SignatureAlgorithmSelection &algorithms)
void update (std::span< const uint8_t > msg) override

Protected Member Functions

Botan::HashFunction * hash ()
const Object & key_handle () const
virtual std::vector< uint8_t > marshal_signature (const TPMT_SIGNATURE &signature) const =0
std::optional< std::string > padding () const
const TPMT_SIG_SCHEME & scheme () const
const SessionBundle & sessions () const

Detailed Description

If the key is restricted, this will transparently use the TPM to hash the data to obtain a validation ticket.

TPM Library, Part 1: Architecture", Section 11.4.6.3 (4) This ticket is used to indicate that a digest of external data is safe to sign using a restricted signing key. A restricted signing key may only sign a digest that was produced by the TPM. [...] This prevents forgeries of attestation data.

Definition at line 74 of file tpm2_pkops.h.

Constructor & Destructor Documentation

◆ Signature_Operation()

Botan::TPM2::Signature_Operation::Signature_Operation ( const Object & object,
const SessionBundle & sessions,
const SignatureAlgorithmSelection & algorithms )

Definition at line 44 of file tpm2_pkops.cpp.

46 :
47 Botan::TPM2::Signature_Operation_Base<PK_Ops::Signature>(
48 object, sessions, algorithms, create_hash_function(object, sessions, algorithms.hash_name)) {}

References Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::sessions(), and Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::Signature_Operation_Base().

Member Function Documentation

◆ algorithm_identifier()

AlgorithmIdentifier Botan::PK_Ops::Signature::algorithm_identifier ( ) const
virtualinherited

Return an algorithm identifier associated with this signature scheme.

Default implementation throws an exception

Reimplemented in Botan::XMSS_Signature_Operation.

Definition at line 30 of file pk_ops.cpp.

30 {
31 throw Not_Implemented("This signature scheme does not have an algorithm identifier available");
32}

Referenced by signature_length().

◆ hash()

◆ hash_function()

std::string Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::hash_function ( ) const
inlineoverridevirtualinherited

Implements Botan::PK_Ops::Signature.

Definition at line 43 of file tpm2_pkops.h.

43{ return m_hash->name(); }

◆ key_handle()

const Object & Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::key_handle ( ) const
inlineprotectedinherited

Definition at line 48 of file tpm2_pkops.h.

48{ return m_key_handle; }

Referenced by Botan::TPM2::Signature_Operation::sign().

◆ marshal_signature()

virtual std::vector< uint8_t > Botan::TPM2::Signature_Operation::marshal_signature ( const TPMT_SIGNATURE & signature) const
protectedpure virtual

Referenced by sign().

◆ padding()

std::optional< std::string > Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::padding ( ) const
inlineprotectedinherited

Definition at line 54 of file tpm2_pkops.h.

54{ return m_padding; }

◆ scheme()

const TPMT_SIG_SCHEME & Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::scheme ( ) const
inlineprotectedinherited

Definition at line 52 of file tpm2_pkops.h.

52{ return m_scheme; }

Referenced by Botan::TPM2::Signature_Operation::sign().

◆ sessions()

const SessionBundle & Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::sessions ( ) const
inlineprotectedinherited

◆ sign()

std::vector< uint8_t > Botan::TPM2::Signature_Operation::sign ( Botan::RandomNumberGenerator & rng)
overridevirtual

Perform a signature operation

Parameters
Random Number Generatorsa random number generator

Implements Botan::PK_Ops::Signature.

Definition at line 50 of file tpm2_pkops.cpp.

50 {
51 BOTAN_UNUSED(rng);
52
53 auto do_sign = [this](const TPM2B_DIGEST& digest, const TPMT_TK_HASHCHECK& validation) {
55 check_rc("Esys_Sign",
56 Esys_Sign(key_handle().context()->esys_context(),
57 key_handle().transient_handle(),
58 sessions()[0],
59 sessions()[1],
60 sessions()[2],
61 &digest,
62 &scheme(),
63 &validation,
64 out_ptr(signature)));
65 BOTAN_ASSERT_NONNULL(signature);
66 BOTAN_ASSERT_NOMSG(signature->sigAlg == scheme().scheme);
67 BOTAN_ASSERT_NOMSG(signature->signature.any.hashAlg == scheme().details.any.hashAlg);
68 return signature;
69 };
70
71 const auto signature = [&] {
72 if(auto* h = dynamic_cast<HashFunction*>(hash())) {
73 // This is a TPM2-based hash object that calculated the digest on
74 // the TPM. We can use the validation ticket to create the signature.
75 auto [digest, validation] = h->final_with_ticket();
77 BOTAN_ASSERT_NONNULL(validation);
78 return do_sign(*digest, *validation);
79 } else {
80 // This is a software hash, so we have to stub the validation ticket
81 // and create the signature without it.
82 TPM2B_DIGEST digest;
83 hash()->final(as_span(digest, hash()->output_length()));
84 return do_sign(digest,
85 TPMT_TK_HASHCHECK{
86 .tag = TPM2_ST_HASHCHECK,
87 .hierarchy = TPM2_RH_NULL,
88 .digest = init_empty<TPM2B_DIGEST>(),
89 });
90 }
91 }();
92
93 return marshal_signature(*signature);
94}
#define BOTAN_UNUSED
Definition assert.h:151
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:121
void final(uint8_t out[])
Definition buf_comp.h:97
virtual std::vector< uint8_t > marshal_signature(const TPMT_SIGNATURE &signature) const =0
constexpr T init_empty()
Create an empty TPM2 buffer of the given type.
Definition tpm2_util.h:151
constexpr void check_rc(std::string_view location, TSS2_RC rc)
Definition tpm2_util.h:53
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:161
constexpr auto as_span(tpm2_buffer auto &data)
Construct a std::span as a view into a TPM2 buffer.
Definition tpm2_util.h:101
constexpr auto out_ptr(T &outptr) noexcept
Definition stl_util.h:164

References Botan::TPM2::as_span(), BOTAN_ASSERT_NOMSG, BOTAN_ASSERT_NONNULL, BOTAN_UNUSED, Botan::TPM2::check_rc(), Botan::Buffered_Computation::final(), Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::hash(), Botan::TPM2::init_empty(), Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::key_handle(), marshal_signature(), Botan::out_ptr(), Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::scheme(), and Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::sessions().

◆ signature_length()

virtual size_t Botan::PK_Ops::Signature::signature_length ( ) const
pure virtualinherited

Return an upper bound on the length of the output signature

Implemented in Botan::XMSS_Signature_Operation.

References algorithm_identifier().

◆ update()

void Botan::TPM2::Signature_Operation_Base< PK_Ops::Signature >::update ( std::span< const uint8_t > input)
inlineoverridevirtualinherited

Implements Botan::PK_Ops::Signature.

Definition at line 41 of file tpm2_pkops.h.

41{ m_hash->update(msg); }
void update(std::span< const uint8_t > msg) override
Definition tpm2_pkops.h:41

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