Botan
1.11.15
|
#include <xts.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
virtual bool | authenticated () const |
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 |
XTS_Decryption (BlockCipher *cipher) | |
Protected Member Functions | |
const BlockCipher & | cipher () const |
const byte * | tweak () const |
void | update_tweak (size_t last_used) |
typedef SCAN_Name Botan::Transform::Spec [inherited] |
Definition at line 27 of file transform.h.
Botan::XTS_Decryption::XTS_Decryption | ( | BlockCipher * | cipher | ) | [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::XTS_Mode::cipher | ( | ) | const [inline, protected, inherited] |
Definition at line 40 of file xts.h.
Referenced by Botan::XTS_Mode::default_nonce_length(), Botan::XTS_Encryption::finish(), finish(), Botan::XTS_Mode::key_spec(), Botan::XTS_Mode::minimum_final_size(), Botan::XTS_Mode::name(), Botan::XTS_Encryption::output_length(), Botan::XTS_Encryption::update(), update(), Botan::XTS_Mode::update_granularity(), and Botan::XTS_Mode::valid_nonce_length().
{ return *m_cipher; }
void Botan::XTS_Mode::clear | ( | ) | [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 62 of file xts.cpp.
References Botan::zeroise().
{ m_cipher->clear(); m_tweak_cipher->clear(); zeroise(m_tweak); }
size_t Botan::XTS_Mode::default_nonce_length | ( | ) | const [override, virtual, inherited] |
Return the default size for a nonce
Implements Botan::Transform.
Definition at line 89 of file xts.cpp.
References Botan::BlockCipher::block_size(), and Botan::XTS_Mode::cipher().
{ return cipher().block_size(); }
void Botan::XTS_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.
Definition at line 249 of file xts.cpp.
References Botan::BlockCipher::block_size(), BOTAN_ASSERT, Botan::XTS_Mode::cipher(), Botan::BlockCipher::decrypt(), Botan::XTS_Mode::minimum_final_size(), Botan::XTS_Mode::tweak(), update(), and Botan::xor_buf().
{ BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; byte* buf = &buffer[offset]; BOTAN_ASSERT(sz >= minimum_final_size(), "Have sufficient final input"); const size_t BS = cipher().block_size(); if(sz % BS == 0) { update(buffer, offset); } else { // steal ciphertext const size_t full_blocks = ((sz / BS) - 1) * BS; const size_t final_bytes = sz - full_blocks; BOTAN_ASSERT(final_bytes > BS && final_bytes < 2*BS, "Left over size in expected range"); secure_vector<byte> last(buf + full_blocks, buf + full_blocks + final_bytes); buffer.resize(full_blocks + offset); update(buffer, offset); xor_buf(last, tweak() + BS, BS); cipher().decrypt(last); xor_buf(last, tweak() + BS, BS); for(size_t i = 0; i != final_bytes - BS; ++i) { last[i] ^= last[i + BS]; last[i + BS] ^= last[i]; last[i] ^= last[i + BS]; } xor_buf(last, tweak(), BS); cipher().decrypt(last); xor_buf(last, tweak(), BS); buffer += last; } }
Key_Length_Specification Botan::XTS_Mode::key_spec | ( | ) | const [override, virtual, inherited] |
Implements Botan::Keyed_Transform.
Definition at line 84 of file xts.cpp.
References Botan::XTS_Mode::cipher(), Botan::SymmetricAlgorithm::key_spec(), and Botan::Key_Length_Specification::multiple().
size_t Botan::XTS_Mode::minimum_final_size | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 79 of file xts.cpp.
References Botan::BlockCipher::block_size(), and Botan::XTS_Mode::cipher().
Referenced by Botan::XTS_Encryption::finish(), and finish().
{ return cipher().block_size() + 1; }
std::string Botan::XTS_Mode::name | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 69 of file xts.cpp.
References Botan::XTS_Mode::cipher(), and Botan::SymmetricAlgorithm::name().
size_t Botan::XTS_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 214 of file xts.cpp.
{ // might be less return input_length; }
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()); }
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; }
const byte* Botan::XTS_Mode::tweak | ( | ) | const [inline, protected, inherited] |
Definition at line 38 of file xts.h.
Referenced by Botan::XTS_Encryption::finish(), finish(), Botan::XTS_Encryption::update(), and update().
{ return &m_tweak[0]; }
void Botan::XTS_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 220 of file xts.cpp.
References Botan::BlockCipher::block_size(), BOTAN_ASSERT, Botan::XTS_Mode::cipher(), Botan::BlockCipher::decrypt_n(), Botan::XTS_Mode::tweak(), Botan::XTS_Mode::update_granularity(), Botan::XTS_Mode::update_tweak(), and Botan::xor_buf().
Referenced by 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; const size_t blocks_in_tweak = update_granularity() / BS; while(blocks) { const size_t to_proc = std::min(blocks, blocks_in_tweak); const size_t to_proc_bytes = to_proc * BS; xor_buf(buf, tweak(), to_proc_bytes); cipher().decrypt_n(buf, buf, to_proc); xor_buf(buf, tweak(), to_proc_bytes); buf += to_proc * BS; blocks -= to_proc; update_tweak(to_proc); } }
size_t Botan::XTS_Mode::update_granularity | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 74 of file xts.cpp.
References Botan::XTS_Mode::cipher(), and Botan::BlockCipher::parallel_bytes().
Referenced by Botan::XTS_Encryption::update(), update(), Botan::XTS_Mode::update_tweak(), and Botan::XTS_Mode::XTS_Mode().
{ return cipher().parallel_bytes(); }
void Botan::XTS_Mode::update_tweak | ( | size_t | last_used | ) | [protected, inherited] |
Definition at line 123 of file xts.cpp.
References Botan::XTS_Mode::update_granularity().
Referenced by Botan::XTS_Encryption::update(), and update().
{ const size_t BS = m_tweak_cipher->block_size(); if(which > 0) poly_double(&m_tweak[0], &m_tweak[(which-1)*BS], BS); const size_t blocks_in_tweak = update_granularity() / BS; for(size_t i = 1; i < blocks_in_tweak; ++i) poly_double(&m_tweak[i*BS], &m_tweak[(i-1)*BS], BS); }
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::XTS_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.
Definition at line 94 of file xts.cpp.
References Botan::BlockCipher::block_size(), Botan::XTS_Mode::cipher(), and n.
{ return cipher().block_size() == n; }