Botan  1.11.34
Crypto and TLS for C++11
xts.h
Go to the documentation of this file.
1 /*
2 * XTS mode, from IEEE P1619
3 * (C) 2009,2013 Jack Lloyd
4 * (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_MODE_XTS_H__
10 #define BOTAN_MODE_XTS_H__
11 
12 #include <botan/cipher_mode.h>
13 #include <botan/block_cipher.h>
14 
15 namespace Botan {
16 
17 /**
18 * IEEE P1619 XTS Mode
19 */
20 class BOTAN_DLL XTS_Mode : public Cipher_Mode
21  {
22  public:
23  std::string name() const override;
24 
25  size_t update_granularity() const override;
26 
27  size_t minimum_final_size() const override;
28 
29  Key_Length_Specification key_spec() const override;
30 
31  size_t default_nonce_length() const override;
32 
33  bool valid_nonce_length(size_t n) const override;
34 
35  void clear() override;
36 
37  void reset() override;
38 
39  protected:
40  explicit XTS_Mode(BlockCipher* cipher);
41 
42  const byte* tweak() const { return m_tweak.data(); }
43 
44  const BlockCipher& cipher() const { return *m_cipher; }
45 
46  void update_tweak(size_t last_used);
47 
48  private:
49  void start_msg(const byte nonce[], size_t nonce_len) override;
50  void key_schedule(const byte key[], size_t length) override;
51 
52  std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher;
53  secure_vector<byte> m_tweak;
54  };
55 
56 /**
57 * IEEE P1619 XTS Encryption
58 */
59 class BOTAN_DLL XTS_Encryption final : public XTS_Mode
60  {
61  public:
62  /**
63  * @param cipher underlying block cipher
64  */
65  explicit XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
66 
67  size_t process(uint8_t buf[], size_t size) override;
68 
69  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
70 
71  size_t output_length(size_t input_length) const override;
72  };
73 
74 /**
75 * IEEE P1619 XTS Decryption
76 */
77 class BOTAN_DLL XTS_Decryption final : public XTS_Mode
78  {
79  public:
80  /**
81  * @param cipher underlying block cipher
82  */
83  explicit XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
84 
85  size_t process(uint8_t buf[], size_t size) override;
86 
87  void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
88 
89  size_t output_length(size_t input_length) const override;
90  };
91 
92 }
93 
94 #endif
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:65
const BlockCipher & cipher() const
Definition: xts.h:44
const byte * tweak() const
Definition: xts.h:42
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:113
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:83
Definition: alg_id.cpp:13
std::uint8_t byte
Definition: types.h:31