Botan  2.10.0
Crypto and TLS for C++11
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 
21 #include <botan/pk_keys.h>
22 #include <botan/secmem.h>
23 
24 namespace Botan {
25 
26 class RandomNumberGenerator;
27 class EME;
28 class KDF;
29 class EMSA;
30 
31 namespace PK_Ops {
32 
33 /**
34 * Public key encryption interface
35 */
37  {
38  public:
39  virtual secure_vector<uint8_t> encrypt(const uint8_t msg[],
40  size_t msg_len,
41  RandomNumberGenerator& rng) = 0;
42 
43  virtual size_t max_input_bits() const = 0;
44 
45  virtual size_t ciphertext_length(size_t ptext_len) const = 0;
46 
47  virtual ~Encryption() = default;
48  };
49 
50 /**
51 * Public key decryption interface
52 */
54  {
55  public:
56  virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask,
57  const uint8_t ciphertext[],
58  size_t ciphertext_len) = 0;
59 
60  virtual size_t plaintext_length(size_t ctext_len) const = 0;
61 
62  virtual ~Decryption() = default;
63  };
64 
65 /**
66 * Public key signature verification interface
67 */
69  {
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  * @param rng a random number generator
81  */
82  virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) = 0;
83 
84  virtual ~Verification() = default;
85  };
86 
87 /**
88 * Public key signature creation interface
89 */
91  {
92  public:
93  /*
94  * Add more data to the message currently being signed
95  * @param msg the message
96  * @param msg_len the length of msg in bytes
97  */
98  virtual void update(const uint8_t msg[], size_t msg_len) = 0;
99 
100  /*
101  * Perform a signature operation
102  * @param rng a random number generator
103  */
104  virtual secure_vector<uint8_t> sign(RandomNumberGenerator& rng) = 0;
105 
106  /*
107  * Return an upper bound on the length of the output signature
108  */
109  virtual size_t signature_length() const = 0;
110 
111  virtual ~Signature() = default;
112  };
113 
114 /**
115 * A generic key agreement operation (eg DH or ECDH)
116 */
118  {
119  public:
120  virtual secure_vector<uint8_t> agree(size_t key_len,
121  const uint8_t other_key[], size_t other_key_len,
122  const uint8_t salt[], size_t salt_len) = 0;
123 
124  virtual size_t agreed_value_size() const = 0;
125 
126  virtual ~Key_Agreement() = default;
127  };
128 
129 /**
130 * KEM (key encapsulation)
131 */
133  {
134  public:
135  virtual void kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
136  secure_vector<uint8_t>& out_shared_key,
137  size_t desired_shared_key_len,
139  const uint8_t salt[],
140  size_t salt_len) = 0;
141 
142  virtual ~KEM_Encryption() = default;
143  };
144 
146  {
147  public:
148  virtual secure_vector<uint8_t> kem_decrypt(const uint8_t encap_key[],
149  size_t len,
150  size_t desired_shared_key_len,
151  const uint8_t salt[],
152  size_t salt_len) = 0;
153 
154  virtual ~KEM_Decryption() = default;
155  };
156 
157 }
158 
159 }
160 
161 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
std::string decrypt(const uint8_t input[], size_t input_len, const std::string &passphrase)
Definition: cryptobox.cpp:162
size_t salt_len
Definition: x509_obj.cpp:26
Definition: alg_id.cpp:13
int(* update)(CTX *, const void *, CC_LONG len)
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
std::string encrypt(const uint8_t input[], size_t input_len, const std::string &passphrase, RandomNumberGenerator &rng)
Definition: cryptobox.cpp:43