Botan
1.11.15
|
#include <ocb.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
bool | authenticated () const override |
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 |
OCB_Decryption (BlockCipher *cipher, size_t tag_size=16) | |
size_t | output_length (size_t input_length) const override |
virtual std::string | provider () const |
template<typename Alloc > | |
void | set_ad (const std::vector< byte, Alloc > &ad) |
void | set_associated_data (const byte ad[], size_t ad_len) override |
template<typename Alloc > | |
void | set_associated_data_vec (const std::vector< byte, Alloc > &ad) |
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) |
size_t | tag_size () const override |
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) const override |
Protected Member Functions | |
size_t | BS () const |
Protected Attributes | |
secure_vector< byte > | m_ad_hash |
size_t | m_block_index = 0 |
size_t | m_BS |
secure_vector< byte > | m_checksum |
std::unique_ptr< BlockCipher > | m_cipher |
std::unique_ptr< L_computer > | m_L |
secure_vector< byte > | m_offset |
typedef SCAN_Name Botan::Transform::Spec [inherited] |
Definition at line 27 of file transform.h.
Botan::OCB_Decryption::OCB_Decryption | ( | BlockCipher * | cipher, |
size_t | tag_size = 16 |
||
) | [inline] |
bool Botan::AEAD_Mode::authenticated | ( | ) | const [inline, override, virtual, inherited] |
Returns true iff this mode provides authentication as well as confidentiality.
Reimplemented from Botan::Cipher_Mode.
Definition at line 25 of file aead.h.
{ return true; }
size_t Botan::OCB_Mode::BS | ( | ) | const [inline, protected, inherited] |
Definition at line 52 of file ocb.h.
Referenced by Botan::OCB_Encryption::finish(), finish(), Botan::OCB_Mode::OCB_Mode(), Botan::OCB_Encryption::update(), and update().
{ return m_BS; }
void Botan::OCB_Mode::clear | ( | ) | [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 138 of file ocb.cpp.
References Botan::OCB_Mode::m_ad_hash, Botan::OCB_Mode::m_checksum, Botan::OCB_Mode::m_cipher, Botan::OCB_Mode::m_L, Botan::OCB_Mode::m_offset, and Botan::zeroise().
size_t Botan::AEAD_Mode::default_nonce_length | ( | ) | const [inline, override, virtual, inherited] |
Default AEAD nonce size (a commonly supported value among AEAD modes, and large enough that random collisions are unlikely).
Implements Botan::Transform.
Reimplemented in Botan::CCM_Mode.
Definition at line 57 of file aead.h.
{ return 12; }
void Botan::OCB_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 359 of file ocb.cpp.
References BOTAN_ASSERT, Botan::OCB_Mode::BS(), Botan::OCB_Mode::m_ad_hash, Botan::OCB_Mode::m_block_index, Botan::OCB_Mode::m_checksum, Botan::OCB_Mode::m_cipher, Botan::OCB_Mode::m_L, Botan::OCB_Mode::m_offset, mac, Botan::same_mem(), Botan::OCB_Mode::tag_size(), Botan::xor_buf(), and Botan::zeroise().
{ BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; byte* buf = &buffer[offset]; BOTAN_ASSERT(sz >= tag_size(), "We have the tag"); const size_t remaining = sz - tag_size(); if(remaining) { const size_t final_full_blocks = remaining / BS(); const size_t final_bytes = remaining - (final_full_blocks * BS()); decrypt(&buf[0], final_full_blocks); if(final_bytes) { BOTAN_ASSERT(final_bytes < BS(), "Only a partial block left"); byte* remainder = &buf[remaining - final_bytes]; m_offset ^= m_L->star(); // Offset_* secure_vector<byte> pad(BS()); m_cipher->encrypt(m_offset, pad); // P_* xor_buf(&remainder[0], &pad[0], final_bytes); xor_buf(&m_checksum[0], &remainder[0], final_bytes); m_checksum[final_bytes] ^= 0x80; } } secure_vector<byte> checksum(BS()); // fold checksum for(size_t i = 0; i != m_checksum.size(); ++i) checksum[i % checksum.size()] ^= m_checksum[i]; // compute the mac secure_vector<byte> mac = m_offset; mac ^= checksum; mac ^= m_L->dollar(); m_cipher->encrypt(mac); mac ^= m_ad_hash; // reset state zeroise(m_checksum); zeroise(m_offset); m_block_index = 0; // compare mac const byte* included_tag = &buf[remaining]; if(!same_mem(&mac[0], included_tag, tag_size())) throw Integrity_Failure("OCB tag check failed"); // remove tag from end of message buffer.resize(remaining + offset); }
Key_Length_Specification Botan::OCB_Mode::key_spec | ( | ) | const [override, virtual, inherited] |
Implements Botan::Keyed_Transform.
Definition at line 163 of file ocb.cpp.
References Botan::OCB_Mode::m_cipher.
{ return m_cipher->key_spec(); }
size_t Botan::OCB_Decryption::minimum_final_size | ( | ) | const [inline, override, virtual] |
Implements Botan::Transform.
Definition at line 114 of file ocb.h.
{ return tag_size(); }
std::string Botan::OCB_Mode::name | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 153 of file ocb.cpp.
References Botan::OCB_Mode::m_cipher.
{ return m_cipher->name() + "/OCB"; // include tag size }
size_t Botan::OCB_Decryption::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::Transform.
Definition at line 108 of file ocb.h.
References BOTAN_ASSERT.
{ BOTAN_ASSERT(input_length > tag_size(), "Sufficient input"); return input_length - tag_size(); }
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::AEAD_Mode::set_ad | ( | const std::vector< byte, Alloc > & | ad | ) | [inline, inherited] |
Definition at line 48 of file aead.h.
{ set_associated_data(&ad[0], ad.size()); }
void Botan::OCB_Mode::set_associated_data | ( | const byte | ad[], |
size_t | ad_len | ||
) | [override, virtual, inherited] |
Set associated data that is not included in the ciphertext but that should be authenticated. Must be called after set_key and before start.
Unless reset by another call, the associated data is kept between messages. Thus, if the AD does not change, calling once (after set_key) is the optimum.
ad | the associated data |
ad_len | length of add in bytes |
Implements Botan::AEAD_Mode.
Definition at line 174 of file ocb.cpp.
References BOTAN_ASSERT, Botan::OCB_Mode::m_ad_hash, Botan::OCB_Mode::m_cipher, and Botan::OCB_Mode::m_L.
{ BOTAN_ASSERT(m_L, "A key was set"); m_ad_hash = ocb_hash(*m_L, *m_cipher, &ad[0], ad_len); }
void Botan::AEAD_Mode::set_associated_data_vec | ( | const std::vector< byte, Alloc > & | ad | ) | [inline, inherited] |
Definition at line 42 of file aead.h.
{ set_associated_data(&ad[0], ad.size()); }
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()); }
size_t Botan::OCB_Mode::tag_size | ( | ) | const [inline, override, virtual, inherited] |
Return the size of the authentication tag used (in bytes)
Reimplemented from Botan::Cipher_Mode.
Definition at line 40 of file ocb.h.
Referenced by Botan::OCB_Encryption::finish(), and finish().
{ return m_tag_size; }
void Botan::OCB_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 348 of file ocb.cpp.
References BOTAN_ASSERT, and Botan::OCB_Mode::BS().
{ BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane"); const size_t sz = buffer.size() - offset; byte* buf = &buffer[offset]; BOTAN_ASSERT(sz % BS() == 0, "Input length is an even number of blocks"); decrypt(buf, sz / BS()); }
size_t Botan::OCB_Mode::update_granularity | ( | ) | const [override, virtual, inherited] |
Implements Botan::Transform.
Definition at line 158 of file ocb.cpp.
References Botan::OCB_Mode::m_cipher.
{ return m_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::OCB_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 148 of file ocb.cpp.
{
return (length > 0 && length < m_cipher->block_size());
}
secure_vector<byte> Botan::OCB_Mode::m_ad_hash [protected, inherited] |
Definition at line 63 of file ocb.h.
Referenced by Botan::OCB_Mode::clear(), Botan::OCB_Encryption::finish(), finish(), and Botan::OCB_Mode::set_associated_data().
size_t Botan::OCB_Mode::m_block_index = 0 [protected, inherited] |
Definition at line 59 of file ocb.h.
Referenced by Botan::OCB_Encryption::finish(), and finish().
size_t Botan::OCB_Mode::m_BS [protected, inherited] |
secure_vector<byte> Botan::OCB_Mode::m_checksum [protected, inherited] |
Definition at line 61 of file ocb.h.
Referenced by Botan::OCB_Mode::clear(), Botan::OCB_Encryption::finish(), and finish().
std::unique_ptr<BlockCipher> Botan::OCB_Mode::m_cipher [protected, inherited] |
Definition at line 55 of file ocb.h.
Referenced by Botan::OCB_Mode::clear(), Botan::OCB_Encryption::finish(), finish(), Botan::OCB_Mode::key_spec(), Botan::OCB_Mode::name(), Botan::OCB_Mode::OCB_Mode(), Botan::OCB_Mode::set_associated_data(), and Botan::OCB_Mode::update_granularity().
std::unique_ptr<L_computer> Botan::OCB_Mode::m_L [protected, inherited] |
Definition at line 56 of file ocb.h.
Referenced by Botan::OCB_Mode::clear(), Botan::OCB_Encryption::finish(), finish(), and Botan::OCB_Mode::set_associated_data().
secure_vector<byte> Botan::OCB_Mode::m_offset [protected, inherited] |
Definition at line 62 of file ocb.h.
Referenced by Botan::OCB_Mode::clear(), Botan::OCB_Encryption::finish(), and finish().