Botan  1.11.10
Public Member Functions | Protected Member Functions | List of all members
Botan::CFB_Decryption Class Reference

#include <cfb.h>

Inheritance diagram for Botan::CFB_Decryption:
Botan::CFB_Mode Botan::Cipher_Mode Botan::Keyed_Transform Botan::Transformation

Public Member Functions

virtual bool authenticated () const
 
 CFB_Decryption (BlockCipher *cipher, size_t feedback_bits)
 
void clear () override
 
size_t default_nonce_length () const override
 
void finish (secure_vector< byte > &final_block, size_t offset=0) override
 
Key_Length_Specification key_spec () const override
 
size_t minimum_final_size () const override
 
std::string name () const override
 
size_t output_length (size_t input_length) const override
 
virtual std::string provider () const
 
template<typename Alloc >
void set_key (const std::vector< byte, Alloc > &key)
 
void set_key (const SymmetricKey &key)
 
void set_key (const byte key[], size_t length)
 
template<typename Alloc >
secure_vector< bytestart (const std::vector< byte, Alloc > &nonce)
 
secure_vector< bytestart (const byte nonce[], size_t nonce_len)
 
secure_vector< bytestart ()
 
template<typename Alloc >
secure_vector< bytestart_vec (const std::vector< byte, Alloc > &nonce)
 
void update (secure_vector< byte > &blocks, size_t offset=0) override
 
size_t update_granularity () const override
 
bool valid_keylength (size_t length) const
 
bool valid_nonce_length (size_t n) const override
 

Protected Member Functions

const BlockCiphercipher () const
 
size_t feedback () const
 
secure_vector< byte > & keystream_buf ()
 
secure_vector< byte > & shift_register ()
 

Detailed Description

CFB Decryption

Definition at line 76 of file cfb.h.

Constructor & Destructor Documentation

Botan::CFB_Decryption::CFB_Decryption ( BlockCipher cipher,
size_t  feedback_bits 
)
inline

Definition at line 79 of file cfb.h.

79  :
80  CFB_Mode(cipher, feedback_bits) {}
const BlockCipher & cipher() const
Definition: cfb.h:41
CFB_Mode(BlockCipher *cipher, size_t feedback_bits)
Definition: cfb.cpp:14

Member Function Documentation

virtual bool Botan::Cipher_Mode::authenticated ( ) const
inlinevirtualinherited

Returns true iff this mode provides authentication as well as confidentiality.

Reimplemented in Botan::AEAD_Mode.

Definition at line 25 of file cipher_mode.h.

25 { return false; }
const BlockCipher& Botan::CFB_Mode::cipher ( ) const
inlineprotectedinherited
void Botan::CFB_Mode::clear ( )
overridevirtualinherited

Implements Botan::Transformation.

Definition at line 23 of file cfb.cpp.

24  {
25  m_cipher->clear();
26  m_shift_register.clear();
27  }
size_t Botan::CFB_Mode::default_nonce_length ( ) const
overridevirtualinherited

Return the default size for a nonce

Implements Botan::Transformation.

Definition at line 57 of file cfb.cpp.

References Botan::BlockCipher::block_size(), and Botan::CFB_Mode::cipher().

58  {
59  return cipher().block_size();
60  }
const BlockCipher & cipher() const
Definition: cfb.h:41
virtual size_t block_size() const =0
size_t Botan::CFB_Mode::feedback ( ) const
inlineprotectedinherited

Definition at line 43 of file cfb.h.

Referenced by Botan::CFB_Mode::CFB_Mode(), Botan::CFB_Mode::name(), Botan::CFB_Encryption::update(), update(), and Botan::CFB_Mode::update_granularity().

43 { return m_feedback_bytes; }
void Botan::CFB_Decryption::finish ( secure_vector< byte > &  final_block,
size_t  offset = 0 
)
overridevirtual

Complete processing of a message.

Parameters
final_blockin/out parameter which must be at least minimum_final_size() bytes, and will be set to any final output
offsetan offset into final_block to begin processing

Implements Botan::Transformation.

Definition at line 145 of file cfb.cpp.

References update().

146  {
147  update(buffer, offset);
148  }
void update(secure_vector< byte > &blocks, size_t offset=0) override
Definition: cfb.cpp:115
Key_Length_Specification Botan::CFB_Mode::key_spec ( ) const
overridevirtualinherited
Returns
object describing limits on key size

