1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*
* PK Operation Types
* (C) 2010,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_PK_OPERATIONS_H__
#define BOTAN_PK_OPERATIONS_H__
#include <botan/pk_keys.h>
#include <botan/secmem.h>
#include <botan/rng.h>
namespace Botan {
class EME;
class KDF;
class EMSA;
namespace PK_Ops {
template<typename Key>
class PK_Spec
{
public:
PK_Spec(const Key& key, const std::string& pad) :
m_key(key), m_pad(pad) {}
std::string algo_name() const { return m_key.algo_name(); }
std::string as_string() const { return algo_name() + "/" + padding(); }
const Key& key() const { return m_key; }
const std::string& padding() const { return m_pad; }
private:
const Key& m_key;
const std::string m_pad;
};
typedef PK_Spec<Public_Key> PK_Spec_Public_Key;
typedef PK_Spec<Private_Key> PK_Spec_Private_Key;
/**
* Public key encryption interface
*/
class BOTAN_DLL Encryption
{
public:
typedef PK_Spec_Public_Key Spec;
virtual size_t max_input_bits() const = 0;
virtual secure_vector<byte> encrypt(const byte msg[],
size_t msg_len,
RandomNumberGenerator& rng) = 0;
virtual ~Encryption() {}
};
/**
* Public key decryption interface
*/
class BOTAN_DLL Decryption
{
public:
typedef PK_Spec_Private_Key Spec;
virtual size_t max_input_bits() const = 0;
virtual secure_vector<byte> decrypt(const byte msg[], size_t msg_len) = 0;
virtual ~Decryption() {}
};
/**
* Public key signature verification interface
*/
class BOTAN_DLL Verification
{
public:
typedef PK_Spec_Public_Key Spec;
/*
* Add more data to the message currently being signed
* @param msg the message
* @param msg_len the length of msg in bytes
*/
virtual void update(const byte msg[], size_t msg_len) = 0;
/*
* Perform a signature operation
* @param rng a random number generator
*/
virtual bool is_valid_signature(const byte sig[], size_t sig_len) = 0;
/**
* Get the maximum message size in bits supported by this public key.
* @return maximum message in bits
*/
virtual size_t max_input_bits() const = 0;
/**
* Find out the number of message parts supported by this scheme.
* @return number of message parts
*/
virtual size_t message_parts() const { return 1; }
/**
* Find out the message part size supported by this scheme/key.
* @return size of the message parts
*/
virtual size_t message_part_size() const { return 0; }
virtual ~Verification() {}
};
/**
* Public key signature creation interface
*/
class BOTAN_DLL Signature
{
public:
typedef PK_Spec_Private_Key Spec;
/**
* Find out the number of message parts supported by this scheme.
* @return number of message parts
*/
virtual size_t message_parts() const { return 1; }
/**
* Find out the message part size supported by this scheme/key.
* @return size of the message parts
*/
virtual size_t message_part_size() const { return 0; }
/*
* Add more data to the message currently being signed
* @param msg the message
* @param msg_len the length of msg in bytes
*/
virtual void update(const byte msg[], size_t msg_len) = 0;
/*
* Perform a signature operation
* @param rng a random number generator
*/
virtual secure_vector<byte> sign(RandomNumberGenerator& rng) = 0;
virtual ~Signature() {}
};
/**
* A generic key agreement operation (eg DH or ECDH)
*/
class BOTAN_DLL Key_Agreement
{
public:
typedef PK_Spec_Private_Key Spec;
virtual secure_vector<byte> agree(size_t key_len,
const byte other_key[], size_t other_key_len,
const byte salt[], size_t salt_len) = 0;
virtual ~Key_Agreement() {}
};
/**
* KEM (key encapsulation)
*/
class BOTAN_DLL KEM_Encryption
{
public:
typedef PK_Spec_Public_Key Spec;
virtual void kem_encrypt(secure_vector<byte>& out_encapsulated_key,
secure_vector<byte>& out_shared_key,
size_t desired_shared_key_len,
Botan::RandomNumberGenerator& rng,
const uint8_t salt[],
size_t salt_len) = 0;
virtual ~KEM_Encryption() {}
};
class BOTAN_DLL KEM_Decryption
{
public:
typedef PK_Spec_Private_Key Spec;
virtual secure_vector<byte> kem_decrypt(const byte encap_key[],
size_t len,
size_t desired_shared_key_len,
const uint8_t salt[],
size_t salt_len) = 0;
virtual ~KEM_Decryption() {}
};
}
}
#endif
|