aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/modes/aead/aead.cpp
blob: c101480b4a80ad76db81a698c911a785be69c66a (plain)
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
/*
* (C) 2013,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include <botan/internal/mode_utils.h>
#include <botan/aead.h>

#if defined(BOTAN_HAS_AEAD_CCM)
#include <botan/ccm.h>
#endif

#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
#include <botan/chacha20poly1305.h>
#endif

#if defined(BOTAN_HAS_AEAD_EAX)
#include <botan/eax.h>
#endif

#if defined(BOTAN_HAS_AEAD_GCM)
#include <botan/gcm.h>
#endif

#if defined(BOTAN_HAS_AEAD_OCB)
#include <botan/ocb.h>
#endif

#if defined(BOTAN_HAS_AEAD_SIV)
#include <botan/siv.h>
#endif

namespace Botan {

AEAD_Mode::~AEAD_Mode() {}

#if defined(BOTAN_HAS_AEAD_CCM)
BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN2(CCM_Encryption, CCM_Decryption, 16, 3);
#endif

#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Encryption);
BOTAN_REGISTER_TRANSFORM_NOARGS(ChaCha20Poly1305_Decryption);
#endif

#if defined(BOTAN_HAS_AEAD_EAX)
BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(EAX_Encryption, EAX_Decryption, 0);
#endif

#if defined(BOTAN_HAS_AEAD_GCM)
BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(GCM_Encryption, GCM_Decryption, 16);
#endif

#if defined(BOTAN_HAS_AEAD_OCB)
BOTAN_REGISTER_BLOCK_CIPHER_MODE_LEN(OCB_Encryption, OCB_Decryption, 16);
#endif

#if defined(BOTAN_HAS_AEAD_SIV)
BOTAN_REGISTER_BLOCK_CIPHER_MODE(SIV_Encryption, SIV_Decryption);
#endif

AEAD_Mode* get_aead(const std::string& algo_spec, Cipher_Dir direction)
   {
   std::unique_ptr<Cipher_Mode> mode(get_cipher_mode(algo_spec, direction));

   if(AEAD_Mode* aead = dynamic_cast<AEAD_Mode*>(mode.get()))
      {
      mode.release();
      return aead;
      }

   return nullptr;
   }

}