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  size_t update_granularity() const override;
25 
26  size_t minimum_final_size() const override;
27 
28  Key_Length_Specification key_spec() const override;
29 
30  size_t default_nonce_length() const override;
31 
32  bool valid_nonce_length(size_t n) const override;
33 
34  void clear() override;
35  protected:
36  XTS_Mode(BlockCipher* cipher);
37 
38  const byte* tweak() const { return &m_tweak[0]; }
39 
40  const BlockCipher& cipher() const { return *m_cipher; }
41 
42  void update_tweak(size_t last_used);
43 
44  private:
45  secure_vector<byte> start_raw(const byte nonce[], size_t nonce_len) override;
46  void key_schedule(const byte key[], size_t length) override;
47 
48  std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher;
49  secure_vector<byte> m_tweak;
50  };
51 
52 /**
53 * IEEE P1619 XTS Encryption
54 */
55 class BOTAN_DLL XTS_Encryption : public XTS_Mode
56  {
57  public:
58  XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
59 
60  void update(secure_vector<byte>& blocks, size_t offset = 0) override;
61 
62  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
63 
64  size_t output_length(size_t input_length) const override;
65  };
66 
67 /**
68 * IEEE P1619 XTS Decryption
69 */
70 class BOTAN_DLL XTS_Decryption : public XTS_Mode
71  {
72  public:
73  XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
74 
75  void update(secure_vector<byte>& blocks, size_t offset = 0) override;
76 
77  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
78 
79  size_t output_length(size_t input_length) const override;
80  };
81 
82 }
83 
84 #endif
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:58
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:92
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:73
uint8_t byte
Definition: types.h:30
Definition: buf_comp.h:15
const BlockCipher & cipher() const
Definition: xts.h:40
const byte * tweak() const
Definition: xts.h:38