• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 12370093224

17 Dec 2024 09:27AM UTC coverage: 91.262% (+0.003%) from 91.259%
12370093224

Pull #4478

github

web-flow
Merge b307ce8bd into 694344901
Pull Request #4478: Fix msvc warnings

93398 of 102340 relevant lines covered (91.26%)

11403200.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.27
/src/lib/prov/tpm2/tpm2_rsa/tpm2_rsa.h
1
/*
2
* TPM 2.0 RSA Key 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
#ifndef BOTAN_TPM2_RSA_H_
9
#define BOTAN_TPM2_RSA_H_
10

11
#include <botan/rsa.h>
12
#include <botan/tpm2_key.h>
13

14
namespace Botan::TPM2 {
15

16
BOTAN_DIAGNOSTIC_PUSH
17
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
18

19
class BOTAN_PUBLIC_API(3, 6) RSA_PublicKey final : public virtual Botan::TPM2::PublicKey,
20
                                                   public virtual Botan::RSA_PublicKey {
21
   public:
22
      std::unique_ptr<Private_Key> generate_another(Botan::RandomNumberGenerator& rng) const override {
×
23
         return TPM2::PublicKey::generate_another(rng);
×
24
      }
25

26
      std::vector<uint8_t> raw_public_key_bits() const override { return TPM2::PublicKey::raw_public_key_bits(); }
×
27

28
      bool supports_operation(PublicKeyOperation op) const override {
×
29
         // TODO: Support RSA-KEM
30
         return op == PublicKeyOperation::Encryption || op == PublicKeyOperation::Signature;
×
31
      }
32

33
      std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
34
                                                                   std::string_view provider) const override;
35

36
      std::unique_ptr<PK_Ops::Encryption> create_encryption_op(Botan::RandomNumberGenerator& rng,
37
                                                               std::string_view params,
38
                                                               std::string_view provider) const override;
39

40
   protected:
41
      friend class TPM2::PublicKey;
42

43
      RSA_PublicKey(Object handle, SessionBundle sessions, const TPM2B_PUBLIC* public_blob);
44
};
45

46
class BOTAN_PUBLIC_API(3, 6) RSA_PrivateKey final : public virtual Botan::TPM2::PrivateKey,
×
47
                                                    public virtual Botan::RSA_PublicKey {
48
   public:
49
      /**
50
       * Create a transient RSA key with the given @p keylength and @p exponent,
51
       * under the given @p parent key, with the given @p auth_value. This key
52
       * may be used for both signatures and data decryption. No restrictions
53
       * on the utilized padding schemes are applied.
54
       *
55
       * TODO: provide the user with some means to specify such restrictions:
56
       *         - allowed key use: sign, decrypt, sign+decrypt, x509sign
57
       *         - allowed padding schemes: PKCS1v1.5, OAEP, PSS
58
       *         - data restrictions ("restricted" field in TPMT_PUBLIC)
59
       *         - session authentication requirements (policy, user authentication, ...)
60
       *         - fixed to TPM, or fixed to parent?
61
       *         - ...
62
       *
63
       * @param ctx The TPM context to use
64
       * @param sessions The session bundle to use in the creation of the key
65
       * @param auth_value The auth value to use for the key
66
       * @param parent The parent key to create the new key under
67
       * @param keylength The desired key length
68
       * @param exponent The desired exponent (default: 0x10001)
69
       */
70
      static std::unique_ptr<TPM2::PrivateKey> create_unrestricted_transient(const std::shared_ptr<Context>& ctx,
71
                                                                             const SessionBundle& sessions,
72
                                                                             std::span<const uint8_t> auth_value,
73
                                                                             const TPM2::PrivateKey& parent,
74
                                                                             uint16_t keylength,
75
                                                                             std::optional<uint32_t> exponent = {});
76

77
   public:
78
      std::unique_ptr<Public_Key> public_key() const override {
6✔
79
         return std::make_unique<Botan::RSA_PublicKey>(algorithm_identifier(), public_key_bits());
18✔
80
      }
81

82
      std::vector<uint8_t> raw_public_key_bits() const override { return TPM2::PrivateKey::raw_public_key_bits(); }
2✔
83

84
      bool supports_operation(PublicKeyOperation op) const override {
×
85
         // TODO: Support RSA-KEM
86
         return op == PublicKeyOperation::Encryption || op == PublicKeyOperation::Signature;
×
87
      }
88

89
      std::unique_ptr<PK_Ops::Signature> create_signature_op(Botan::RandomNumberGenerator& rng,
90
                                                             std::string_view params,
91
                                                             std::string_view provider) const override;
92

93
      std::unique_ptr<PK_Ops::Decryption> create_decryption_op(Botan::RandomNumberGenerator& rng,
94
                                                               std::string_view params,
95
                                                               std::string_view provider) const override;
96

97
   protected:
98
      friend class TPM2::PrivateKey;
99

100
      RSA_PrivateKey(Object handle,
101
                     SessionBundle sessions,
102
                     const TPM2B_PUBLIC* public_blob,
103
                     std::span<const uint8_t> private_blob = {});
104
};
105

106
BOTAN_DIAGNOSTIC_POP
107

108
}  // namespace Botan::TPM2
109

110
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc