Coverage Report

Created: 2020-11-21 08:34

/src/botan/build/include/botan/internal/cfb.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* CFB mode
3
* (C) 1999-2007,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_CFB_H_
10
#define BOTAN_MODE_CFB_H_
11
12
#include <botan/cipher_mode.h>
13
#include <botan/block_cipher.h>
14
15
namespace Botan {
16
17
/**
18
* CFB Mode
19
*/
20
class CFB_Mode : public Cipher_Mode
21
   {
22
   public:
23
      std::string name() const override final;
24
25
      size_t update_granularity() const override final;
26
27
      size_t minimum_final_size() const override final;
28
29
      Key_Length_Specification key_spec() const override final;
30
31
      size_t output_length(size_t input_length) const override final;
32
33
      size_t default_nonce_length() const override final;
34
35
      bool valid_nonce_length(size_t n) const override final;
36
37
      void clear() override final;
38
39
      void reset() override final;
40
   protected:
41
      CFB_Mode(BlockCipher* cipher, size_t feedback_bits);
42
43
      void shift_register();
44
45
0
      size_t feedback() const { return m_feedback_bytes; }
46
0
      const BlockCipher& cipher() const { return *m_cipher; }
47
0
      size_t block_size() const { return m_block_size; }
48
49
      secure_vector<uint8_t> m_state;
50
      secure_vector<uint8_t> m_keystream;
51
      size_t m_keystream_pos = 0;
52
53
   private:
54
      void start_msg(const uint8_t nonce[], size_t nonce_len) override;
55
      void key_schedule(const uint8_t key[], size_t length) override;
56
57
      std::unique_ptr<BlockCipher> m_cipher;
58
      const size_t m_block_size;
59
      const size_t m_feedback_bytes;
60
   };
61
62
/**
63
* CFB Encryption
64
*/
65
class CFB_Encryption final : public CFB_Mode
66
   {
67
   public:
68
      /**
69
      * If feedback_bits is zero, cipher->block_size() bytes will be used.
70
      * @param cipher block cipher to use
71
      * @param feedback_bits number of bits fed back into the shift register,
72
      * must be a multiple of 8
73
      */
74
      CFB_Encryption(BlockCipher* cipher, size_t feedback_bits) :
75
0
         CFB_Mode(cipher, feedback_bits) {}
76
77
      size_t process(uint8_t buf[], size_t size) override;
78
79
      void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
80
   };
81
82
/**
83
* CFB Decryption
84
*/
85
class CFB_Decryption final : public CFB_Mode
86
   {
87
   public:
88
      /**
89
      * If feedback_bits is zero, cipher->block_size() bytes will be used.
90
      * @param cipher block cipher to use
91
      * @param feedback_bits number of bits fed back into the shift register,
92
      * must be a multiple of 8
93
      */
94
      CFB_Decryption(BlockCipher* cipher, size_t feedback_bits) :
95
0
         CFB_Mode(cipher, feedback_bits) {}
96
97
      size_t process(uint8_t buf[], size_t size) override;
98
99
      void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
100
   };
101
102
}
103
104
#endif