Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

`#include <stream_mode.h>`

Inheritance diagram for Botan::Stream_Cipher_Mode:

## Public Member Functions
virtual bool | authenticated () const
void | clear () override
size_t | default_nonce_length () const override
void | finish (secure_vector< uint8_t > &buf, size_t offset) 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
size_t | process (uint8_t buf[], size_t sz) override
virtual std::string | provider () const
void | reset () override
template<typename Alloc >
void | set_key (const std::vector< uint8_t, Alloc > &key)
void | set_key (const SymmetricKey &key)
void | set_key (const uint8_t key[], size_t length)
template<typename Alloc >
void | start (const std::vector< uint8_t, Alloc > &nonce)
void | start (const uint8_t nonce[], size_t nonce_len)
void | start ()
| Stream_Cipher_Mode (StreamCipher *cipher)
virtual size_t | tag_size () const
void | update (secure_vector< uint8_t > &buffer, size_t offset=0)
size_t | update_granularity () const override
bool | valid_keylength (size_t length) const
bool | valid_nonce_length (size_t nonce_len) const override

## Detailed Description

Definition at line 16 of file stream_mode.h.

## Constructor & Destructor Documentation

Botan::Stream_Cipher_Mode::Stream_Cipher_Mode | ( | StreamCipher * | cipher | ) |
| inline explicit

Parameters

  cipher | underyling stream cipher

Definition at line 22 of file stream_mode.h.

22 : m_cipher(cipher) {}

## Member Function Documentation

virtual bool Botan::Cipher_Mode::authenticated | ( |  | ) | const
| inline virtual inherited

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

Reimplemented in Botan::AEAD_Mode.

Definition at line 145 of file cipher_mode.h.

145 { return false; }

void Botan::Stream_Cipher_Mode::clear | ( |  | ) |
| inline override virtual

Zeroise all state See also reset_msg()

Implements Botan::Cipher_Mode.

Definition at line 48 of file stream_mode.h.

49 {
50 m_cipher->clear();
51 reset();
52 }
Botan::Stream_Cipher_Mode::reset
void reset() override
Definition: stream_mode.h:54

size_t Botan::Stream_Cipher_Mode::default_nonce_length | ( |  | ) | const
| inline override virtual

Returns
  the default size for a nonce

Implements Botan::Cipher_Mode.

Definition at line 39 of file stream_mode.h.

39 { return 0; }

void Botan::Stream_Cipher_Mode::finish | ( | secure_vector< uint8_t > & | final_block,
|  | size_t | offset
| ) |  |
| inline override virtual

Complete processing of a message.

Parameters

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

Implements Botan::Cipher_Mode.

Definition at line 30 of file stream_mode.h.

31 { return update(buf, offset); }
Botan::Cipher_Mode::update
void update(secure_vector< uint8_t > &buffer, size_t offset=0)
Definition: cipher_mode.h:81

Key_Length_Specification Botan::Stream_Cipher_Mode::key_spec | ( |  | ) | const
| inline override virtual

Returns
  object describing limits on key size

Implements Botan::Cipher_Mode.

Definition at line 44 of file stream_mode.h.

44 { return m_cipher->key_spec(); }

size_t Botan::Stream_Cipher_Mode::minimum_final_size | ( |  | ) | const
| inline override virtual

Returns
  required minimium size to finalize() - may be any length larger than this.

Implements Botan::Cipher_Mode.

Definition at line 37 of file stream_mode.h.

37 { return 0; }

std::string Botan::Stream_Cipher_Mode::name | ( |  | ) | const
| inline override virtual

Implements Botan::Cipher_Mode.

Definition at line 46 of file stream_mode.h.

46 { return m_cipher->name(); }

size_t Botan::Stream_Cipher_Mode::output_length | ( | size_t | input_length | ) | const
| inline override virtual

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::Cipher_Mode.

Definition at line 33 of file stream_mode.h.

33 { return input_length; }

size_t Botan::Stream_Cipher_Mode::process | ( | uint8_t | msg[],
|  | size_t | msg_len
| ) |  |
| inline override virtual

Process message blocks

Input must be a multiple of update_granularity

Processes msg in place and returns bytes written. Normally this will be either msg_len (indicating the entire message was processed) or for certain AEAD modes zero (indicating that the mode requires the entire message be processed in one pass).

Parameters

  msg | the message to be processed
  msg_len | length of the message in bytes

Implements Botan::Cipher_Mode.

Definition at line 24 of file stream_mode.h.

25 {
26 m_cipher->cipher1(buf, sz);
27 return sz;
28 }

virtual std::string Botan::Cipher_Mode::provider | ( |  | ) | const
| inline virtual inherited

Returns
  provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Reimplemented in Botan::GCM_Mode.

Definition at line 202 of file cipher_mode.h.

202 { return "base"; }

void Botan::Stream_Cipher_Mode::reset | ( |  | ) |
| inline override virtual

Resets just the message specific state and allows encrypting again under the existing key

Implements Botan::Cipher_Mode.

Definition at line 54 of file stream_mode.h.

54 { /* no msg state */ return; }
template<typename Alloc >

void Botan::Cipher_Mode::set_key | ( | const std::vector< uint8_t, Alloc > & | key | ) |
| inline inherited

Set the symmetric key of this transform

Parameters

  key | contains the key material

Definition at line 172 of file cipher_mode.h.

Referenced by botan_cipher_set_key().

