Botan  2.4.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 ~Encryption() = default;
46  };
47 
48 /**
49 * Public key decryption interface
50 */
52  {
53  public:
54  virtual secure_vector<uint8_t> decrypt(uint8_t& valid_mask,
55  const uint8_t ciphertext[],
56  size_t ciphertext_len) = 0;
57 
58  virtual ~Decryption() = default;
59  };
60 
61 /**
62 * Public key signature verification interface
63 */
65  {
66  public:
67  /*
68  * Add more data to the message currently being signed
69  * @param msg the message
70  * @param msg_len the length of msg in bytes
71  */
72  virtual void update(const uint8_t msg[], size_t msg_len) = 0;
73 
74  /*
75  * Perform a verification operation
76  * @param rng a random number generator
77  */
78  virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) = 0;
79 
80  virtual ~Verification() = default;
81  };
82 
83 /**
84 * Public key signature creation interface
85 */
87  {
88  public:
89  /*
90  * Add more data to the message currently being signed
91  * @param msg the message
92  * @param msg_len the length of msg in bytes
93  */
94  virtual void update(const uint8_t msg[], size_t msg_len) = 0;
95 
96  /*
97  * Perform a signature operation
98  * @param rng a random number generator
99  */
100  virtual secure_vector<uint8_t> sign(RandomNumberGenerator& rng) = 0;
101 
102  virtual ~Signature() = default;
103  };
104 
105 /**
106 * A generic key agreement operation (eg DH or ECDH)
107 */
109  {
110  public:
111  virtual secure_vector<uint8_t> agree(size_t key_len,
112  const uint8_t other_key[], size_t other_key_len,
113  const uint8_t salt[], size_t salt_len) = 0;
114 
115  virtual ~Key_Agreement() = default;
116  };
117 
118 /**
119 * KEM (key encapsulation)
120 */
122  {
123  public:
124  virtual void kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
125  secure_vector<uint8_t>& out_shared_key,
126  size_t desired_shared_key_len,
128  const uint8_t salt[],
129  size_t salt_len) = 0;
130 
131  virtual ~KEM_Encryption() = default;
132  };
133 
135  {
136  public:
137  virtual secure_vector<uint8_t> kem_decrypt(const uint8_t encap_key[],
138  size_t len,
139  size_t desired_shared_key_len,
140  const uint8_t salt[],
141  size_t salt_len) = 0;
142 
143  virtual ~KEM_Decryption() = default;
144  };
145 
146 }
147 
148 }
149 
150 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
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:25
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
std::string encrypt(const uint8_t input[], size_t input_len, const std::string &passphrase, RandomNumberGenerator &rng)
Definition: cryptobox.cpp:43