Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | Protected Member Functions | List of all members
Botan::StreamCipher_Filter Class Referencefinal

#include <filters.h>

Inheritance diagram for Botan::StreamCipher_Filter:
Botan::Keyed_Filter Botan::Filter

Public Member Functions

virtual bool attachable ()
 
virtual void end_msg ()
 
Key_Length_Specification key_spec () const override
 
std::string name () const override
 
void set_iv (const InitializationVector &iv) override
 
void set_key (const SymmetricKey &key) override
 
virtual void start_msg ()
 
 StreamCipher_Filter (StreamCipher *cipher)
 
 StreamCipher_Filter (StreamCipher *cipher, const SymmetricKey &key)
 
 StreamCipher_Filter (const std::string &cipher)
 
 StreamCipher_Filter (const std::string &cipher, const SymmetricKey &key)
 
bool valid_iv_length (size_t iv_len) const override
 
bool valid_keylength (size_t length) const
 
void write (const uint8_t input[], size_t input_len) override
 

Protected Member Functions

virtual void send (const uint8_t in[], size_t length)
 
void send (uint8_t in)
 
void send (const secure_vector< uint8_t > &in)
 
void send (const std::vector< uint8_t > &in)
 
void send (const secure_vector< uint8_t > &in, size_t length)
 
void send (const std::vector< uint8_t > &in, size_t length)
 

Detailed Description

Stream Cipher Filter

Definition at line 30 of file filters.h.

Constructor & Destructor Documentation

◆ StreamCipher_Filter() [1/4]

Botan::StreamCipher_Filter::StreamCipher_Filter ( StreamCipher cipher)
explicit

Construct a stream cipher filter.

Parameters
ciphera cipher object to use

Definition at line 13 of file algo_filt.cpp.

13  :
14  m_buffer(DEFAULT_BUFFERSIZE),
15  m_cipher(cipher)
16  {
17  }

◆ StreamCipher_Filter() [2/4]

Botan::StreamCipher_Filter::StreamCipher_Filter ( StreamCipher cipher,
const SymmetricKey key 
)

Construct a stream cipher filter.

Parameters
ciphera cipher object to use
keythe key to use inside this filter

Definition at line 19 of file algo_filt.cpp.

19  :
20  m_buffer(DEFAULT_BUFFERSIZE),
21  m_cipher(cipher)
22  {
23  m_cipher->set_key(key);
24  }

◆ StreamCipher_Filter() [3/4]

Botan::StreamCipher_Filter::StreamCipher_Filter ( const std::string &  cipher)
explicit

Construct a stream cipher filter.

Parameters
cipherthe name of the desired cipher

Definition at line 26 of file algo_filt.cpp.

26  :
27  m_buffer(DEFAULT_BUFFERSIZE),
28  m_cipher(StreamCipher::create_or_throw(sc_name))
29  {
30  }
static std::unique_ptr< StreamCipher > create_or_throw(const std::string &algo_spec, const std::string &provider="")

◆ StreamCipher_Filter() [4/4]

Botan::StreamCipher_Filter::StreamCipher_Filter ( const std::string &  cipher,
const SymmetricKey key 
)

Construct a stream cipher filter.

Parameters
cipherthe name of the desired cipher
keythe key to use inside this filter

Definition at line 32 of file algo_filt.cpp.

32  :
33  m_buffer(DEFAULT_BUFFERSIZE),
34  m_cipher(StreamCipher::create_or_throw(sc_name))
35  {
36  m_cipher->set_key(key);
37  }
static std::unique_ptr< StreamCipher > create_or_throw(const std::string &algo_spec, const std::string &provider="")

Member Function Documentation

◆ attachable()

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::SecureQueue, and Botan::DataSink.

Definition at line 52 of file filter.h.

52 { return true; }

◆ end_msg()

virtual void Botan::Filter::end_msg ( )
inlinevirtualinherited

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented in Botan::MAC_Filter, Botan::Hash_Filter, Botan::Base64_Decoder, Botan::Hex_Decoder, Botan::DataSink_Stream, Botan::Base64_Encoder, and Botan::Hex_Encoder.

Definition at line 46 of file filter.h.

Referenced by Botan::Filter::send().

46 { /* default empty */ }

◆ key_spec()

Key_Length_Specification Botan::StreamCipher_Filter::key_spec ( ) const
inlineoverridevirtual
Returns
object describing limits on key size

Implements Botan::Keyed_Filter.

Definition at line 61 of file filters.h.

61 { return m_cipher->key_spec(); }

◆ name()

std::string Botan::StreamCipher_Filter::name ( ) const
inlineoverridevirtual
Returns
descriptive name for this filter

