Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

aead.h
Go to the documentation of this file.
1 /*
2 * Interface for AEAD modes
3 * (C) 2013 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_AEAD_MODE_H__
9 #define BOTAN_AEAD_MODE_H__
10
11 #include <botan/cipher_mode.h>
12
13 namespace Botan {
14
15 /**
16 * Interface for AEAD (Authenticated Encryption with Associated Data)
17 * modes. These modes provide both encryption and message
18 * authentication, and can authenticate additional per-message data
19 * which is not included in the ciphertext (for instance a sequence
20 * number).
21 */
22 class BOTAN_DLL AEAD_Mode : public Cipher_Mode
23 {
24 public:
25 bool authenticated() const override { return true; }
26
27 /**
28 * Set associated data that is not included in the ciphertext but
29 * that should be authenticated. Must be called after set_key and
30 * before start.
31 *
32 * Unless reset by another call, the associated data is kept
33 * between messages. Thus, if the AD does not change, calling
34 * once (after set_key) is the optimum.
35 *
36 * @param ad the associated data
37 * @param ad_len length of add in bytes
38 */
39 virtual void set_associated_data(const uint8_t ad[], size_t ad_len) = 0;
40
41 /**
42 * Set associated data that is not included in the ciphertext but
43 * that should be authenticated. Must be called after set_key and
44 * before start.
45 *
46 * See @ref set_associated_data().
47 *
48 * @param ad the associated data
49 */
50 template<typename Alloc>
51 void set_associated_data_vec(const std::vector<uint8_t, Alloc>& ad)
52 {
53 set_associated_data(ad.data(), ad.size());
54 }
55
56 /**
57 * Set associated data that is not included in the ciphertext but
58 * that should be authenticated. Must be called after set_key and
59 * before start.
60 *
61 * See @ref set_associated_data().
62 *
63 * @param ad the associated data
64 */
65 template<typename Alloc>
66 void set_ad(const std::vector<uint8_t, Alloc>& ad)
67 {
68 set_associated_data(ad.data(), ad.size());
69 }
70
71 /**
72 * @return default AEAD nonce size (a commonly supported value among AEAD
73 * modes, and large enough that random collisions are unlikely)
74 */
75 size_t default_nonce_length() const override { return 12; }
76
77 virtual ~AEAD_Mode() = default;
78 };
79
80 /**
81 * Get an AEAD mode by name (eg "AES-128/GCM" or "Serpent/EAX")
82 * @param name AEAD name
83 * @param direction ENCRYPTION or DECRYPTION
84 */
85 BOTAN_DLL AEAD_Mode* get_aead(const std::string& name, Cipher_Dir direction);
86
87 }
88
89 #endif
Botan::AEAD_Mode::default_nonce_length
size_t default_nonce_length() const override
Definition: aead.h:75
Botan::AEAD_Mode::set_ad
void set_ad(const std::vector< uint8_t, Alloc > &ad)
Definition: aead.h:66
Botan::AEAD_Mode::authenticated
bool authenticated() const override
Definition: aead.h:25
Botan::AEAD_Mode::set_associated_data_vec
void set_associated_data_vec(const std::vector< uint8_t, Alloc > &ad)
Definition: aead.h:51
Botan::get_aead
AEAD_Mode * get_aead(const std::string &algo, Cipher_Dir dir)
Definition: aead.cpp:41
Botan
Definition: alg_id.cpp:13
Botan::AEAD_Mode
Definition: aead.h:22
Botan::Cipher_Mode
Definition: cipher_mode.h:23
Botan::Cipher_Dir
Cipher_Dir
Definition: cipher_mode.h:212