Botan 3.3.0
Crypto and TLS for C&
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/block_cipher.h>
13#include <botan/cipher_mode.h>
14
15namespace Botan {
16
17/**
18* IEEE P1619 XTS Mode
19*/
20class XTS_Mode : public Cipher_Mode {
21 public:
22 std::string name() const final;
23
24 size_t update_granularity() const final;
25
26 size_t ideal_granularity() const final;
27
28 size_t minimum_final_size() const final;
29
31
32 size_t default_nonce_length() const final;
33
34 bool valid_nonce_length(size_t n) const final;
35
36 void clear() final;
37
38 void reset() final;
39
40 bool has_keying_material() const final;
41
42 protected:
43 explicit XTS_Mode(std::unique_ptr<BlockCipher> cipher);
44
45 const uint8_t* tweak() const { return m_tweak.data(); }
46
47 bool tweak_set() const { return m_tweak.empty() == false; }
48
49 size_t tweak_blocks() const { return m_tweak_blocks; }
50
51 const BlockCipher& cipher() const { return *m_cipher; }
52
53 void update_tweak(size_t last_used);
54
55 size_t cipher_block_size() const { return m_cipher_block_size; }
56
57 private:
58 void start_msg(const uint8_t nonce[], size_t nonce_len) override;
59 void key_schedule(std::span<const uint8_t> key) override;
60
61 std::unique_ptr<BlockCipher> m_cipher;
62 std::unique_ptr<BlockCipher> m_tweak_cipher;
64 const size_t m_cipher_block_size;
65 const size_t m_cipher_parallelism;
66 const size_t m_tweak_blocks;
67};
68
69/**
70* IEEE P1619 XTS Encryption
71*/
73 public:
74 /**
75 * @param cipher underlying block cipher
76 */
77 explicit XTS_Encryption(std::unique_ptr<BlockCipher> cipher) : XTS_Mode(std::move(cipher)) {}
78
79 size_t output_length(size_t input_length) const override;
80
81 private:
82 size_t process_msg(uint8_t buf[], size_t size) override;
83 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
84};
85
86/**
87* IEEE P1619 XTS Decryption
88*/
90 public:
91 /**
92 * @param cipher underlying block cipher
93 */
94 explicit XTS_Decryption(std::unique_ptr<BlockCipher> cipher) : XTS_Mode(std::move(cipher)) {}
95
96 size_t output_length(size_t input_length) const override;
97
98 private:
99 size_t process_msg(uint8_t buf[], size_t size) override;
100 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
101};
102
103} // namespace Botan
104
105#endif
XTS_Decryption(std::unique_ptr< BlockCipher > cipher)
Definition xts.h:94
size_t output_length(size_t input_length) const override
Definition xts.cpp:174
size_t output_length(size_t input_length) const override
Definition xts.cpp:108
XTS_Encryption(std::unique_ptr< BlockCipher > cipher)
Definition xts.h:77
void reset() final
Definition xts.cpp:42
const uint8_t * tweak() const
Definition xts.h:45
size_t ideal_granularity() const final
Definition xts.cpp:38
std::string name() const final
Definition xts.cpp:46
size_t default_nonce_length() const final
Definition xts.cpp:58
size_t cipher_block_size() const
Definition xts.h:55
size_t update_granularity() const final
Definition xts.cpp:34
bool has_keying_material() const final
Definition xts.cpp:66
void clear() final
Definition xts.cpp:28
XTS_Mode(std::unique_ptr< BlockCipher > cipher)
Definition xts.cpp:16
const BlockCipher & cipher() const
Definition xts.h:51
size_t tweak_blocks() const
Definition xts.h:49
Key_Length_Specification key_spec() const final
Definition xts.cpp:54
void update_tweak(size_t last_used)
Definition xts.cpp:94
bool tweak_set() const
Definition xts.h:47
bool valid_nonce_length(size_t n) const final
Definition xts.cpp:62
size_t minimum_final_size() const final
Definition xts.cpp:50
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61