aboutsummaryrefslogtreecommitdiffstats
path: root/src/modes/eax/eax.h
blob: 67507f776d06bb508bc39a77dec3b5a5a41a52cf (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
77
78
79
80
81
82
83
/*************************************************
* EAX Mode Header File                           *
* (C) 1999-2007 Jack Lloyd                       *
*************************************************/

#ifndef BOTAN_EAX_H__
#define BOTAN_EAX_H__

#include <botan/basefilt.h>
#include <botan/block_cipher.h>
#include <botan/mac.h>

namespace Botan {

/*************************************************
* EAX Base Class                                 *
*************************************************/
class BOTAN_DLL EAX_Base : public Keyed_Filter
   {
   public:
      void set_key(const SymmetricKey&);
      void set_iv(const InitializationVector&);
      void set_header(const byte[], u32bit);
      std::string name() const;

      bool valid_keylength(u32bit) const;

      ~EAX_Base() { delete cipher; delete mac; }
   protected:
      EAX_Base(BlockCipher*, u32bit);
      void start_msg();
      void increment_counter();

      const u32bit TAG_SIZE, BLOCK_SIZE;
      BlockCipher* cipher;
      MessageAuthenticationCode* mac;
      SecureVector<byte> nonce_mac, header_mac, state, buffer;
      u32bit position;
   };

/*************************************************
* EAX Encryption                                 *
*************************************************/
class BOTAN_DLL EAX_Encryption : public EAX_Base
   {
   public:
      EAX_Encryption(BlockCipher* ciph, u32bit tag_size = 0) :
         EAX_Base(ciph, tag_size) {}

      EAX_Encryption(BlockCipher* ciph, const SymmetricKey& key,
                     const InitializationVector& iv,
                     u32bit tag_size) : EAX_Base(ciph, tag_size)
         {
         set_key(key);
         set_iv(iv);
         }
   private:
      void write(const byte[], u32bit);
      void end_msg();
   };

/*************************************************
* EAX Decryption                                 *
*************************************************/
class BOTAN_DLL EAX_Decryption : public EAX_Base
   {
   public:
      EAX_Decryption(BlockCipher* ciph, u32bit tag_size = 0);

      EAX_Decryption(BlockCipher* ciph, const SymmetricKey& key,
                     const InitializationVector& iv,
                     u32bit tag_size = 0);
   private:
      void write(const byte[], u32bit);
      void do_write(const byte[], u32bit);
      void end_msg();
      SecureVector<byte> queue;
      u32bit queue_start, queue_end;
   };

}

#endif