Botan 3.0.0
Crypto and TLS for C&
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
24namespace Botan {
25
26class RandomNumberGenerator;
27class EME;
28class KDF;
29class EMSA;
30
31namespace 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 */
81 virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len) = 0;
82
83 /**
84 * Return the hash function being used by this signer
85 */
86 virtual std::string hash_function() const = 0;
87
88 virtual ~Verification() = default;
89 };
90
91/**
92* Public key signature creation interface
93*/
95 {
96 public:
97 /**
98 * Add more data to the message currently being signed
99 * @param msg the message
100 * @param msg_len the length of msg in bytes
101 */
102 virtual void update(const uint8_t msg[], size_t msg_len) = 0;
103
104 /**
105 * Perform a signature operation
106 * @param rng a random number generator
107 */
109
110 /**
111 * Return an upper bound on the length of the output signature
112 */
113 virtual size_t signature_length() const = 0;
114
115 /**
116 * Return an algorithm identifier associated with this signature scheme.
117 *
118 * Default implementation throws an exception
119 */
121
122 /**
123 * Return the hash function being used by this signer
124 */
125 virtual std::string hash_function() const = 0;
126
127 virtual ~Signature() = default;
128 };
129
130/**
131* A generic key agreement operation (eg DH or ECDH)
132*/
134 {
135 public:
136 virtual secure_vector<uint8_t> agree(size_t key_len,
137 const uint8_t other_key[], size_t other_key_len,
138 const uint8_t salt[], size_t salt_len) = 0;
139
140 virtual size_t agreed_value_size() const = 0;
141
142 virtual ~Key_Agreement() = default;
143 };
144
145/**
146* KEM (key encapsulation)
147*/
149 {
150 public:
151 virtual void kem_encrypt(secure_vector<uint8_t>& out_encapsulated_key,
152 secure_vector<uint8_t>& out_shared_key,
153 size_t desired_shared_key_len,
155 const uint8_t salt[],
156 size_t salt_len) = 0;
157
158 virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0;
159
160 virtual size_t encapsulated_key_length() const = 0;
161
162 virtual ~KEM_Encryption() = default;
163 };
164
166 {
167 public:
168 virtual secure_vector<uint8_t> kem_decrypt(const uint8_t encap_key[],
169 size_t len,
170 size_t desired_shared_key_len,
171 const uint8_t salt[],
172 size_t salt_len) = 0;
173
174 virtual size_t shared_key_length(size_t desired_shared_key_len) const = 0;
175
176 virtual ~KEM_Decryption() = default;
177 };
178
179}
180
181}
182
183#endif
virtual secure_vector< uint8_t > decrypt(uint8_t &valid_mask, const uint8_t ciphertext[], size_t ciphertext_len)=0
virtual ~Decryption()=default
virtual size_t plaintext_length(size_t ctext_len) const =0
virtual size_t ciphertext_length(size_t ptext_len) const =0
virtual ~Encryption()=default
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 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
virtual size_t shared_key_length(size_t desired_shared_key_len) const =0
virtual size_t encapsulated_key_length() const =0
virtual ~KEM_Encryption()=default
virtual size_t shared_key_length(size_t desired_shared_key_len) const =0
virtual void kem_encrypt(secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, size_t desired_shared_key_len, RandomNumberGenerator &rng, const uint8_t salt[], size_t salt_len)=0
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
virtual AlgorithmIdentifier algorithm_identifier() const
Definition: pk_ops.cpp:23
virtual size_t signature_length() const =0
virtual ~Signature()=default
virtual std::string hash_function() const =0
virtual secure_vector< uint8_t > sign(RandomNumberGenerator &rng)=0
virtual void update(const uint8_t msg[], size_t msg_len)=0
virtual void update(const uint8_t msg[], size_t msg_len)=0
virtual std::string hash_function() const =0
virtual bool is_valid_signature(const uint8_t sig[], size_t sig_len)=0
virtual ~Verification()=default
Definition: alg_id.cpp:12
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64