Botan
1.11.15
|
#include <salsa20.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
void | cipher (const byte in[], byte out[], size_t length) |
void | cipher1 (byte buf[], size_t len) |
void | clear () |
StreamCipher * | clone () 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 |
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 |
typedef SCAN_Name Botan::StreamCipher::Spec [inherited] |
Definition at line 73 of file stream_cipher.h.
void Botan::Salsa20::cipher | ( | const byte | in[], |
byte | out[], | ||
size_t | len | ||
) | [virtual] |
Encrypt or decrypt a message
in | the plaintext |
out | the byte array to hold the output, i.e. the ciphertext |
len | the length of both in and out in bytes |
Implements Botan::StreamCipher.
Definition at line 106 of file salsa20.cpp.
References Botan::xor_buf().
{ while(length >= m_buffer.size() - m_position) { xor_buf(out, in, &m_buffer[m_position], m_buffer.size() - m_position); length -= (m_buffer.size() - m_position); in += (m_buffer.size() - m_position); out += (m_buffer.size() - m_position); salsa20(&m_buffer[0], &m_state[0]); ++m_state[8]; m_state[9] += (m_state[8] == 0); m_position = 0; } xor_buf(out, in, &m_buffer[m_position], length); m_position += length; }
void Botan::StreamCipher::cipher1 | ( | byte | buf[], |
size_t | len | ||
) | [inline, inherited] |
Encrypt or decrypt a message
buf | the plaintext / ciphertext |
len | the length of buf in bytes |
Definition at line 36 of file stream_cipher.h.
Referenced by Botan::SIV_Encryption::finish().
{ cipher(buf, buf, len); }
void Botan::Salsa20::clear | ( | ) | [virtual] |
Implements Botan::SymmetricAlgorithm.
Definition at line 225 of file salsa20.cpp.
References Botan::zap().
StreamCipher* Botan::Salsa20::clone | ( | ) | const [inline, virtual] |
Get a new object representing the same algorithm as *this
Implements Botan::StreamCipher.
Definition at line 35 of file salsa20.h.
{ return new Salsa20; }
void Botan::StreamCipher::decrypt | ( | std::vector< byte, Alloc > & | inout | ) | [inline, inherited] |
Definition at line 48 of file stream_cipher.h.
{ cipher(&inout[0], &inout[0], inout.size()); }
void Botan::StreamCipher::encipher | ( | std::vector< byte, Alloc > & | inout | ) | [inline, inherited] |
Definition at line 40 of file stream_cipher.h.
{ cipher(&inout[0], &inout[0], inout.size()); }
void Botan::StreamCipher::encrypt | ( | std::vector< byte, Alloc > & | inout | ) | [inline, inherited] |
Definition at line 44 of file stream_cipher.h.
{ cipher(&inout[0], &inout[0], inout.size()); }
Key_Length_Specification Botan::Salsa20::key_spec | ( | ) | const [inline, virtual] |
Implements Botan::SymmetricAlgorithm.
Definition at line 28 of file salsa20.h.
{
return Key_Length_Specification(16, 32, 16);
}
size_t Botan::SymmetricAlgorithm::maximum_keylength | ( | ) | const [inline, inherited] |
Definition at line 36 of file sym_algo.h.
References Botan::Key_Length_Specification::maximum_keylength().
{ return key_spec().maximum_keylength(); }
size_t Botan::SymmetricAlgorithm::minimum_keylength | ( | ) | const [inline, inherited] |
Definition at line 44 of file sym_algo.h.
{ return key_spec().minimum_keylength(); }
std::string Botan::Salsa20::name | ( | ) | const [virtual] |
Implements Botan::SymmetricAlgorithm.
Definition at line 217 of file salsa20.cpp.
Referenced by set_iv().
{ return "Salsa20"; }
void Botan::Salsa20::set_iv | ( | const byte | [], |
size_t | iv_len | ||
) | [virtual] |
Resync the cipher using the IV
iv | the initialization vector |
iv_len | the length of the IV in bytes |
Reimplemented from Botan::StreamCipher.
Definition at line 170 of file salsa20.cpp.
References Botan::load_le< u32bit >(), name(), and valid_iv_length().
{ if(!valid_iv_length(length)) throw Invalid_IV_Length(name(), length); if(length == 8) { // Salsa20 m_state[6] = load_le<u32bit>(iv, 0); m_state[7] = load_le<u32bit>(iv, 1); } else { // XSalsa20 m_state[6] = load_le<u32bit>(iv, 0); m_state[7] = load_le<u32bit>(iv, 1); m_state[8] = load_le<u32bit>(iv, 2); m_state[9] = load_le<u32bit>(iv, 3); secure_vector<u32bit> hsalsa(8); hsalsa20(&hsalsa[0], &m_state[0]); m_state[ 1] = hsalsa[0]; m_state[ 2] = hsalsa[1]; m_state[ 3] = hsalsa[2]; m_state[ 4] = hsalsa[3]; m_state[ 6] = load_le<u32bit>(iv, 4); m_state[ 7] = load_le<u32bit>(iv, 5); m_state[11] = hsalsa[4]; m_state[12] = hsalsa[5]; m_state[13] = hsalsa[6]; m_state[14] = hsalsa[7]; } m_state[8] = 0; m_state[9] = 0; salsa20(&m_buffer[0], &m_state[0]); ++m_state[8]; m_state[9] += (m_state[8] == 0); m_position = 0; }
void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) | [inline, inherited] |
Set the symmetric key of this object.
key | the 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_set_key(), Botan::TLS::Session::decrypt(), Botan::TLS::Session::encrypt(), and Botan::pbkdf2().
{ set_key(key.begin(), key.length()); }
void Botan::SymmetricAlgorithm::set_key | ( | const std::vector< byte, Alloc > & | key | ) | [inline, inherited] |
Definition at line 69 of file sym_algo.h.
{ set_key(&key[0], key.size()); }
void Botan::SymmetricAlgorithm::set_key | ( | const byte | key[], |
size_t | length | ||
) | [inline, inherited] |
Set the symmetric key of this object.
key | the to be set as a byte array. |
length | in bytes of key param |
Definition at line 79 of file sym_algo.h.
{ if(!valid_keylength(length)) throw Invalid_Key_Length(name(), length); key_schedule(key, length); }
bool Botan::Salsa20::valid_iv_length | ( | size_t | iv_len | ) | const [inline, virtual] |
iv_len | the length of the IV in bytes |
Reimplemented from Botan::StreamCipher.
Definition at line 25 of file salsa20.h.
Referenced by set_iv().
{ return (iv_len == 8 || iv_len == 24); }
bool Botan::SymmetricAlgorithm::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 54 of file sym_algo.h.
Referenced by Botan::aont_package(), and Botan::aont_unpackage().
{ return key_spec().valid_keylength(length); }