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

#include <ofb.h>

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

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
 

Detailed Description

Output Feedback Mode

Definition at line 19 of file ofb.h.

Constructor & Destructor Documentation

Botan::OFB::OFB ( BlockCipher cipher)
Parameters
cipherthe underlying block cipher to use

Definition at line 13 of file ofb.cpp.

13  :
14  m_cipher(cipher),
15  m_buffer(m_cipher->block_size()),
16  m_buf_pos(0)
17  {
18  }
void cipher(const byte in[], byte out[], size_t length)
Definition: ofb.cpp:40

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 40 of file ofb.cpp.

References Botan::xor_buf().

41  {
42  while(length >= m_buffer.size() - m_buf_pos)
43  {
44  xor_buf(out, in, &m_buffer[m_buf_pos], m_buffer.size() - m_buf_pos);
45  length -= (m_buffer.size() - m_buf_pos);
46  in += (m_buffer.size() - m_buf_pos);
47  out += (m_buffer.size() - m_buf_pos);
48  m_cipher->encrypt(m_buffer);
49  m_buf_pos = 0;
50  }
51  xor_buf(out, in, &m_buffer[m_buf_pos], length);
52  m_buf_pos += length;
53  }
void xor_buf(T out[], const T in[], size_t length)
Definition: xor_buf.h:23
void Botan::StreamCipher::cipher1 ( byte  buf[],
size_t  len 
)
inlineinherited

Encrypt or decrypt a message

Parameters
bufthe plaintext / ciphertext
lenthe length of buf in bytes

Definition at line 34 of file stream_cipher.h.

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

35  { cipher(buf, buf, len); }
virtual void cipher(const byte in[], byte out[], size_t len)=0
void Botan::OFB::clear ( )
virtual

Implements Botan::SymmetricAlgorithm.

Definition at line 20 of file ofb.cpp.

References Botan::zeroise().

21  {
22  m_cipher->clear();
23  zeroise(m_buffer);
24  m_buf_pos = 0;
25  }
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:166
OFB* Botan::OFB::clone ( ) const
inlinevirtual

Get a new object representing the same algorithm as *this

Implements Botan::StreamCipher.

Definition at line 36 of file ofb.h.

37  { return new OFB(m_cipher->clone()); }
OFB(BlockCipher *cipher)
Definition: ofb.cpp:13
template<typename Alloc >
void Botan::StreamCipher::decrypt ( std::vector< byte, Alloc > &  inout)
inlineinherited

Definition at line 46 of file stream_cipher.h.

47  { cipher(&inout[0], &inout[0], inout.size()); }
virtual void cipher(const byte in[], byte out[], size_t len)=0
template<typename Alloc >
void Botan::StreamCipher::encipher ( std::vector< byte, Alloc > &  inout)
inlineinherited

Definition at line 38 of file stream_cipher.h.

39  { cipher(&inout[0], &inout[0], inout.size()); }
virtual void cipher(const byte in[], byte out[], size_t len)=0
template<typename Alloc >
void Botan::StreamCipher::encrypt ( std::vector< byte, Alloc > &  inout)
inlineinherited

Definition at line 42 of file stream_cipher.h.

43  { cipher(&inout[0], &inout[0], inout.size()); }
virtual void cipher(const byte in[], byte out[], size_t len)=0
Key_Length_Specification Botan::OFB::key_spec ( ) const
inlinevirtual
Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 29 of file ofb.h.

30  {
31  return m_cipher->key_spec();
32  }
size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 36 of file sym_algo.h.

Referenced by Botan::PBE_PKCS5v20::PBE_PKCS5v20().

37  {
38  return key_spec().maximum_keylength();
39  }
size_t maximum_keylength() const
Definition: key_spec.h:69
virtual Key_Length_Specification key_spec() const =0
size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited
Returns
maxmium allowed key length

Definition at line 44 of file sym_algo.h.

45  {
46  return key_spec().minimum_keylength();
47  }
size_t minimum_keylength() const
Definition: key_spec.h:61
virtual Key_Length_Specification key_spec() const =0
std::string Botan::OFB::name ( ) const
virtual

Implements Botan::SymmetricAlgorithm.

Definition at line 35 of file ofb.cpp.

Referenced by set_iv().

36  {
37  return "OFB(" + m_cipher->name() + ")";
38  }
void Botan::OFB::set_iv ( const byte  iv[],
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 55 of file ofb.cpp.

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

56  {
57  if(!valid_iv_length(iv_len))
58  throw Invalid_IV_Length(name(), iv_len);
59 
60  zeroise(m_buffer);
61  buffer_insert(m_buffer, 0, iv, iv_len);
62 
63  m_cipher->encrypt(m_buffer);
64  m_buf_pos = 0;
65  }
std::string name() const
Definition: ofb.cpp:35
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
Definition: secmem.h:103
bool valid_iv_length(size_t iv_len) const
Definition: ofb.h:26
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:166
void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key)
inlineinherited

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_Filter::MAC_Filter(), and Botan::StreamCipher_Filter::StreamCipher_Filter().

64  {
65  set_key(key.begin(), key.length());
66  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:63
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key ( const std::vector< byte, Alloc > &  key)
inlineinherited

Definition at line 69 of file sym_algo.h.

70  {
71  set_key(&key[0], key.size());
72  }
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:63
void Botan::SymmetricAlgorithm::set_key ( const byte  key[],
size_t  length 
)
inlineinherited

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.

80  {
81  if(!valid_keylength(length))
82  throw Invalid_Key_Length(name(), length);
83  key_schedule(key, length);
84  }
bool valid_keylength(size_t length) const
Definition: sym_algo.h:54
virtual std::string name() const =0
bool Botan::OFB::valid_iv_length ( size_t  iv_len) const
inlinevirtual
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().

27  { return (iv_len <= m_cipher->block_size()); }
bool Botan::SymmetricAlgorithm::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 54 of file sym_algo.h.

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

55  {
56  return key_spec().valid_keylength(length);
57  }
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
virtual Key_Length_Specification key_spec() const =0

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