Botan 3.6.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::HashFunctionhash ()
 
const Objectkey_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 SessionBundlesessions () 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 45 of file tpm2_pkops.cpp.

47 :
49 object, sessions, algorithms, create_hash_function(object, sessions, algorithms.hash_name)) {}

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 24 of file pk_ops.cpp.

24 {
25 throw Not_Implemented("This signature scheme does not have an algorithm identifier available");
26}

◆ hash()

Definition at line 46 of file tpm2_pkops.h.

46{ return m_hash.get(); }

Referenced by sign().

◆ 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 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 sign().

◆ sessions()

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

Definition at line 50 of file tpm2_pkops.h.

50{ return m_sessions; }

Referenced by sign().

◆ sign()

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

Perform a signature operation

Parameters
rnga random number generator

Implements Botan::PK_Ops::Signature.

Definition at line 51 of file tpm2_pkops.cpp.

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

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.

◆ 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); }

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