Botan  2.11.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 */
20 class BOTAN_PUBLIC_API(2,0) 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 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 */
61 class BOTAN_PUBLIC_API(2,0) XTS_Encryption final : public XTS_Mode
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 */
79 class BOTAN_PUBLIC_API(2,0) XTS_Decryption final : public XTS_Mode
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
BigInt size_t n
Definition: bigint.h:1096
bool BigInt BigInt size_t size_t const std::vector< uint8_t > size_t offset
Definition: numthry.h:271
size_t const uint8_t size_t input_length
Definition: base32.h:30
const uint8_t size_t nonce_len
Definition: ffi.h:504
const uint8_t * buf
Definition: ffi.h:371
size_t * output_length
Definition: ffi.h:280
int(* final)(unsigned char *, CTX *)
char * name
Definition: ffi.h:330
BigInt const BigInt const SymmetricKey const std::vector< uint8_t > & tweak
Definition: fpe_fe1.h:101
void BlockCipher * cipher
Definition: package.h:29
class BOTAN_PUBLIC_API(2, 11) Argon2 final class BOTAN_PUBLIC_API(2, 11) Argon2_Family final void size_t const char size_t const uint8_t size_t const uint8_t key[]
Definition: argon2.h:87
Definition: alg_id.cpp:13
class BOTAN_PUBLIC_API(2, 0) AlgorithmIdentifier final bool BOTAN_PUBLIC_API(2, 0) operator
Name Constraints.
Definition: asn1_obj.h:66
const uint8_t * nonce
Definition: ffi.h:504