/src/Botan-3.13.0/build/include/public/botan/pk_ops.h
Line | Count | Source |
1 | | /* |
2 | | * (C) 2010,2015 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #ifndef BOTAN_PK_OPERATIONS_H_ |
8 | | #define BOTAN_PK_OPERATIONS_H_ |
9 | | |
10 | | /** |
11 | | * Ordinary applications should never need to include or use this |
12 | | * header. It is exposed only for specialized applications which want |
13 | | * to implement new versions of public key crypto without merging them |
14 | | * as changes to the library. One actual example of such usage is an |
15 | | * application which creates RSA signatures using a custom TPM library. |
16 | | * Unless you're doing something like that, you don't need anything |
17 | | * here. Instead use pubkey.h which wraps these types safely and |
18 | | * provides a stable application-oriented API. |
19 | | * |
20 | | * Note: This header was accidentally pulled from the public API between |
21 | | * Botan 3.0.0 and 3.2.0, and then restored in 3.3.0. If you are |
22 | | * maintaining an application which used this header in Botan 2.x, |
23 | | * you should make sure to use Botan 3.3.0 or later when migrating. |
24 | | */ |
25 | | |
26 | | #include <botan/pk_keys.h> |
27 | | #include <botan/secmem.h> |
28 | | #include <span> |
29 | | |
30 | | namespace Botan { |
31 | | |
32 | | class RandomNumberGenerator; |
33 | | |
34 | | } // namespace Botan |
35 | | |
36 | | namespace Botan::PK_Ops { |
37 | | |
38 | | /** |
39 | | * Public key encryption interface |
40 | | */ |
41 | | class BOTAN_UNSTABLE_API Encryption /* NOLINT(*special-member-functions) */ { |
42 | | public: |
43 | | /** |
44 | | * Encrypt a message returning the ciphertext |
45 | | */ |
46 | | virtual std::vector<uint8_t> encrypt(std::span<const uint8_t> msg, RandomNumberGenerator& rng) = 0; |
47 | | |
48 | | /** |
49 | | * Return the maximum input size for this key |
50 | | */ |
51 | | virtual size_t max_input_bits() const = 0; |
52 | | |
53 | | /** |
54 | | * Given the plaintext length, return an upper bound of the ciphertext |
55 | | * length for this key and padding. |
56 | | */ |
57 | | virtual size_t ciphertext_length(size_t ptext_len) const = 0; |
58 | | |
59 | 41 | virtual ~Encryption() = default; |
60 | | }; |
61 | | |
62 | | /** |
63 | | * Public key decryption interface |
64 | | */ |
65 | | class BOTAN_UNSTABLE_API Decryption /* NOLINT(*special-member-functions) */ { |
66 | | public: |
67 | | virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask, std::span<const uint8_t> ctext) = 0; |
68 | | |
69 | | virtual size_t plaintext_length(size_t ctext_len) const = 0; |
70 | | |
71 | | /** |
72 | | * Given the plaintext length, return an upper bound on the ciphertext |
73 | | * length that decrypt() expects for this key and padding. |
74 | | */ |
75 | | virtual size_t ciphertext_length(size_t ptext_len) const = 0; |
76 | | |
77 | 0 | virtual ~Decryption() = default; |
78 | | }; |
79 | | |
80 | | /** |
81 | | * Public key signature verification interface |
82 | | */ |
83 | | class BOTAN_UNSTABLE_API Verification /* NOLINT(*special-member-functions) */ { |
84 | | public: |
85 | | /** |
86 | | * Add more data to the message currently being signed |
87 | | * @param input the input to be hashed/verified |
88 | | */ |
89 | | virtual void update(std::span<const uint8_t> input) = 0; |
90 | | |
91 | | /** |
92 | | * Perform a verification operation |
93 | | * @param sig the signature to be checked with respect to the input |
94 | | */ |
95 | | virtual bool is_valid_signature(std::span<const uint8_t> sig) = 0; |
96 | | |
97 | | /** |
98 | | * Return the hash function being used by this signer |
99 | | */ |
100 | | virtual std::string hash_function() const = 0; |
101 | | |
102 | 287k | virtual ~Verification() = default; |
103 | | }; |
104 | | |
105 | | /** |
106 | | * Public key signature creation interface |
107 | | */ |
108 | | class BOTAN_UNSTABLE_API Signature /* NOLINT(*special-member-functions) */ { |
109 | | public: |
110 | | /** |
111 | | * Add more data to the message currently being signed |
112 | | * @param input the input to be hashed/signed |
113 | | */ |
114 | | virtual void update(std::span<const uint8_t> input) = 0; |
115 | | |
116 | | /** |
117 | | * Perform a signature operation |
118 | | * @param rng a random number generator |
119 | | */ |
120 | | virtual std::vector<uint8_t> sign(RandomNumberGenerator& rng) = 0; |
121 | | |
122 | | /** |
123 | | * Return an upper bound on the length of the output signature |
124 | | */ |
125 | | virtual size_t signature_length() const = 0; |
126 | | |
127 | | /** |
128 | | * Return an algorithm identifier associated with this signature scheme. |
129 | | * |
130 | | * Default implementation throws an exception |
131 | | */ |
132 | | virtual AlgorithmIdentifier algorithm_identifier() const; |
133 | | |
134 | | /** |
135 | | * Return the hash function being used by this signer |
136 | | */ |
137 | | virtual std::string hash_function() const = 0; |
138 | | |
139 | 0 | virtual ~Signature() = default; |
140 | | }; |
141 | | |
142 | | /** |
143 | | * A generic key agreement operation (eg DH or ECDH) |
144 | | */ |
145 | | class BOTAN_UNSTABLE_API Key_Agreement /* NOLINT(*special-member-functions) */ { |
146 | | public: |
147 | | virtual secure_vector<uint8_t> agree(size_t key_len, |
148 | | std::span<const uint8_t> other_key, |
149 | | std::span<const uint8_t> salt) = 0; |
150 | | |
151 | | virtual size_t agreed_value_size() const = 0; |
152 | | |
153 | 0 | virtual ~Key_Agreement() = default; |
154 | | }; |
155 | | |
156 | | /** |
157 | | * KEM (key encapsulation) |
158 | | */ |
159 | | class BOTAN_UNSTABLE_API KEM_Encryption /* NOLINT(*special-member-functions) */ { |
160 | | public: |
161 | | virtual void kem_encrypt(std::span<uint8_t> out_encapsulated_key, |
162 | | std::span<uint8_t> out_shared_key, |
163 | | RandomNumberGenerator& rng, |
164 | | size_t desired_shared_key_len, |
165 | | std::span<const uint8_t> salt) = 0; |
166 | | |
167 | | virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0; |
168 | | |
169 | | virtual size_t encapsulated_key_length() const = 0; |
170 | | |
171 | 0 | virtual ~KEM_Encryption() = default; |
172 | | }; |
173 | | |
174 | | class BOTAN_UNSTABLE_API KEM_Decryption /* NOLINT(*special-member-functions) */ { |
175 | | public: |
176 | | virtual void kem_decrypt(std::span<uint8_t> out_shared_key, |
177 | | std::span<const uint8_t> encapsulated_key, |
178 | | size_t desired_shared_key_len, |
179 | | std::span<const uint8_t> salt) = 0; |
180 | | |
181 | | virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0; |
182 | | |
183 | | virtual size_t encapsulated_key_length() const = 0; |
184 | | |
185 | 0 | virtual ~KEM_Decryption() = default; |
186 | | }; |
187 | | |
188 | | } // namespace Botan::PK_Ops |
189 | | |
190 | | #endif |