Coverage Report

Created: 2026-11-12 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/botan/build/include/internal/botan/internal/xts.h
Line
Count
Source
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
15
namespace Botan {
16
17
/**
18
* IEEE P1619 XTS Mode
19
*/
20
class 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
30
      Key_Length_Specification key_spec() const final;
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
0
      const uint8_t* tweak() const { return m_tweak.data(); }
46
47
0
      bool tweak_set() const { return !m_tweak.empty(); }
48
49
0
      size_t tweak_blocks() const { return m_tweak_blocks; }
50
51
0
      const BlockCipher& cipher() const { return *m_cipher; }
52
53
      void update_tweak(size_t last_used);
54
55
0
      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;
63
      secure_vector<uint8_t> m_tweak;
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
*/
72
class XTS_Encryption final : public XTS_Mode {
73
   public:
74
      /**
75
      * @param cipher underlying block cipher
76
      */
77
0
      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
*/
89
class XTS_Decryption final : public XTS_Mode {
90
   public:
91
      /**
92
      * @param cipher underlying block cipher
93
      */
94
0
      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