Implements Botan::Filter.

Definition at line 34 of file filters.h.

34 { return m_cipher->name(); }

◆ send() [1/6]

void Botan::Filter::send ( const uint8_t  in[],
size_t  length 
)
protectedvirtualinherited
Parameters
insome input for the filter
lengththe length of in

Definition at line 27 of file filter.cpp.

References Botan::Filter::end_msg(), Botan::Filter::start_msg(), and Botan::Filter::write().

Referenced by Botan::Base64_Encoder::Base64_Encoder(), Botan::Hex_Encoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Base64_Decoder::end_msg(), Botan::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::Hex_Encoder::Hex_Encoder(), Botan::Cipher_Mode_Filter::valid_iv_length(), write(), Botan::Hex_Decoder::write(), and Botan::Base64_Decoder::write().

28  {
29  if(!length)
30  return;
31 
32  bool nothing_attached = true;
33  for(size_t j = 0; j != total_ports(); ++j)
34  if(m_next[j])
35  {
36  if(m_write_queue.size())
37  m_next[j]->write(m_write_queue.data(), m_write_queue.size());
38  m_next[j]->write(input, length);
39  nothing_attached = false;
40  }
41 
42  if(nothing_attached)
43  m_write_queue += std::make_pair(input, length);
44  else
45  m_write_queue.clear();
46  }
virtual void write(const uint8_t input[], size_t length)=0

◆ send() [2/6]

void Botan::Filter::send ( uint8_t  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 65 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

65 { send(&in, 1); }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [3/6]

void Botan::Filter::send ( const secure_vector< uint8_t > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 70 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

70 { send(in.data(), in.size()); }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [4/6]

void Botan::Filter::send ( const std::vector< uint8_t > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 75 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

75 { send(in.data(), in.size()); }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [5/6]

void Botan::Filter::send ( const secure_vector< uint8_t > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 81 of file filter.h.

82  {
83  send(in.data(), length);
84  }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ send() [6/6]

void Botan::Filter::send ( const std::vector< uint8_t > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 90 of file filter.h.

91  {
92  send(in.data(), length);
93  }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

◆ set_iv()

void Botan::StreamCipher_Filter::set_iv ( const InitializationVector iv)
inlineoverridevirtual

Set the initialization vector for this filter.

Parameters
ivthe initialization vector to set

Reimplemented from Botan::Keyed_Filter.

Definition at line 50 of file filters.h.

51  {
52  m_cipher->set_iv(iv.begin(), iv.length());
53  }

◆ set_key()

void Botan::StreamCipher_Filter::set_key ( const SymmetricKey key)
inlineoverridevirtual

Set the key of this filter.

Parameters
keythe key to set

Implements Botan::Keyed_Filter.

Definition at line 59 of file filters.h.

59 { m_cipher->set_key(key); }

◆ start_msg()

virtual void Botan::Filter::start_msg ( )
inlinevirtualinherited

Start a new message. Must be closed by end_msg() before another message can be started.

Definition at line 40 of file filter.h.

Referenced by Botan::Filter::send().

40 { /* default empty */ }

◆ valid_iv_length()

bool Botan::StreamCipher_Filter::valid_iv_length ( size_t  length) const
inlineoverridevirtual

Check whether an IV length is valid for this filter

Parameters
lengththe IV length to be checked for validity
Returns
true if the IV length is valid, false otherwise

Reimplemented from Botan::Keyed_Filter.

Definition at line 43 of file filters.h.

44  { return m_cipher->valid_iv_length(iv_len); }

◆ valid_keylength()

bool Botan::Keyed_Filter::valid_keylength ( size_t  length) const
inlineinherited

Check whether a key length is valid for this filter

Parameters
lengththe key length to be checked for validity
Returns
true if the key length is valid, false otherwise

Definition at line 42 of file key_filt.h.

43  {
44  return key_spec().valid_keylength(length);
45  }
virtual Key_Length_Specification key_spec() const =0
bool valid_keylength(size_t length) const
Definition: key_spec.h:51

◆ write()

void Botan::StreamCipher_Filter::write ( const uint8_t  input[],
size_t  input_len 
)
overridevirtual

Write input data

Parameters
inputdata
input_lenlength of input in bytes

Implements Botan::Filter.

Definition at line 39 of file algo_filt.cpp.

References Botan::Filter::send().

40  {
41  while(length)
42  {
43  size_t copied = std::min<size_t>(length, m_buffer.size());
44  m_cipher->cipher(input, m_buffer.data(), copied);
45  send(m_buffer, copied);
46  input += copied;
47  length -= copied;
48  }
49  }
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27

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