Coverage Report

Created: 2020-06-30 13:58

/src/botan/build/include/botan/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
BOTAN_FUTURE_INTERNAL_HEADER(xts.h)
16
17
namespace 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
0
      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
0
      const uint8_t* tweak() const { return m_tweak.data(); }
45
46
0
      bool tweak_set() const { return m_tweak.empty() == false; }
47
48
0
      const BlockCipher& cipher() const { return *m_cipher; }
49
50
      void update_tweak(size_t last_used);
51
52
0
      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
0
      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
0
      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