/src/Botan-3.4.0/build/include/public/botan/pk_ops.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
29 | | namespace Botan { |
30 | | |
31 | | class RandomNumberGenerator; |
32 | | class EME; |
33 | | class KDF; |
34 | | class EMSA; |
35 | | |
36 | | namespace PK_Ops { |
37 | | |
38 | | /** |
39 | | * Public key encryption interface |
40 | | */ |
41 | | class BOTAN_UNSTABLE_API Encryption { |
42 | | public: |
43 | | virtual secure_vector<uint8_t> encrypt(const uint8_t msg[], size_t msg_len, RandomNumberGenerator& rng) = 0; |
44 | | |
45 | | virtual size_t max_input_bits() const = 0; |
46 | | |
47 | | virtual size_t ciphertext_length(size_t ptext_len) const = 0; |
48 | | |
49 | 0 | virtual ~Encryption() = default; |
50 | | }; |
51 | | |
52 | | /** |
53 | | * Public key decryption interface |
54 | | */ |
55 | | class BOTAN_UNSTABLE_API Decryption { |
56 | | public: |
57 | | virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask, |
58 | | const uint8_t ciphertext[], |
59 | | size_t ciphertext_len) = 0; |
60 | | |
61 | | virtual size_t plaintext_length(size_t ctext_len) const = 0; |
62 | | |
63 | 0 | virtual ~Decryption() = default; |
64 | | }; |
65 | | |
66 | | /** |
67 | | * Public key signature verification interface |
68 | | */ |
69 | | class BOTAN_UNSTABLE_API Verification { |
70 | | public: |
71 | | /** |
72 | | * Add more data to the message currently being signed |
73 | | * @param msg the message |
74 | | * @param msg_len the length of msg in bytes |
75 | | */ |
76 | | virtual void update(const uint8_t msg[], size_t msg_len) = 0; |
77 | | |
78 | | /** |
79 | | * Perform a verification operation |
80 | | */ |
81 | | virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) = 0; |
82 | | |
83 | | /** |
84 | | * Return the hash function being used by this signer |
85 | | */ |
86 | | virtual std::string hash_function() const = 0; |
87 | | |
88 | 190k | virtual ~Verification() = default; |
89 | | }; |
90 | | |
91 | | /** |
92 | | * Public key signature creation interface |
93 | | */ |
94 | | class BOTAN_UNSTABLE_API Signature { |
95 | | public: |
96 | | /** |
97 | | * Add more data to the message currently being signed |
98 | | * @param msg the message |
99 | | * @param msg_len the length of msg in bytes |
100 | | */ |
101 | | virtual void update(const uint8_t msg[], size_t msg_len) = 0; |
102 | | |
103 | | /** |
104 | | * Perform a signature operation |
105 | | * @param rng a random number generator |
106 | | */ |
107 | | virtual secure_vector<uint8_t> sign(RandomNumberGenerator& rng) = 0; |
108 | | |
109 | | /** |
110 | | * Return an upper bound on the length of the output signature |
111 | | */ |
112 | | virtual size_t signature_length() const = 0; |
113 | | |
114 | | /** |
115 | | * Return an algorithm identifier associated with this signature scheme. |
116 | | * |
117 | | * Default implementation throws an exception |
118 | | */ |
119 | | virtual AlgorithmIdentifier algorithm_identifier() const; |
120 | | |
121 | | /** |
122 | | * Return the hash function being used by this signer |
123 | | */ |
124 | | virtual std::string hash_function() const = 0; |
125 | | |
126 | 0 | virtual ~Signature() = default; |
127 | | }; |
128 | | |
129 | | /** |
130 | | * A generic key agreement operation (eg DH or ECDH) |
131 | | */ |
132 | | class BOTAN_UNSTABLE_API Key_Agreement { |
133 | | public: |
134 | | virtual secure_vector<uint8_t> agree( |
135 | | size_t key_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len) = 0; |
136 | | |
137 | | virtual size_t agreed_value_size() const = 0; |
138 | | |
139 | 0 | virtual ~Key_Agreement() = default; |
140 | | }; |
141 | | |
142 | | /** |
143 | | * KEM (key encapsulation) |
144 | | */ |
145 | | class BOTAN_UNSTABLE_API KEM_Encryption { |
146 | | public: |
147 | | virtual void kem_encrypt(std::span<uint8_t> out_encapsulated_key, |
148 | | std::span<uint8_t> out_shared_key, |
149 | | RandomNumberGenerator& rng, |
150 | | size_t desired_shared_key_len, |
151 | | std::span<const uint8_t> salt) = 0; |
152 | | |
153 | | virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0; |
154 | | |
155 | | virtual size_t encapsulated_key_length() const = 0; |
156 | | |
157 | 0 | virtual ~KEM_Encryption() = default; |
158 | | }; |
159 | | |
160 | | class BOTAN_UNSTABLE_API KEM_Decryption { |
161 | | public: |
162 | | virtual void kem_decrypt(std::span<uint8_t> out_shared_key, |
163 | | std::span<const uint8_t> encapsulated_key, |
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_Decryption() = default; |
172 | | }; |
173 | | |
174 | | } // namespace PK_Ops |
175 | | |
176 | | } // namespace Botan |
177 | | |
178 | | #endif |