Botan  2.13.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 
16 
17 namespace Botan {
18 
19 /**
20 * IEEE P1619 XTS Mode
21 */
23  {
24  public:
25  std::string name() const override;
26 
27  size_t update_granularity() const override { return m_cipher_parallelism; }
28 
29  size_t minimum_final_size() const override;
30 
31  Key_Length_Specification key_spec() const override;
32 
33  size_t default_nonce_length() const override;
34 
35  bool valid_nonce_length(size_t n) const override;
36 
37  void clear() override;
38 
39  void reset() override;
40 
41  protected:
42  explicit XTS_Mode(BlockCipher* cipher);
43 
44  const uint8_t* tweak() const { return m_tweak.data(); }
45 
46  bool tweak_set() const { return m_tweak.empty() == false; }
47 
48  const BlockCipher& cipher() const { return *m_cipher; }
49 
50  void update_tweak(size_t last_used);
51 
52  size_t cipher_block_size() const { return m_cipher_block_size; }
53 
54  private:
55  void start_msg(const uint8_t nonce[], size_t nonce_len) override;
56  void key_schedule(const uint8_t key[], size_t length) override;
57 
58  std::unique_ptr<BlockCipher> m_cipher;
59  std::unique_ptr<BlockCipher> m_tweak_cipher;
60  secure_vector<uint8_t> m_tweak;
61  const size_t m_cipher_block_size;
62  const size_t m_cipher_parallelism;
63  };
64 
65 /**
66 * IEEE P1619 XTS Encryption
67 */
69  {
70  public:
71  /**
72  * @param cipher underlying block cipher
73  */
74  explicit XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
75 
76  size_t process(uint8_t buf[], size_t size) override;
77 
78  void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
79 
80  size_t output_length(size_t input_length) const override;
81  };
82 
83 /**
84 * IEEE P1619 XTS Decryption
85 */
87  {
88  public:
89  /**
90  * @param cipher underlying block cipher
91  */
92  explicit XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
93 
94  size_t process(uint8_t buf[], size_t size) override;
95 
96  void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
97 
98  size_t output_length(size_t input_length) const override;
99  };
100 
101 }
102 
103 #endif
size_t cipher_block_size() const
Definition: xts.h:52
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:74
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
const BlockCipher & cipher() const
Definition: xts.h:48
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0
const uint8_t * tweak() const
Definition: xts.h:44
virtual void reset()=0
virtual size_t minimum_final_size() const =0
virtual size_t default_nonce_length() const =0
virtual size_t output_length(size_t input_length) const =0
virtual std::string name() const =0
virtual void clear()=0
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:92
Definition: alg_id.cpp:13
virtual Key_Length_Specification key_spec() const =0
virtual size_t process(uint8_t msg[], size_t msg_len)=0
bool tweak_set() const
Definition: xts.h:46
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
size_t update_granularity() const override
Definition: xts.h:27
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
virtual bool valid_nonce_length(size_t nonce_len) const =0
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0