173 {
174 set_key(key.data(), key.size());
175 }
Botan::Cipher_Mode::set_key
void set_key(const std::vector< uint8_t, Alloc > &key)
Definition: cipher_mode.h:172

void Botan::Cipher_Mode::set_key | ( | const SymmetricKey & | key | ) |
| inline inherited

Set the symmetric key of this transform

Parameters

  key | contains the key material

Definition at line 181 of file cipher_mode.h.

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

182 {
183 set_key(key.begin(), key.length());
184 }
Botan::Cipher_Mode::set_key
void set_key(const std::vector< uint8_t, Alloc > &key)
Definition: cipher_mode.h:172

void Botan::Cipher_Mode::set_key | ( | const uint8_t | key[],
|  | size_t | length
| ) |  |
| inline inherited

Set the symmetric key of this transform

Parameters

  key | contains the key material
  length | in bytes of key param

Definition at line 191 of file cipher_mode.h.

192 {
193 if(!valid_keylength(length))
194 throw Invalid_Key_Length(name(), length);
195 key_schedule(key, length);
196 }
Botan::Cipher_Mode::name
virtual std::string name() const =0
Botan::Cipher_Mode::valid_keylength
bool valid_keylength(size_t length) const
Definition: cipher_mode.h:162
template<typename Alloc >

void Botan::Cipher_Mode::start | ( | const std::vector< uint8_t, Alloc > & | nonce | ) |
| inline inherited

Begin processing a message.

Parameters

  nonce | the per message nonce

Definition at line 38 of file cipher_mode.h.

Referenced by botan_cipher_start(), and Botan::TLS::write_record().

39 {
40 start_msg(nonce.data(), nonce.size());
41 }
Botan::Cipher_Mode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0

void Botan::Cipher_Mode::start | ( | const uint8_t | nonce[],
|  | size_t | nonce_len
| ) |  |
| inline inherited

Begin processing a message.

Parameters

  nonce | the per message nonce
  nonce_len | length of nonce

Definition at line 48 of file cipher_mode.h.

49 {
50 start_msg(nonce, nonce_len);
51 }
Botan::Cipher_Mode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0

void Botan::Cipher_Mode::start | ( |  | ) |
| inline inherited

Begin processing a message.

Definition at line 56 of file cipher_mode.h.

57 {
58 return start_msg(nullptr, 0);
59 }
Botan::Cipher_Mode::start_msg
virtual void start_msg(const uint8_t nonce[], size_t nonce_len)=0

virtual size_t Botan::Cipher_Mode::tag_size | ( |  | ) | const
| inline virtual inherited

Returns
  the size of the authentication tag used (in bytes)

Reimplemented in Botan::SIV_Mode, Botan::CCM_Mode, Botan::OCB_Mode, Botan::TLS::TLS_CBC_HMAC_AEAD_Mode, Botan::ChaCha20Poly1305_Mode, Botan::GCM_Mode, and Botan::EAX_Mode.

Definition at line 150 of file cipher_mode.h.

Referenced by botan_cipher_get_tag_length().

150 { return 0; }

void Botan::Cipher_Mode::update | ( | secure_vector< uint8_t > & | buffer,
|  | size_t | offset = `0`
| ) |  |
| inline inherited

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

Parameters

  buffer | in/out parameter which will possibly be resized
  offset | an offset into blocks to begin processing

Definition at line 81 of file cipher_mode.h.

References BOTAN_ASSERT.

Referenced by botan_cipher_update(), Botan::XTS_Encryption::finish(), Botan::ChaCha20Poly1305_Encryption::finish(), Botan::CBC_Encryption::finish(), Botan::CFB_Encryption::finish(), Botan::EAX_Encryption::finish(), Botan::XTS_Decryption::finish(), Botan::CFB_Decryption::finish(), Botan::CTS_Encryption::finish(), Botan::CBC_Decryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::CTS_Decryption::finish(), and Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish().

82 {
83 BOTAN_ASSERT(buffer.size() >= offset, "Offset ok");
84 uint8_t* buf = buffer.data() + offset;
85 const size_t buf_size = buffer.size() - offset;
86
87 const size_t written = process(buf, buf_size);
88 buffer.resize(offset + written);
89 }
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
Botan::Cipher_Mode::process
virtual size_t process(uint8_t msg[], size_t msg_len)=0

size_t Botan::Stream_Cipher_Mode::update_granularity | ( |  | ) | const
| inline override virtual

Returns
  size of required blocks to update

Implements Botan::Cipher_Mode.

Definition at line 35 of file stream_mode.h.

35 { return 1; }

bool Botan::Cipher_Mode::valid_keylength | ( | size_t | length | ) | const
| inline inherited

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

Parameters

  length | the key length to be checked.

Returns
  true if the key length is valid.

Definition at line 162 of file cipher_mode.h.

163 {
164 return key_spec().valid_keylength(length);
165 }
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: key_spec.h:51
Botan::Cipher_Mode::key_spec
virtual Key_Length_Specification key_spec() const =0

bool Botan::Stream_Cipher_Mode::valid_nonce_length | ( | size_t | nonce_len | ) | const
| inline override virtual

Returns
  true iff nonce_len is a valid length for the nonce

Implements Botan::Cipher_Mode.

Definition at line 41 of file stream_mode.h.

42 { return m_cipher->valid_iv_length(nonce_len); }

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

- src/lib/modes/stream_mode.h