Botan  1.10.9
xts.h
Go to the documentation of this file.
1 /*
2 * XTS mode, from IEEE P1619
3 * (C) 2009 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_XTS_H__
9 #define BOTAN_XTS_H__
10 
11 #include <botan/block_cipher.h>
12 #include <botan/key_filt.h>
13 #include <botan/buf_filt.h>
14 
15 namespace Botan {
16 
17 /**
18 * IEEE P1619 XTS Encryption
19 */
20 class BOTAN_DLL XTS_Encryption : public Keyed_Filter,
21  private Buffered_Filter
22  {
23  public:
24  void set_key(const SymmetricKey& key);
25  void set_iv(const InitializationVector& iv);
26 
27  bool valid_keylength(size_t key_len) const
28  { return cipher->valid_keylength(key_len); }
29 
30  bool valid_iv_length(size_t iv_len) const
31  { return (iv_len == cipher->block_size()); }
32 
33  std::string name() const;
34 
36 
38  const SymmetricKey& key,
39  const InitializationVector& iv);
40 
41  ~XTS_Encryption() { delete cipher; delete cipher2; }
42  private:
43  void write(const byte[], size_t);
44  void end_msg();
45 
46  void buffered_block(const byte input[], size_t input_length);
47  void buffered_final(const byte input[], size_t input_length);
48 
49  BlockCipher* cipher;
50  BlockCipher* cipher2;
51  SecureVector<byte> tweak;
52  };
53 
54 /**
55 * IEEE P1619 XTS Encryption
56 */
57 class BOTAN_DLL XTS_Decryption : public Keyed_Filter,
58  private Buffered_Filter
59  {
60  public:
61  void set_key(const SymmetricKey& key);
62  void set_iv(const InitializationVector& iv);
63 
64  bool valid_keylength(size_t key_len) const
65  { return cipher->valid_keylength(key_len); }
66 
67  bool valid_iv_length(size_t iv_len) const
68  { return (iv_len == cipher->block_size()); }
69 
70  std::string name() const;
71 
73 
75  const SymmetricKey& key,
76  const InitializationVector& iv);
77 
78  ~XTS_Decryption() { delete cipher; delete cipher2; }
79  private:
80  void write(const byte[], size_t);
81  void end_msg();
82 
83  void buffered_block(const byte input[], size_t input_length);
84  void buffered_final(const byte input[], size_t input_length);
85 
86  BlockCipher* cipher;
87  BlockCipher* cipher2;
88  SecureVector<byte> tweak;
89  };
90 
91 }
92 
93 #endif
bool valid_keylength(size_t key_len) const
Definition: xts.h:64
unsigned char byte
Definition: types.h:22
bool valid_keylength(size_t key_len) const
Definition: xts.h:27
bool valid_iv_length(size_t iv_len) const
Definition: xts.h:30
bool valid_iv_length(size_t iv_len) const
Definition: xts.h:67