Botan 3.4.0
Crypto and TLS for C&
cfb.h
Go to the documentation of this file.
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/block_cipher.h>
13#include <botan/cipher_mode.h>
14
15namespace Botan {
16
17/**
18* CFB Mode
19*/
20class CFB_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
31
32 size_t output_length(size_t input_length) const final;
33
34 size_t default_nonce_length() const final;
35
36 bool valid_nonce_length(size_t n) const final;
37
38 void clear() final;
39
40 void reset() final;
41
42 bool has_keying_material() const final;
43
44 protected:
45 CFB_Mode(std::unique_ptr<BlockCipher> cipher, size_t feedback_bits);
46
47 void shift_register();
48
49 size_t feedback() const { return m_feedback_bytes; }
50
51 const BlockCipher& cipher() const { return *m_cipher; }
52
53 size_t block_size() const { return m_block_size; }
54
57 size_t m_keystream_pos = 0;
58
59 private:
60 void start_msg(const uint8_t nonce[], size_t nonce_len) override;
61 void key_schedule(std::span<const uint8_t> key) override;
62
63 std::unique_ptr<BlockCipher> m_cipher;
64 const size_t m_block_size;
65 const size_t m_feedback_bytes;
66};
67
68/**
69* CFB Encryption
70*/
72 public:
73 /**
74 * If feedback_bits is zero, cipher->block_size() bytes will be used.
75 * @param cipher block cipher to use
76 * @param feedback_bits number of bits fed back into the shift register,
77 * must be a multiple of 8
78 */
79 CFB_Encryption(std::unique_ptr<BlockCipher> cipher, size_t feedback_bits) :
80 CFB_Mode(std::move(cipher), feedback_bits) {}
81
82 private:
83 size_t process_msg(uint8_t buf[], size_t size) override;
84 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
85};
86
87/**
88* CFB Decryption
89*/
91 public:
92 /**
93 * If feedback_bits is zero, cipher->block_size() bytes will be used.
94 * @param cipher block cipher to use
95 * @param feedback_bits number of bits fed back into the shift register,
96 * must be a multiple of 8
97 */
98 CFB_Decryption(std::unique_ptr<BlockCipher> cipher, size_t feedback_bits) :
99 CFB_Mode(std::move(cipher), feedback_bits) {}
100
101 private:
102 size_t process_msg(uint8_t buf[], size_t size) override;
103 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
104};
105
106} // namespace Botan
107
108#endif
CFB_Decryption(std::unique_ptr< BlockCipher > cipher, size_t feedback_bits)
Definition cfb.h:98
CFB_Encryption(std::unique_ptr< BlockCipher > cipher, size_t feedback_bits)
Definition cfb.h:79
size_t ideal_granularity() const final
Definition cfb.cpp:51
size_t block_size() const
Definition cfb.h:53
secure_vector< uint8_t > m_keystream
Definition cfb.h:56
std::string name() const final
Definition cfb.cpp:35
CFB_Mode(std::unique_ptr< BlockCipher > cipher, size_t feedback_bits)
Definition cfb.cpp:15
void shift_register()
Definition cfb.cpp:100
Key_Length_Specification key_spec() const final
Definition cfb.cpp:60
size_t default_nonce_length() const final
Definition cfb.cpp:64
size_t feedback() const
Definition cfb.h:49
bool has_keying_material() const final
Definition cfb.cpp:72
size_t output_length(size_t input_length) const final
Definition cfb.cpp:43
secure_vector< uint8_t > m_state
Definition cfb.h:55
void reset() final
Definition cfb.cpp:30
void clear() final
Definition cfb.cpp:24
const BlockCipher & cipher() const
Definition cfb.h:51
size_t m_keystream_pos
Definition cfb.h:57
size_t update_granularity() const final
Definition cfb.cpp:47
bool valid_nonce_length(size_t n) const final
Definition cfb.cpp:68
size_t minimum_final_size() const final
Definition cfb.cpp:56
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61