Botan: src/filters/modes/xts/xts.h Source File

Botan 1.10.17

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
35 XTS_Encryption(BlockCipher* ciph);
36
37 XTS_Encryption(BlockCipher* ciph,
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
72 XTS_Decryption(BlockCipher* ciph);
73
74 XTS_Decryption(BlockCipher* ciph,
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
Botan::Buffered_Filter
Definition: buf_filt.h:19
Botan::OctetString
Definition: symkey.h:19
Botan::Keyed_Filter
Definition: key_filt.h:20
Botan::XTS_Encryption
Definition: xts.h:20
Botan::XTS_Decryption
Definition: xts.h:57
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::XTS_Encryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: xts.h:27
Botan::XTS_Decryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: xts.h:64
Botan::XTS_Encryption::~XTS_Encryption
~XTS_Encryption()
Definition: xts.h:41
Botan
Definition: algo_base.h:14
Botan::XTS_Encryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: xts.h:30
Botan::XTS_Decryption::~XTS_Decryption
~XTS_Decryption()
Definition: xts.h:78
Botan::XTS_Decryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: xts.h:67
Botan::SecureVector< byte >
Botan::BlockCipher
Definition: block_cipher.h:18