Botan  1.11.10
xts.h
Go to the documentation of this file.
1 /*
2 * XTS mode, from IEEE P1619
3 * (C) 2009,2013 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_MODE_XTS_H__
9 #define BOTAN_MODE_XTS_H__
10 
11 #include <botan/cipher_mode.h>
12 #include <botan/block_cipher.h>
13 
14 namespace Botan {
15 
16 /**
17 * IEEE P1619 XTS Mode
18 */
19 class BOTAN_DLL XTS_Mode : public Cipher_Mode
20  {
21  public:
22  std::string name() const override;
23 
24  secure_vector<byte> start(const byte nonce[], size_t nonce_len) override;
25 
26  size_t update_granularity() const override;
27 
28  size_t minimum_final_size() const override;
29 
30  Key_Length_Specification key_spec() const override;
31 
32  size_t default_nonce_length() const override;
33 
34  bool valid_nonce_length(size_t n) const override;
35 
36  void clear() override;
37  protected:
38  XTS_Mode(BlockCipher* cipher);
39 
40  const byte* tweak() const { return &m_tweak[0]; }
41 
42  const BlockCipher& cipher() const { return *m_cipher; }
43 
44  void update_tweak(size_t last_used);
45 
46  private:
47  void key_schedule(const byte key[], size_t length) override;
48 
49  std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher;
50  secure_vector<byte> m_tweak;
51  };
52 
53 /**
54 * IEEE P1619 XTS Encryption
55 */
56 class BOTAN_DLL XTS_Encryption : public XTS_Mode
57  {
58  public:
59  XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
60 
61  void update(secure_vector<byte>& blocks, size_t offset = 0) override;
62 
63  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
64 
65  size_t output_length(size_t input_length) const override;
66  };
67 
68 /**
69 * IEEE P1619 XTS Decryption
70 */
71 class BOTAN_DLL XTS_Decryption : public XTS_Mode
72  {
73  public:
74  XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
75 
76  void update(secure_vector<byte>& blocks, size_t offset = 0) override;
77 
78  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
79 
80  size_t output_length(size_t input_length) const override;
81  };
82 
83 }
84 
85 #endif
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:59
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:92
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:74
uint8_t byte
Definition: types.h:30
const BlockCipher & cipher() const
Definition: xts.h:42
const byte * tweak() const
Definition: xts.h:40
hash update(io.send(*this))