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
|
/*
* (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_
/**
* Ordinary applications should never need to include or use this
* header. It is exposed only for specialized applications which want
* to implement new versions of public key crypto without merging them
* as changes to the library. One actual example of such usage is an
* application which creates RSA signatures using a custom TPM library.
* Unless you're doing something like that, you don't need anything
* here. Instead use pubkey.h which wraps these types safely and
* provides a stable application-oriented API.
*/
#include <botan/pk_keys.h>
#include <botan/secmem.h>
namespace Botan {
class RandomNumberGenerator;
class EME;
class KDF;
class EMSA;
namespace PK_Ops {
/**
* Public key encryption interface
*/
class Encryption
{
public:
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 size_t ciphertext_length(size_t ptext_len) const = 0;
virtual ~Encryption() = default;
};
/**
* Public key decryption interface
*/
class Decryption
{
public:
virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask,
const uint8_t ciphertext[],
size_t ciphertext_len) = 0;
virtual size_t plaintext_length(size_t ctext_len) const = 0;
virtual ~Decryption() = default;
};
/**
* Public key signature verification interface
*/
class Verification
{
public:
/*
* 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 uint8_t msg[], size_t msg_len) = 0;
/*
* Perform a verification operation
* @param rng a random number generator
*/
virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) = 0;
virtual ~Verification() = default;
};
/**
* Public key signature creation interface
*/
class Signature
{
public:
/*
* 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 uint8_t msg[], size_t msg_len) = 0;
/*
* Perform a signature operation
* @param rng a random number generator
*/
virtual secure_vector<uint8_t> sign(RandomNumberGenerator& rng) = 0;
/*
* Return an upper bound on the length of the output signature
*/
virtual size_t signature_length() const = 0;
virtual ~Signature() = default;
};
/**
* A generic key agreement operation (eg DH or ECDH)
*/
class Key_Agreement
{
public:
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;
};
/**
* KEM (key encapsulation)
*/
class KEM_Encryption
{
public:
virtual void kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
secure_vector<uint8_t>& out_shared_key,
size_t desired_shared_key_len,
Botan::RandomNumberGenerator& rng,
const uint8_t salt[],
size_t salt_len) = 0;
virtual ~KEM_Encryption() = default;
};
class KEM_Decryption
{
public:
virtual secure_vector<uint8_t> kem_decrypt(const uint8_t encap_key[],
size_t len,
size_t desired_shared_key_len,
const uint8_t salt[],
size_t salt_len) = 0;
virtual ~KEM_Decryption() = default;
};
}
}
#endif
|