Botan 2.19.5 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/cipher_mode.h>
13#include <botan/block_cipher.h>
14
15 BOTAN_FUTURE_INTERNAL_HEADER(xts.h)
16
17namespace Botan {
18
19/**
20* IEEE P1619 XTS Mode
21*/
22 class BOTAN_PUBLIC_API(2,0) XTS_Mode : public Cipher_Mode
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*/
68 class BOTAN_PUBLIC_API(2,0) XTS_Encryption final : public XTS_Mode
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*/
86 class BOTAN_PUBLIC_API(2,0) XTS_Decryption final : public XTS_Mode
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
Botan::BlockCipher
Definition: block_cipher.h:22
Botan::Cipher_Mode
Definition: cipher_mode.h:29
Botan::Cipher_Mode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0
Botan::Cipher_Mode::process
virtual size_t process(uint8_t msg[], size_t msg_len)=0
Botan::Cipher_Mode::default_nonce_length
virtual size_t default_nonce_length() const =0
Botan::Cipher_Mode::reset
virtual void reset()=0
Botan::Cipher_Mode::output_length
virtual size_t output_length(size_t input_length) const =0
Botan::Cipher_Mode::finish
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
Botan::Cipher_Mode::minimum_final_size
virtual size_t minimum_final_size() const =0
Botan::Cipher_Mode::valid_nonce_length
virtual bool valid_nonce_length(size_t nonce_len) const =0
Botan::Key_Length_Specification
Definition: sym_algo.h:20
Botan::SymmetricAlgorithm::name
virtual std::string name() const =0
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::XTS_Decryption
Definition: xts.h:87
Botan::XTS_Decryption::XTS_Decryption
XTS_Decryption(BlockCipher *cipher)
Definition: xts.h:92
Botan::XTS_Encryption
Definition: xts.h:69
Botan::XTS_Encryption::XTS_Encryption
XTS_Encryption(BlockCipher *cipher)
Definition: xts.h:74
Botan::XTS_Mode
Definition: xts.h:23
Botan::XTS_Mode::tweak
const uint8_t * tweak() const
Definition: xts.h:44
Botan::XTS_Mode::cipher_block_size
size_t cipher_block_size() const
Definition: xts.h:52
Botan::XTS_Mode::update_granularity
size_t update_granularity() const override
Definition: xts.h:27
Botan::XTS_Mode::cipher
const BlockCipher & cipher() const
Definition: xts.h:48
Botan::XTS_Mode::tweak_set
bool tweak_set() const
Definition: xts.h:46
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:29
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136
Botan
Definition: alg_id.cpp:13
Botan::secure_vector
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65