Botan
1.11.15
|
#include <cbc.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
virtual bool | authenticated () const |
CBC_Decryption (BlockCipher *cipher, BlockCipherModePaddingMethod *padding) | |
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< byte > | start (const std::vector< byte, Alloc > &nonce) |
secure_vector< byte > | start (const byte nonce[], size_t nonce_len) |
secure_vector< byte > | start () |
template<typename Alloc > | |
secure_vector< byte > | start_vec (const std::vector< byte, Alloc > &nonce) |
virtual size_t | tag_size () const |
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 BlockCipher & | cipher () const |
const BlockCipherModePaddingMethod & | padding () const |
secure_vector< byte > & | state () |
byte * | state_ptr () |
typedef SCAN_Name Botan::Transform::Spec [inherited] |
Definition at line 27 of file transform.h.
Botan::CBC_Decryption::CBC_Decryption | ( | BlockCipher * | cipher, |
BlockCipherModePaddingMethod * | padding | ||
) | [inline] |
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 26 of file cipher_mode.h.
{ return false; }
const BlockCipher& Botan::CBC_Mode::cipher | ( | ) | const [inline, protected, inherited] |
Definition at line 37 of file cbc.h.
Referenced by Botan::CBC_Mode::default_nonce_length(), Botan::CBC_Encryption::finish(), Botan::CTS_Encryption::finish(), finish(), Botan::CTS_Decryption::finish(), Botan::CBC_Mode::key_spec(), Botan::CTS_Encryption::minimum_final_size(), minimum_final_size(), Botan::CTS_Decryption::minimum_final_size(), Botan::CBC_Mode::name(), Botan::CBC_Encryption::output_length(), Botan::CBC_Encryption::update(), update(), Botan::CBC_Mode::update_granularity(), Botan::CBC_Mode::valid_nonce_length(), Botan::CTS_Encryption::valid_nonce_length(), and Botan::CTS_Decryption::valid_nonce_length().
{ return *m_cipher; }
void Botan::CBC_Mode::clear | ( | ) | [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 46 of file cbc.cpp.
{ m_cipher->clear(); m_state.clear(); }
size_t Botan::CBC_Mode::default_nonce_length | ( | ) | const [override, virtual, inherited] |
Return the default size for a nonce
Implements Botan::Transform.
Definition at line 70 of file cbc.cpp.
References Botan::BlockCipher::block_size(), and Botan::CBC_Mode::cipher().
{ return cipher().block_size(); }
void Botan::CBC_Decryption::finish | ( | secure_vector< byte > & | final_block, |
size_t | offset = 0 |
||
) | [override, virtual] |
Complete processing of a message.
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::Transform.
Reimplemented in Botan::CTS_Decryption.
Definition at line 250 of file cbc.cpp.
References Botan::BlockCipher::block_size(), BOTAN_ASSERT, Botan::CBC_Mode::cipher(), Botan::CBC_Mode::name(), Botan::CBC_Mode::padding(), Botan::BlockCipherModePaddingMethod::unpad(), and update().
{ BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; const size_t BS = cipher().block_size(); if(sz == 0 || sz % BS) throw Decoding_Error(name() + ": Ciphertext not a multiple of block size"); update(buffer, offset); const size_t pad_bytes = BS - padding().unpad(&buffer[buffer.size()-BS], BS); buffer.resize(buffer.size() - pad_bytes); // remove padding }
Key_Length_Specification Botan::CBC_Mode::key_spec | ( | ) | const [override, virtual, inherited] |
Implements Botan::Keyed_Transform.
Definition at line 65 of file cbc.cpp.
References Botan::CBC_Mode::cipher(), and Botan::SymmetricAlgorithm::key_spec().
size_t Botan::CBC_Decryption::minimum_final_size | ( | ) | const [override, virtual] |
Implements Botan::Transform.
Reimplemented in Botan::CTS_Decryption.
Definition at line 217 of file cbc.cpp.
References Botan::BlockCipher::block_size(), and Botan::CBC_Mode::cipher().
{ return cipher().block_size(); }
std::string Botan::CBC_Mode::name | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 52 of file cbc.cpp.
References Botan::CBC_Mode::cipher(), Botan::BlockCipherModePaddingMethod::name(), Botan::SymmetricAlgorithm::name(), and Botan::CBC_Mode::padding().
Referenced by Botan::CBC_Encryption::finish(), Botan::CTS_Encryption::finish(), finish(), and Botan::CTS_Decryption::finish().
size_t Botan::CBC_Decryption::output_length | ( | size_t | input_length | ) | const [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::Transform.
Definition at line 212 of file cbc.cpp.
{ return input_length; // precise for CTS, worst case otherwise }
const BlockCipherModePaddingMethod& Botan::CBC_Mode::padding | ( | ) | const [inline, protected, inherited] |
Definition at line 39 of file cbc.h.
References BOTAN_ASSERT_NONNULL.
Referenced by Botan::CBC_Encryption::finish(), finish(), and Botan::CBC_Mode::name().
{ BOTAN_ASSERT_NONNULL(m_padding); return *m_padding; }
virtual std::string Botan::Transform::provider | ( | ) | const [inline, virtual, inherited] |
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 120 of file transform.h.
{ return "core"; }
void Botan::Keyed_Transform::set_key | ( | const std::vector< byte, Alloc > & | key | ) | [inline, inherited] |
Definition at line 148 of file transform.h.
Referenced by botan_cipher_set_key().
{ set_key(&key[0], key.size()); }
void Botan::Keyed_Transform::set_key | ( | const SymmetricKey & | key | ) | [inline, inherited] |
Definition at line 153 of file transform.h.
References Botan::OctetString::begin(), and Botan::OctetString::length().
{ set_key(key.begin(), key.length()); }
void Botan::Keyed_Transform::set_key | ( | const byte | key[], |
size_t | length | ||
) | [inline, inherited] |
Set the symmetric key of this transform
key | contains the key material |
length | in bytes of key param |
Definition at line 163 of file transform.h.
{ if(!valid_keylength(length)) throw Invalid_Key_Length(name(), length); key_schedule(key, length); }
secure_vector<byte> Botan::Transform::start | ( | const std::vector< byte, Alloc > & | nonce | ) | [inline, inherited] |
Begin processing a message.
nonce | the per message nonce |
Definition at line 34 of file transform.h.
Referenced by botan_cipher_start().
{ return start(&nonce[0], nonce.size()); }
secure_vector<byte> Botan::Transform::start | ( | const byte | nonce[], |
size_t | nonce_len | ||
) | [inline, inherited] |
Begin processing a message.
nonce | the per message nonce |
nonce_len | length of nonce |
Definition at line 55 of file transform.h.
{ return start_raw(nonce, nonce_len); }
secure_vector<byte> Botan::Transform::start | ( | ) | [inline, inherited] |
Begin processing a message.
Definition at line 63 of file transform.h.
{ return start_raw(nullptr, 0); }
secure_vector<byte> Botan::Transform::start_vec | ( | const std::vector< byte, Alloc > & | nonce | ) | [inline, inherited] |
Begin processing a message.
nonce | the per message nonce |
Definition at line 45 of file transform.h.
{ return start(&nonce[0], nonce.size()); }
secure_vector<byte>& Botan::CBC_Mode::state | ( | ) | [inline, protected, inherited] |
Definition at line 45 of file cbc.h.
Referenced by Botan::CBC_Encryption::update().
{ return m_state; }
byte* Botan::CBC_Mode::state_ptr | ( | ) | [inline, protected, inherited] |
Definition at line 47 of file cbc.h.
Referenced by Botan::CTS_Encryption::finish(), Botan::CTS_Decryption::finish(), Botan::CBC_Encryption::update(), and update().
{ return &m_state[0]; }
virtual size_t Botan::Cipher_Mode::tag_size | ( | ) | const [inline, virtual, inherited] |
Return the size of the authentication tag used (in bytes)
Reimplemented in Botan::SIV_Mode, Botan::CCM_Mode, Botan::OCB_Mode, Botan::ChaCha20Poly1305_Mode, Botan::GCM_Mode, and Botan::EAX_Mode.
Definition at line 31 of file cipher_mode.h.
Referenced by botan_cipher_get_tag_length().
{ return 0; }
void Botan::CBC_Decryption::update | ( | secure_vector< byte > & | blocks, |
size_t | offset = 0 |
||
) | [override, virtual] |
Process some data. Input must be in size update_granularity() byte blocks.
blocks | in/out paramter which will possibly be resized |
offset | an offset into blocks to begin processing |
Implements Botan::Transform.
Definition at line 222 of file cbc.cpp.
References Botan::BlockCipher::block_size(), BOTAN_ASSERT, Botan::CBC_Mode::cipher(), Botan::copy_mem(), Botan::BlockCipher::decrypt_n(), Botan::CBC_Mode::state_ptr(), and Botan::xor_buf().
Referenced by finish(), and Botan::CTS_Decryption::finish().
{ BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; byte* buf = &buffer[offset]; const size_t BS = cipher().block_size(); BOTAN_ASSERT(sz % BS == 0, "Input is full blocks"); size_t blocks = sz / BS; while(blocks) { const size_t to_proc = std::min(BS * blocks, m_tempbuf.size()); cipher().decrypt_n(buf, &m_tempbuf[0], to_proc / BS); xor_buf(&m_tempbuf[0], state_ptr(), BS); xor_buf(&m_tempbuf[BS], buf, to_proc - BS); copy_mem(state_ptr(), buf + (to_proc - BS), BS); copy_mem(buf, &m_tempbuf[0], to_proc); buf += to_proc; blocks -= to_proc / BS; } }
size_t Botan::CBC_Mode::update_granularity | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 60 of file cbc.cpp.
References Botan::CBC_Mode::cipher(), and Botan::BlockCipher::parallel_bytes().
{ return cipher().parallel_bytes(); }
bool Botan::Keyed_Transform::valid_keylength | ( | size_t | length | ) | const [inline, inherited] |
Check whether a given key length is valid for this algorithm.
length | the key length to be checked. |
Definition at line 142 of file transform.h.
References Botan::Key_Length_Specification::valid_keylength().
{ return key_spec().valid_keylength(length); }
bool Botan::CBC_Mode::valid_nonce_length | ( | size_t | nonce_len | ) | const [override, virtual, inherited] |
Return true iff nonce_len is a valid length for the nonce
Implements Botan::Transform.
Reimplemented in Botan::CTS_Decryption, and Botan::CTS_Encryption.
Definition at line 75 of file cbc.cpp.
References Botan::CBC_Mode::cipher().