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
|
/*************************************************
* Public Key Interface Header File *
* (C) 1999-2007 Jack Lloyd *
*************************************************/
#ifndef BOTAN_PUBKEY_H__
#define BOTAN_PUBKEY_H__
#include <botan/base.h>
#include <botan/pk_keys.h>
#include <botan/pk_util.h>
namespace Botan {
enum Signature_Format { IEEE_1363, DER_SEQUENCE };
/*************************************************
* Public Key Encryptor *
*************************************************/
class BOTAN_DLL PK_Encryptor
{
public:
SecureVector<byte> encrypt(const byte[], u32bit) const;
SecureVector<byte> encrypt(const MemoryRegion<byte>&) const;
virtual u32bit maximum_input_size() const = 0;
virtual ~PK_Encryptor() {}
private:
virtual SecureVector<byte> enc(const byte[], u32bit) const = 0;
};
/*************************************************
* Public Key Decryptor *
*************************************************/
class BOTAN_DLL PK_Decryptor
{
public:
SecureVector<byte> decrypt(const byte[], u32bit) const;
SecureVector<byte> decrypt(const MemoryRegion<byte>&) const;
virtual ~PK_Decryptor() {}
private:
virtual SecureVector<byte> dec(const byte[], u32bit) const = 0;
};
/*************************************************
* Public Key Signer *
*************************************************/
class BOTAN_DLL PK_Signer
{
public:
SecureVector<byte> sign_message(const byte[], u32bit);
SecureVector<byte> sign_message(const MemoryRegion<byte>&);
void update(byte);
void update(const byte[], u32bit);
void update(const MemoryRegion<byte>&);
SecureVector<byte> signature();
void set_output_format(Signature_Format);
PK_Signer(const PK_Signing_Key&, const std::string&);
~PK_Signer() { delete emsa; }
private:
const PK_Signing_Key& key;
Signature_Format sig_format;
EMSA* emsa;
};
/*************************************************
* Public Key Verifier *
*************************************************/
class BOTAN_DLL PK_Verifier
{
public:
bool verify_message(const byte[], u32bit, const byte[], u32bit);
bool verify_message(const MemoryRegion<byte>&,
const MemoryRegion<byte>&);
void update(byte);
void update(const byte[], u32bit);
void update(const MemoryRegion<byte>&);
bool check_signature(const byte[], u32bit);
bool check_signature(const MemoryRegion<byte>&);
void set_input_format(Signature_Format);
PK_Verifier(const std::string&);
virtual ~PK_Verifier();
protected:
virtual bool validate_signature(const MemoryRegion<byte>&,
const byte[], u32bit) = 0;
virtual u32bit key_message_parts() const = 0;
virtual u32bit key_message_part_size() const = 0;
Signature_Format sig_format;
EMSA* emsa;
};
/*************************************************
* Key Agreement *
*************************************************/
class BOTAN_DLL PK_Key_Agreement
{
public:
SymmetricKey derive_key(u32bit, const byte[], u32bit,
const std::string& = "") const;
SymmetricKey derive_key(u32bit, const byte[], u32bit,
const byte[], u32bit) const;
PK_Key_Agreement(const PK_Key_Agreement_Key&, const std::string&);
private:
const PK_Key_Agreement_Key& key;
const std::string kdf_name;
};
/*************************************************
* Encryption with an MR algorithm and an EME *
*************************************************/
class BOTAN_DLL PK_Encryptor_MR_with_EME : public PK_Encryptor
{
public:
u32bit maximum_input_size() const;
PK_Encryptor_MR_with_EME(const PK_Encrypting_Key&, const std::string&);
~PK_Encryptor_MR_with_EME() { delete encoder; }
private:
SecureVector<byte> enc(const byte[], u32bit) const;
const PK_Encrypting_Key& key;
const EME* encoder;
};
/*************************************************
* Decryption with an MR algorithm and an EME *
*************************************************/
class BOTAN_DLL PK_Decryptor_MR_with_EME : public PK_Decryptor
{
public:
PK_Decryptor_MR_with_EME(const PK_Decrypting_Key&, const std::string&);
~PK_Decryptor_MR_with_EME() { delete encoder; }
private:
SecureVector<byte> dec(const byte[], u32bit) const;
const PK_Decrypting_Key& key;
const EME* encoder;
};
/*************************************************
* Public Key Verifier with Message Recovery *
*************************************************/
class BOTAN_DLL PK_Verifier_with_MR : public PK_Verifier
{
public:
PK_Verifier_with_MR(const PK_Verifying_with_MR_Key&, const std::string&);
private:
bool validate_signature(const MemoryRegion<byte>&, const byte[], u32bit);
u32bit key_message_parts() const { return key.message_parts(); }
u32bit key_message_part_size() const { return key.message_part_size(); }
const PK_Verifying_with_MR_Key& key;
};
/*************************************************
* Public Key Verifier without Message Recovery *
*************************************************/
class BOTAN_DLL PK_Verifier_wo_MR : public PK_Verifier
{
public:
PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key&, const std::string&);
private:
bool validate_signature(const MemoryRegion<byte>&, const byte[], u32bit);
u32bit key_message_parts() const { return key.message_parts(); }
u32bit key_message_part_size() const { return key.message_part_size(); }
const PK_Verifying_wo_MR_Key& key;
};
}
#endif
|