Botan  2.8.0
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 */
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 uint8_t* tweak() const { return m_tweak.data(); }
43 
44  bool tweak_set() const { return m_tweak.empty() == false; }
45 
46  const BlockCipher& cipher() const { return *m_cipher; }
47 
48  void update_tweak(size_t last_used);
49 
50  private:
51  void start_msg(const uint8_t nonce[], size_t nonce_len) override;
52  void key_schedule(const uint8_t key[], size_t length) override;
53 
54  std::unique_ptr<BlockCipher> m_cipher, m_tweak_cipher;
55  secure_vector<uint8_t> m_tweak;
56  };
57 
58 /**
59 * IEEE P1619 XTS Encryption
60 */
62  {
63  public:
64  /**
65  * @param cipher underlying block cipher
66  */
67  explicit XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
68 
69  size_t process(uint8_t buf[], size_t size) override;
70 
71  void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
72 
73  size_t output_length(size_t input_length) const override;
74  };
75 
76 /**
77 * IEEE P1619 XTS Decryption
78 */
80  {
81  public:
82  /**
83  * @param cipher underlying block cipher
84  */
85  explicit XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
86 
87  size_t process(uint8_t buf[], size_t size) override;
88 
89  void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
90 
91  size_t output_length(size_t input_length) const override;
92  };
93 
94 }
95 
96 #endif
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:67
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
const BlockCipher & cipher() const
Definition: xts.h:46
const uint8_t * tweak() const
Definition: xts.h:42
std::string name
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:85
Definition: alg_id.cpp:13
bool tweak_set() const
Definition: xts.h:44
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88