Botan 3.6.1
Crypto and TLS for C&
pk_ops.h
Go to the documentation of this file.
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
30namespace Botan {
31
32class RandomNumberGenerator;
33class EME;
34class KDF;
35class EMSA;
36
37} // namespace Botan
38
39namespace Botan::PK_Ops {
40
41/**
42* Public key encryption interface
43*/
45 public:
46 /**
47 * Encrypt a message returning the ciphertext
48 */
49 virtual std::vector<uint8_t> encrypt(std::span<const uint8_t> msg, RandomNumberGenerator& rng) = 0;
50
51 /**
52 * Return the maximum input size for this key
53 */
54 virtual size_t max_input_bits() const = 0;
55
56 /**
57 * Given the plaintext length, return an upper bound of the ciphertext
58 * length for this key and padding.
59 */
60 virtual size_t ciphertext_length(size_t ptext_len) const = 0;
61
62 virtual ~Encryption() = default;
63};
64
65/**
66* Public key decryption interface
67*/
69 public:
70 virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask, std::span<const uint8_t> ctext) = 0;
71
72 virtual size_t plaintext_length(size_t ctext_len) const = 0;
73
74 virtual ~Decryption() = default;
75};
76
77/**
78* Public key signature verification interface
79*/
81 public:
82 /**
83 * Add more data to the message currently being signed
84 * @param input the input to be hashed/verified
85 */
86 virtual void update(std::span<const uint8_t> input) = 0;
87
88 /**
89 * Perform a verification operation
90 * @param sig the signature to be checked with respect to the input
91 */
92 virtual bool is_valid_signature(std::span<const uint8_t> sig) = 0;
93
94 /**
95 * Return the hash function being used by this signer
96 */
97 virtual std::string hash_function() const = 0;
98
99 virtual ~Verification() = default;
100};
101
102/**
103* Public key signature creation interface
104*/
106 public:
107 /**
108 * Add more data to the message currently being signed
109 * @param input the input to be hashed/signed
110 */
111 virtual void update(std::span<const uint8_t> input) = 0;
112
113 /**
114 * Perform a signature operation
115 * @param rng a random number generator
116 */
117 virtual std::vector<uint8_t> sign(RandomNumberGenerator& rng) = 0;
118
119 /**
120 * Return an upper bound on the length of the output signature
121 */
122 virtual size_t signature_length() const = 0;
123
124 /**
125 * Return an algorithm identifier associated with this signature scheme.
126 *
127 * Default implementation throws an exception
128 */
129 virtual AlgorithmIdentifier algorithm_identifier() const;
130
131 /**
132 * Return the hash function being used by this signer
133 */
134 virtual std::string hash_function() const = 0;
135
136 virtual ~Signature() = default;
137};
138
139/**
140* A generic key agreement operation (eg DH or ECDH)
141*/
143 public:
144 virtual secure_vector<uint8_t> agree(size_t key_len,
145 std::span<const uint8_t> other_key,
146 std::span<const uint8_t> salt) = 0;
147
148 virtual size_t agreed_value_size() const = 0;
149
150 virtual ~Key_Agreement() = default;
151};
152
153/**
154* KEM (key encapsulation)
155*/
157 public:
158 virtual void kem_encrypt(std::span<uint8_t> out_encapsulated_key,
159 std::span<uint8_t> out_shared_key,
161 size_t desired_shared_key_len,
162 std::span<const uint8_t> salt) = 0;
163
164 virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0;
165
166 virtual size_t encapsulated_key_length() const = 0;
167
168 virtual ~KEM_Encryption() = default;
169};
170
172 public:
173 virtual void kem_decrypt(std::span<uint8_t> out_shared_key,
174 std::span<const uint8_t> encapsulated_key,
175 size_t desired_shared_key_len,
176 std::span<const uint8_t> salt) = 0;
177
178 virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0;
179
180 virtual size_t encapsulated_key_length() const = 0;
181
182 virtual ~KEM_Decryption() = default;
183};
184
185} // namespace Botan::PK_Ops
186
187#endif
virtual secure_vector< uint8_t > decrypt(uint8_t &valid_mask, std::span< const uint8_t > ctext)=0
virtual ~Decryption()=default
virtual size_t plaintext_length(size_t ctext_len) const =0
virtual size_t ciphertext_length(size_t ptext_len) const =0
virtual std::vector< uint8_t > encrypt(std::span< const uint8_t > msg, RandomNumberGenerator &rng)=0
virtual ~Encryption()=default
virtual size_t max_input_bits() const =0
virtual void kem_decrypt(std::span< uint8_t > out_shared_key, std::span< const uint8_t > encapsulated_key, size_t desired_shared_key_len, std::span< const uint8_t > salt)=0
virtual ~KEM_Decryption()=default
virtual size_t encapsulated_key_length() const =0
virtual size_t shared_key_length(size_t desired_shared_key_len) const =0
virtual size_t encapsulated_key_length() const =0
virtual ~KEM_Encryption()=default
virtual void kem_encrypt(std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len, std::span< const uint8_t > salt)=0
virtual size_t shared_key_length(size_t desired_shared_key_len) const =0
virtual size_t agreed_value_size() const =0
virtual secure_vector< uint8_t > agree(size_t key_len, std::span< const uint8_t > other_key, std::span< const uint8_t > salt)=0
virtual ~Key_Agreement()=default
virtual size_t signature_length() const =0
virtual ~Signature()=default
virtual std::string hash_function() const =0
virtual void update(std::span< const uint8_t > input)=0
virtual std::vector< uint8_t > sign(RandomNumberGenerator &rng)=0
virtual std::string hash_function() const =0
virtual void update(std::span< const uint8_t > input)=0
virtual ~Verification()=default
virtual bool is_valid_signature(std::span< const uint8_t > sig)=0
#define BOTAN_UNSTABLE_API
Definition compiler.h:44
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61