Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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/cipher_mode.h>
13 #include <botan/block_cipher.h>
14
15 namespace Botan {
16
17 /**
18 * CFB Mode
19 */
20 class BOTAN_DLL CFB_Mode : public Cipher_Mode
21 {
22 public:
23 std::string name() const override;
24
25 size_t update_granularity() const override;
26
27 size_t minimum_final_size() const override;
28
29 Key_Length_Specification key_spec() const override;
30
31 size_t output_length(size_t input_length) 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 protected:
41 CFB_Mode(BlockCipher* cipher, size_t feedback_bits);
42
43 const BlockCipher& cipher() const { return *m_cipher; }
44
45 size_t feedback() const { return m_feedback_bytes; }
46
47 secure_vector<uint8_t>& shift_register() { return m_shift_register; }
48
49 secure_vector<uint8_t>& keystream_buf() { return m_keystream_buf; }
50
51 private:
52 void start_msg(const uint8_t nonce[], size_t nonce_len) override;
53 void key_schedule(const uint8_t key[], size_t length) override;
54
55 std::unique_ptr<BlockCipher> m_cipher;
56 secure_vector<uint8_t> m_shift_register;
57 secure_vector<uint8_t> m_keystream_buf;
58 size_t m_feedback_bytes;
59 };
60
61 /**
62 * CFB Encryption
63 */
64 class BOTAN_DLL CFB_Encryption final : public CFB_Mode
65 {
66 public:
67 /**
68 * If feedback_bits is zero, cipher->block_size() bytes will be used.
69 * @param cipher block cipher to use
70 * @param feedback_bits number of bits fed back into the shift register,
71 * must be a multiple of 8
72 */
73 CFB_Encryption(BlockCipher* cipher, size_t feedback_bits) :
74 CFB_Mode(cipher, feedback_bits) {}
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
81 /**
82 * CFB Decryption
83 */
84 class BOTAN_DLL CFB_Decryption final : public CFB_Mode
85 {
86 public:
87 /**
88 * If feedback_bits is zero, cipher->block_size() bytes will be used.
89 * @param cipher block cipher to use
90 * @param feedback_bits number of bits fed back into the shift register,
91 * must be a multiple of 8
92 */
93 CFB_Decryption(BlockCipher* cipher, size_t feedback_bits) :
94 CFB_Mode(cipher, feedback_bits) {}
95
96 size_t process(uint8_t buf[], size_t size) override;
97
98 void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
99 };
100
101 }
102
103 #endif
Botan::CFB_Mode
Definition: cfb.h:20
Botan::CFB_Mode::cipher
const BlockCipher & cipher() const
Definition: cfb.h:43
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::CFB_Encryption::CFB_Encryption
CFB_Encryption(BlockCipher *cipher, size_t feedback_bits)
Definition: cfb.h:73
Botan::CFB_Mode::shift_register
secure_vector< uint8_t > & shift_register()
Definition: cfb.h:47
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan
Definition: alg_id.cpp:13
Botan::CFB_Mode::feedback
size_t feedback() const
Definition: cfb.h:45
Botan::CFB_Decryption::CFB_Decryption
CFB_Decryption(BlockCipher *cipher, size_t feedback_bits)
Definition: cfb.h:93
Botan::Cipher_Mode
Definition: cipher_mode.h:23
Botan::CFB_Decryption
Definition: cfb.h:84
Botan::CFB_Mode::keystream_buf
secure_vector< uint8_t > & keystream_buf()
Definition: cfb.h:49
Botan::CFB_Encryption
Definition: cfb.h:64
Botan::BlockCipher
Definition: block_cipher.h:19