Botan 3.3.0
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
29namespace Botan {
30
31class RandomNumberGenerator;
32class EME;
33class KDF;
34class EMSA;
35
36namespace PK_Ops {
37
38/**
39* Public key encryption interface
40*/
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 virtual ~Encryption() = default;
50};
51
52/**
53* Public key decryption interface
54*/
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 virtual ~Decryption() = default;
64};
65
66/**
67* Public key signature verification interface
68*/
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 virtual ~Verification() = default;
89};
90
91/**
92* Public key signature creation interface
93*/
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 */
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 virtual ~Signature() = default;
127};
128
129/**
130* A generic key agreement operation (eg DH or ECDH)
131*/
133 public:
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 virtual ~Key_Agreement() = default;
140};
141
142/**
143* KEM (key encapsulation)
144*/
146 public:
147 virtual void kem_encrypt(std::span<uint8_t> out_encapsulated_key,
148 std::span<uint8_t> out_shared_key,
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 virtual ~KEM_Encryption() = default;
158};
159
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 virtual ~KEM_Decryption() = default;
172};
173
174} // namespace PK_Ops
175
176} // namespace Botan
177
178#endif
virtual secure_vector< uint8_t > decrypt(uint8_t &valid_mask, const uint8_t ciphertext[], size_t ciphertext_len)=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 ~Encryption()=default
virtual secure_vector< uint8_t > encrypt(const uint8_t msg[], size_t msg_len, RandomNumberGenerator &rng)=0
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 secure_vector< uint8_t > agree(size_t key_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)=0
virtual size_t agreed_value_size() const =0
virtual ~Key_Agreement()=default
virtual size_t signature_length() const =0
virtual ~Signature()=default
virtual std::string hash_function() const =0
virtual secure_vector< uint8_t > sign(RandomNumberGenerator &rng)=0
virtual void update(const uint8_t msg[], size_t msg_len)=0
virtual void update(const uint8_t msg[], size_t msg_len)=0
virtual std::string hash_function() const =0
virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len)=0
virtual ~Verification()=default
#define BOTAN_UNSTABLE_API
Definition compiler.h:44
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61