Coverage Report

Created: 2020-05-23 13:54

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