Botan 2.13.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 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 size_t feedback() const { return m_feedback_bytes; }
48 const BlockCipher& cipher() const { return *m_cipher; }
49 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 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 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
m_cipher
CCCryptorRef m_cipher
Definition: commoncrypto_mode.cpp:50
Botan::CFB_Mode
Definition: cfb.h:22
Botan::CFB_Mode::cipher
const BlockCipher & cipher() const
Definition: cfb.h:48
Botan::CFB_Mode::block_size
size_t block_size() const
Definition: cfb.h:49
Botan::CFB_Mode::m_keystream
secure_vector< uint8_t > m_keystream
Definition: cfb.h:52
Botan::Key_Length_Specification
Definition: key_spec.h:18
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
Botan::Cipher_Mode::update_granularity
virtual size_t update_granularity() const =0
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::Cipher_Mode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0
Botan::Cipher_Mode::reset
virtual void reset()=0
Botan::CFB_Encryption::CFB_Encryption
CFB_Encryption(BlockCipher *cipher, size_t feedback_bits)
Definition: cfb.h:76
Botan::Cipher_Mode::minimum_final_size
virtual size_t minimum_final_size() const =0
Botan::Cipher_Mode::default_nonce_length
virtual size_t default_nonce_length() const =0
Botan::Cipher_Mode::output_length
virtual size_t output_length(size_t input_length) const =0
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::SymmetricAlgorithm::name
virtual std::string name() const =0
Botan::SymmetricAlgorithm::clear
virtual void clear()=0
Botan::CFB_Mode::m_state
secure_vector< uint8_t > m_state
Definition: cfb.h:51
Botan
Definition: alg_id.cpp:13
Botan::CFB_Mode::feedback
size_t feedback() const
Definition: cfb.h:47
Botan::CFB_Decryption::CFB_Decryption
CFB_Decryption(BlockCipher *cipher, size_t feedback_bits)
Definition: cfb.h:96
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0
Botan::Cipher_Mode
Definition: cipher_mode.h:28
Botan::Cipher_Mode::process
virtual size_t process(uint8_t msg[], size_t msg_len)=0
Botan::CFB_Decryption
Definition: cfb.h:87
Botan::CFB_Encryption
Definition: cfb.h:67
m_block_size
size_t m_block_size
Definition: openssl_mode.cpp:47
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139
Botan::Cipher_Mode::valid_nonce_length
virtual bool valid_nonce_length(size_t nonce_len) const =0
Botan::Cipher_Mode::finish
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
Botan::BlockCipher
Definition: block_cipher.h:21