Implements Botan::Keyed_Transform.

Definition at line 52 of file cfb.cpp.

References Botan::CFB_Mode::cipher(), and Botan::SymmetricAlgorithm::key_spec().

53  {
54  return cipher().key_spec();
55  }
const BlockCipher & cipher() const
Definition: cfb.h:41
virtual Key_Length_Specification key_spec() const =0
secure_vector<byte>& Botan::CFB_Mode::keystream_buf ( )
inlineprotectedinherited

Definition at line 47 of file cfb.h.

Referenced by Botan::CFB_Encryption::update(), and update().

47 { return m_keystream_buf; }
size_t Botan::CFB_Mode::minimum_final_size ( ) const
overridevirtualinherited
Returns
required minimium size to finalize() - may be any length larger than this.

Implements Botan::Transformation.

Definition at line 47 of file cfb.cpp.

48  {
49  return 0;
50  }
std::string Botan::CFB_Mode::name ( ) const
overridevirtualinherited

Implements Botan::Transformation.

Definition at line 29 of file cfb.cpp.

References Botan::CFB_Mode::cipher(), Botan::CFB_Mode::feedback(), Botan::SymmetricAlgorithm::name(), and Botan::ASN1::to_string().

Referenced by Botan::CFB_Mode::CFB_Mode().

30  {
31  if(feedback() == cipher().block_size())
32  return cipher().name() + "/CFB";
33  else
34  return cipher().name() + "/CFB(" + std::to_string(feedback()*8) + ")";
35  }
const BlockCipher & cipher() const
Definition: cfb.h:41
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:46
virtual std::string name() const =0
size_t feedback() const
Definition: cfb.h:43
size_t Botan::CFB_Mode::output_length ( size_t  input_length) const
overridevirtualinherited

Returns the size of the output if this transform is used to process a message with input_length bytes. Will throw if unable to give a precise answer.

Implements Botan::Transformation.

Definition at line 37 of file cfb.cpp.

38  {
39  return input_length;
40  }
virtual std::string Botan::Transformation::provider ( ) const
inlinevirtualinherited

Return some short name describing the provider of this tranformation. Useful in cases where multiple implementations are available (eg, different implementations of AES). Default "core" is used for the 'standard' implementation included in the library.

Definition at line 117 of file transform.h.

117 { return "core"; }
template<typename Alloc >
void Botan::Keyed_Transform::set_key ( const std::vector< byte, Alloc > &  key)
inlineinherited

Definition at line 145 of file transform.h.

146  {
147  set_key(&key[0], key.size());
148  }
void set_key(const std::vector< byte, Alloc > &key)
Definition: transform.h:145
void Botan::Keyed_Transform::set_key ( const SymmetricKey key)
inlineinherited

Definition at line 150 of file transform.h.

References Botan::OctetString::begin(), and Botan::OctetString::length().

151  {
152  set_key(key.begin(), key.length());
153  }
void set_key(const std::vector< byte, Alloc > &key)
Definition: transform.h:145
void Botan::Keyed_Transform::set_key ( const byte  key[],
size_t  length 
)
inlineinherited

Set the symmetric key of this transform

Parameters
keycontains the key material
lengthin bytes of key param

Definition at line 160 of file transform.h.

161  {
162  if(!valid_keylength(length))
163  throw Invalid_Key_Length(name(), length);
164  key_schedule(key, length);
165  }
virtual std::string name() const =0
bool valid_keylength(size_t length) const
Definition: transform.h:139
secure_vector<byte>& Botan::CFB_Mode::shift_register ( )
inlineprotectedinherited

Definition at line 45 of file cfb.h.

Referenced by Botan::CFB_Encryption::update(), and update().

45 { return m_shift_register; }
template<typename Alloc >
secure_vector<byte> Botan::Transformation::start ( const std::vector< byte, Alloc > &  nonce)
inlineinherited

Begin processing a message.

Parameters
noncethe per message nonce

Definition at line 31 of file transform.h.

32  {
33  return start(&nonce[0], nonce.size());
34  }
secure_vector< byte > start()
Definition: transform.h:60
secure_vector<byte> Botan::Transformation::start ( const byte  nonce[],
size_t  nonce_len 
)
inlineinherited

