Coverage Report

Created: 2021-04-07 06:07

/src/botan/build/include/botan/internal/xts.h
Line
Count
Source (jump to first uncovered line)
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
namespace Botan {
16
17
/**
18
* IEEE P1619 XTS Mode
19
*/
20
class XTS_Mode : public Cipher_Mode
21
   {
22
   public:
23
      std::string name() const override;
24
25
0
      size_t update_granularity() const override { return m_cipher_parallelism; }
26
27
      size_t minimum_final_size() const override;
28
29
      Key_Length_Specification key_spec() const override;
30
31
      size_t default_nonce_length() const override;
32
33
      bool valid_nonce_length(size_t n) const override;
34
35
      void clear() override;
36
37
      void reset() override;
38
39
   protected:
40
      explicit XTS_Mode(BlockCipher* cipher);
41
42
0
      const uint8_t* tweak() const { return m_tweak.data(); }
43
44
0
      bool tweak_set() const { return m_tweak.empty() == false; }
45
46
0
      const BlockCipher& cipher() const { return *m_cipher; }
47
48
      void update_tweak(size_t last_used);
49
50
0
      size_t cipher_block_size() const { return m_cipher_block_size; }
51
52
   private:
53
      void start_msg(const uint8_t nonce[], size_t nonce_len) override;
54
      void key_schedule(const uint8_t key[], size_t length) override;
55
56
      std::unique_ptr<BlockCipher> m_cipher;
57
      std::unique_ptr<BlockCipher> m_tweak_cipher;
58
      secure_vector<uint8_t> m_tweak;
59
      const size_t m_cipher_block_size;
60
      const size_t m_cipher_parallelism;
61
   };
62
63
/**
64
* IEEE P1619 XTS Encryption
65
*/
66
class XTS_Encryption final : public XTS_Mode
67
   {
68
   public:
69
      /**
70
      * @param cipher underlying block cipher
71
      */
72
0
      explicit XTS_Encryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
73
74
      size_t process(uint8_t buf[], size_t size) override;
75
76
      void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
77
78
      size_t output_length(size_t input_length) const override;
79
   };
80
81
/**
82
* IEEE P1619 XTS Decryption
83
*/
84
class XTS_Decryption final : public XTS_Mode
85
   {
86
   public:
87
      /**
88
      * @param cipher underlying block cipher
89
      */
90
0
      explicit XTS_Decryption(BlockCipher* cipher) : XTS_Mode(cipher) {}
91
92
      size_t process(uint8_t buf[], size_t size) override;
93
94
      void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
95
96
      size_t output_length(size_t input_length) const override;
97
   };
98
99
}
100
101
#endif