Botan 2.19.3
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/cipher_mode.h>
13#include <botan/block_cipher.h>
14
16
17namespace Botan {
18
19/**
20* CFB Mode
21*/
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
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*/
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*/
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
CFB_Decryption(BlockCipher *cipher, size_t feedback_bits)
Definition cfb.h:96
CFB_Encryption(BlockCipher *cipher, size_t feedback_bits)
Definition cfb.h:76
size_t block_size() const
Definition cfb.h:49
secure_vector< uint8_t > m_keystream
Definition cfb.h:52
size_t feedback() const
Definition cfb.h:47
secure_vector< uint8_t > m_state
Definition cfb.h:51
const BlockCipher & cipher() const
Definition cfb.h:48
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0
virtual size_t process(uint8_t msg[], size_t msg_len)=0
virtual size_t default_nonce_length() const =0
virtual void reset()=0
virtual size_t output_length(size_t input_length) const =0
virtual void finish(secure_vector< uint8_t > &final_block, size_t offset=0)=0
virtual size_t minimum_final_size() const =0
virtual size_t update_granularity() const =0
virtual bool valid_nonce_length(size_t nonce_len) const =0
virtual std::string name() const =0
virtual void clear()=0
virtual Key_Length_Specification key_spec() const =0
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition compiler.h:136
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:65