Begin processing a message.

Parameters
noncethe per message nonce
nonce_lenlength of nonce

Definition at line 52 of file transform.h.

53  {
54  return start_raw(nonce, nonce_len);
55  }
virtual secure_vector< byte > start_raw(const byte nonce[], size_t nonce_len)=0
secure_vector<byte> Botan::Transformation::start ( )
inlineinherited

Begin processing a message.

Definition at line 60 of file transform.h.

61  {
62  return start_raw(nullptr, 0);
63  }
virtual secure_vector< byte > start_raw(const byte nonce[], size_t nonce_len)=0
template<typename Alloc >
secure_vector<byte> Botan::Transformation::start_vec ( const std::vector< byte, Alloc > &  nonce)
inlineinherited

Begin processing a message.

Parameters
noncethe per message nonce

Definition at line 42 of file transform.h.

43  {
44  return start(&nonce[0], nonce.size());
45  }
secure_vector< byte > start()
Definition: transform.h:60
void Botan::CFB_Decryption::update ( secure_vector< byte > &  blocks,
size_t  offset = 0 
)
overridevirtual

Process some data. Input must be in size update_granularity() byte blocks.

Parameters
blocksin/out paramter which will possibly be resized
offsetan offset into blocks to begin processing

Implements Botan::Transformation.

Definition at line 115 of file cfb.cpp.

References Botan::BlockCipher::block_size(), BOTAN_ASSERT, Botan::CFB_Mode::cipher(), Botan::copy_mem(), Botan::BlockCipher::encrypt(), Botan::CFB_Mode::feedback(), Botan::CFB_Mode::keystream_buf(), Botan::CFB_Mode::shift_register(), state, and Botan::xor_buf().

Referenced by finish().

116  {
117  BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
118  size_t sz = buffer.size() - offset;
119  byte* buf = &buffer[offset];
120 
121  const size_t BS = cipher().block_size();
122 
123  secure_vector<byte>& state = shift_register();
124  const size_t shift = feedback();
125 
126  while(sz)
127  {
128  const size_t took = std::min(shift, sz);
129 
130  // first update shift register with ciphertext
131  copy_mem(&state[0], &state[shift], BS - shift);
132  copy_mem(&state[BS-shift], &buf[0], took);
133 
134  // then decrypt
135  xor_buf(&buf[0], &keystream_buf()[0], took);
136 
137  // then update keystream
138  cipher().encrypt(state, keystream_buf());
139 
140  buf += took;
141  sz -= took;
142  }
143  }
void xor_buf(T out[], const T in[], size_t length)
Definition: xor_buf.h:23
secure_vector< byte > & shift_register()
Definition: cfb.h:45
const BlockCipher & cipher() const
Definition: cfb.h:41
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
RC4_KEY state
Definition: ossl_arc4.cpp:40
secure_vector< byte > & keystream_buf()
Definition: cfb.h:47
uint8_t byte
Definition: types.h:30
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:39
size_t feedback() const
Definition: cfb.h:43
void encrypt(const byte in[], byte out[]) const
Definition: block_cipher.h:47
virtual size_t block_size() const =0
size_t Botan::CFB_Mode::update_granularity ( ) const
overridevirtualinherited
Returns
size of required blocks to update

Implements Botan::Transformation.

Definition at line 42 of file cfb.cpp.

References Botan::CFB_Mode::feedback().

43  {
44  return feedback();
45  }
size_t feedback() const
Definition: cfb.h:43
bool Botan::Keyed_Transform::valid_keylength ( size_t  length) const
inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 139 of file transform.h.

140  {
141  return key_spec().valid_keylength(length);
142  }
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
virtual Key_Length_Specification key_spec() const =0
bool Botan::CFB_Mode::valid_nonce_length ( size_t  nonce_len) const
overridevirtualinherited

Return true iff nonce_len is a valid length for the nonce

Implements Botan::Transformation.

Definition at line 62 of file cfb.cpp.

References Botan::CFB_Mode::cipher().

63  {
64  return (n == cipher().block_size());
65  }
const BlockCipher & cipher() const
Definition: cfb.h:41

The documentation for this class was generated from the following files: