Botan  1.11.15
Public Types | Public Member Functions | Static Public Member Functions
Botan::OFB Class Reference

#include <ofb.h>

Inheritance diagram for Botan::OFB:
Botan::StreamCipher Botan::SymmetricAlgorithm

List of all members.

Public Types

typedef SCAN_Name Spec

Public Member Functions

void cipher (const byte in[], byte out[], size_t length)
void cipher1 (byte buf[], size_t len)
void clear ()
OFBclone () const
template<typename Alloc >
void decrypt (std::vector< byte, Alloc > &inout)
template<typename Alloc >
void encipher (std::vector< byte, Alloc > &inout)
template<typename Alloc >
void encrypt (std::vector< byte, Alloc > &inout)
Key_Length_Specification key_spec () const
size_t maximum_keylength () const
size_t minimum_keylength () const
std::string name () const
 OFB (BlockCipher *cipher)
void set_iv (const byte iv[], size_t iv_len)
void set_key (const SymmetricKey &key)
template<typename Alloc >
void set_key (const std::vector< byte, Alloc > &key)
void set_key (const byte key[], size_t length)
bool valid_iv_length (size_t iv_len) const
bool valid_keylength (size_t length) const

Static Public Member Functions

static OFBmake (const Spec &spec)

Detailed Description

Output Feedback Mode

Definition at line 19 of file ofb.h.


Member Typedef Documentation

typedef SCAN_Name Botan::StreamCipher::Spec [inherited]

Definition at line 73 of file stream_cipher.h.


Constructor & Destructor Documentation

Parameters:
cipherthe underlying block cipher to use

Definition at line 25 of file ofb.cpp.

Referenced by make().

                            :
   m_cipher(cipher),
   m_buffer(m_cipher->block_size()),
   m_buf_pos(0)
   {
   }

Member Function Documentation

void Botan::OFB::cipher ( const byte  in[],
byte  out[],
size_t  len 
) [virtual]

Encrypt or decrypt a message

Parameters:
inthe plaintext
outthe byte array to hold the output, i.e. the ciphertext
lenthe length of both in and out in bytes

Implements Botan::StreamCipher.

Definition at line 52 of file ofb.cpp.

References Botan::xor_buf().

   {
   while(length >= m_buffer.size() - m_buf_pos)
      {
      xor_buf(out, in, &m_buffer[m_buf_pos], m_buffer.size() - m_buf_pos);
      length -= (m_buffer.size() - m_buf_pos);
      in += (m_buffer.size() - m_buf_pos);
      out += (m_buffer.size() - m_buf_pos);
      m_cipher->encrypt(m_buffer);
      m_buf_pos = 0;
      }
   xor_buf(out, in, &m_buffer[m_buf_pos], length);
   m_buf_pos += length;
   }
void Botan::StreamCipher::cipher1 ( byte  buf[],
size_t  len 
) [inline, inherited]

Encrypt or decrypt a message

Parameters:
bufthe plaintext / ciphertext
lenthe length of buf in bytes

Definition at line 36 of file stream_cipher.h.

Referenced by Botan::SIV_Encryption::finish().

         { cipher(buf, buf, len); }
void Botan::OFB::clear ( ) [virtual]

Implements Botan::SymmetricAlgorithm.

Definition at line 32 of file ofb.cpp.

References Botan::zeroise().

   {
   m_cipher->clear();
   zeroise(m_buffer);
   m_buf_pos = 0;
   }
OFB* Botan::OFB::clone ( ) const [inline, virtual]

Get a new object representing the same algorithm as *this

Implements Botan::StreamCipher.

Definition at line 36 of file ofb.h.

         { return new OFB(m_cipher->clone()); }
template<typename Alloc >
void Botan::StreamCipher::decrypt ( std::vector< byte, Alloc > &  inout) [inline, inherited]

Definition at line 48 of file stream_cipher.h.

         { cipher(&inout[0], &inout[0], inout.size()); }
template<typename Alloc >
void Botan::StreamCipher::encipher ( std::vector< byte, Alloc > &  inout) [inline, inherited]

Definition at line 40 of file stream_cipher.h.

         { cipher(&inout[0], &inout[0], inout.size()); }
template<typename Alloc >
void Botan::StreamCipher::encrypt ( std::vector< byte, Alloc > &  inout) [inline, inherited]

Definition at line 44 of file stream_cipher.h.

         { cipher(&inout[0], &inout[0], inout.size()); }
Key_Length_Specification Botan::OFB::key_spec ( ) const [inline, virtual]
Returns:
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 29 of file ofb.h.

         {
         return m_cipher->key_spec();
         }
OFB * Botan::OFB::make ( const Spec spec) [static]

Definition at line 15 of file ofb.cpp.

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_count(), c, Botan::Algo_Registry< T >::make(), and OFB().

   {
   if(spec.algo_name() == "OFB" && spec.arg_count() == 1)
      {
      if(BlockCipher* c = Algo_Registry<BlockCipher>::global_registry().make(spec.arg(0)))
         return new OFB(c);
      }
   return nullptr;
   }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const [inline, inherited]
Returns:
minimum allowed key length

Definition at line 36 of file sym_algo.h.

References Botan::Key_Length_Specification::maximum_keylength().

         {
         return key_spec().maximum_keylength();
         }
size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const [inline, inherited]
Returns:
maxmium allowed key length

Definition at line 44 of file sym_algo.h.

         {
         return key_spec().minimum_keylength();
         }
std::string Botan::OFB::name ( ) const [virtual]

Implements Botan::SymmetricAlgorithm.

Definition at line 47 of file ofb.cpp.

Referenced by set_iv().

   {
   return "OFB(" + m_cipher->name() + ")";
   }
void Botan::OFB::set_iv ( const byte  [],
size_t  iv_len 
) [virtual]

Resync the cipher using the IV

Parameters:
ivthe initialization vector
iv_lenthe length of the IV in bytes

Reimplemented from Botan::StreamCipher.

Definition at line 67 of file ofb.cpp.

References Botan::buffer_insert(), name(), valid_iv_length(), and Botan::zeroise().

   {
   if(!valid_iv_length(iv_len))
      throw Invalid_IV_Length(name(), iv_len);

   zeroise(m_buffer);
   buffer_insert(m_buffer, 0, iv, iv_len);

   m_cipher->encrypt(m_buffer);
   m_buf_pos = 0;
   }
void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key) [inline, inherited]

Set the symmetric key of this object.

Parameters:
keythe SymmetricKey to be set.

Definition at line 63 of file sym_algo.h.

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

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_mac_set_key(), Botan::TLS::Session::decrypt(), Botan::TLS::Session::encrypt(), and Botan::pbkdf2().

         {
         set_key(key.begin(), key.length());
         }
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< byte, Alloc > &  key) [inline, inherited]

Definition at line 69 of file sym_algo.h.

         {
         set_key(&key[0], key.size());
         }
void Botan::SymmetricAlgorithm::set_key ( const byte  key[],
size_t  length 
) [inline, inherited]

Set the symmetric key of this object.

Parameters:
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 79 of file sym_algo.h.

         {
         if(!valid_keylength(length))
            throw Invalid_Key_Length(name(), length);
         key_schedule(key, length);
         }
bool Botan::OFB::valid_iv_length ( size_t  iv_len) const [inline, virtual]
Parameters:
iv_lenthe length of the IV in bytes
Returns:
if the length is valid for this algorithm

Reimplemented from Botan::StreamCipher.

Definition at line 26 of file ofb.h.

Referenced by set_iv().

         { return (iv_len <= m_cipher->block_size()); }
bool Botan::SymmetricAlgorithm::valid_keylength ( size_t  length) const [inline, inherited]

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 54 of file sym_algo.h.

Referenced by Botan::aont_package(), and Botan::aont_unpackage().

         {
         return key_spec().valid_keylength(length);
         }

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