#include <salsa20.h>
DJB's Salsa20 (and XSalsa20)
Definition at line 18 of file salsa20.h.
void Botan::Salsa20::cipher |
( |
const uint8_t |
in[], |
|
|
uint8_t |
out[], |
|
|
size_t |
len |
|
) |
| |
|
overridevirtual |
Encrypt or decrypt a message
- Parameters
-
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 104 of file salsa20.cpp.
References Botan::xor_buf().
106 while(length >= m_buffer.size() - m_position)
108 xor_buf(out, in, &m_buffer[m_position], m_buffer.size() - m_position);
109 length -= (m_buffer.size() - m_position);
110 in += (m_buffer.size() - m_position);
111 out += (m_buffer.size() - m_position);
112 salsa20(m_buffer.data(), m_state.data());
115 m_state[9] += (m_state[8] == 0);
120 xor_buf(out, in, &m_buffer[m_position], length);
122 m_position += length;
void xor_buf(T out[], const T in[], size_t length)
void Botan::StreamCipher::cipher1 |
( |
uint8_t |
buf[], |
|
|
size_t |
len |
|
) |
| |
|
inlineinherited |
Encrypt or decrypt a message The message is encrypted/decrypted in place.
- Parameters
-
buf | the plaintext / ciphertext |
len | the length of buf in bytes |
Definition at line 65 of file stream_cipher.h.
Referenced by Botan::SIV_Encryption::finish().
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len)=0
void Botan::Salsa20::clear |
( |
| ) |
|
|
overridevirtual |
- Returns
- a new object representing the same algorithm as *this
Implements Botan::StreamCipher.
Definition at line 35 of file salsa20.h.
35 {
return new Salsa20; }
std::unique_ptr< StreamCipher > Botan::StreamCipher::create |
( |
const std::string & |
algo_spec, |
|
|
const std::string & |
provider = "" |
|
) |
| |
|
staticinherited |
Create an instance based on a name If provider is empty then best available is chosen.
- Parameters
-
algo_spec | algorithm name |
provider | provider implementation to use |
- Returns
- a null pointer if the algo/provider combination cannot be found
Definition at line 41 of file stream_cipher.cpp.
References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), BOTAN_UNUSED, and Botan::BlockCipher::create().
Referenced by Botan::BlockCipher::create(), Botan::StreamCipher::create_or_throw(), Botan::get_cipher_mode(), and Botan::get_stream_cipher().
44 const SCAN_Name req(algo_spec);
46 #if defined(BOTAN_HAS_CTR_BE)
47 if(req.algo_name() ==
"CTR-BE" && req.arg_count() == 1)
52 return std::unique_ptr<StreamCipher>(
new CTR_BE(c.release()));
57 #if defined(BOTAN_HAS_CHACHA)
58 if(req.algo_name() ==
"ChaCha")
61 return std::unique_ptr<StreamCipher>(
new ChaCha(req.arg_as_integer(0, 20)));
65 #if defined(BOTAN_HAS_SALSA20)
66 if(req.algo_name() ==
"Salsa20")
69 return std::unique_ptr<StreamCipher>(
new Salsa20);
73 #if defined(BOTAN_HAS_SHAKE_CIPHER)
74 if(req.algo_name() ==
"SHAKE-128")
77 return std::unique_ptr<StreamCipher>(
new SHAKE_128_Cipher);
81 #if defined(BOTAN_HAS_OFB)
82 if(req.algo_name() ==
"OFB" && req.arg_count() == 1)
87 return std::unique_ptr<StreamCipher>(
new OFB(c.release()));
92 #if defined(BOTAN_HAS_RC4)
94 if(req.algo_name() ==
"RC4" ||
95 req.algo_name() ==
"ARC4" ||
96 req.algo_name() ==
"MARK-4")
98 const size_t skip = (req.algo_name() ==
"MARK-4") ? 256 : req.arg_as_integer(0, 0);
100 #if defined(BOTAN_HAS_OPENSSL)
103 return std::unique_ptr<StreamCipher>(make_openssl_rc4(skip));
109 return std::unique_ptr<StreamCipher>(
new RC4(skip));
virtual std::string provider() const
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
std::unique_ptr< StreamCipher > Botan::StreamCipher::create_or_throw |
( |
const std::string & |
algo_spec, |
|
|
const std::string & |
provider = "" |
|
) |
| |
|
staticinherited |
Create an instance based on a name If provider is empty then best available is chosen.
- Parameters
-
algo_spec | algorithm name |
provider | provider implementation to use Throws a Lookup_Error if the algo/provider combination cannot be found |
Definition at line 123 of file stream_cipher.cpp.
References Botan::StreamCipher::create().
Referenced by Botan::make_stream_cipher().
130 throw Lookup_Error(
"Stream cipher", algo,
provider);
virtual std::string provider() const
static std::unique_ptr< StreamCipher > create(const std::string &algo_spec, const std::string &provider="")
template<typename Alloc >
void Botan::StreamCipher::decrypt |
( |
std::vector< uint8_t, Alloc > & |
inout | ) |
|
|
inlineinherited |
Decrypt a message in place The message is decrypted in place.
- Parameters
-
inout | the plaintext / ciphertext |
Definition at line 92 of file stream_cipher.h.
93 {
cipher(inout.data(), inout.data(), inout.size()); }
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len)=0
template<typename Alloc >
void Botan::StreamCipher::encipher |
( |
std::vector< uint8_t, Alloc > & |
inout | ) |
|
|
inlineinherited |
Encrypt a message The message is encrypted/decrypted in place.
- Parameters
-
inout | the plaintext / ciphertext |
Definition at line 74 of file stream_cipher.h.
75 {
cipher(inout.data(), inout.data(), inout.size()); }
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len)=0
template<typename Alloc >
void Botan::StreamCipher::encrypt |
( |
std::vector< uint8_t, Alloc > & |
inout | ) |
|
|
inlineinherited |
Encrypt a message The message is encrypted in place.
- Parameters
-
inout | the plaintext / ciphertext |
Definition at line 83 of file stream_cipher.h.
84 {
cipher(inout.data(), inout.data(), inout.size()); }
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len)=0
size_t Botan::SymmetricAlgorithm::maximum_keylength |
( |
| ) |
const |
|
inlineinherited |
- Returns
- minimum allowed key length
Definition at line 39 of file sym_algo.h.
size_t maximum_keylength() const
virtual Key_Length_Specification key_spec() const =0
size_t Botan::SymmetricAlgorithm::minimum_keylength |
( |
| ) |
const |
|
inlineinherited |
- Returns
- maximum allowed key length
Definition at line 47 of file sym_algo.h.
size_t minimum_keylength() const
virtual Key_Length_Specification key_spec() const =0
std::string Botan::Salsa20::name |
( |
| ) |
const |
|
overridevirtual |
virtual std::string Botan::StreamCipher::provider |
( |
| ) |
const |
|
inlinevirtualinherited |
- Returns
- provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.
Reimplemented in Botan::ChaCha.
Definition at line 123 of file stream_cipher.h.
std::vector< std::string > Botan::StreamCipher::providers |
( |
const std::string & |
algo_spec | ) |
|
|
staticinherited |
void Botan::Salsa20::seek |
( |
uint64_t |
offset | ) |
|
|
overridevirtual |
Set the offset and the state used later to generate the keystream
- Parameters
-
offset | the offset where we begin to generate the keystream |
Implements Botan::StreamCipher.
Definition at line 235 of file salsa20.cpp.
237 throw Not_Implemented(
"Salsa20::seek");
void Botan::Salsa20::set_iv |
( |
const uint8_t |
iv[], |
|
|
size_t |
iv_len |
|
) |
| |
|
overridevirtual |
Resync the cipher using the IV
- Parameters
-
iv | the initialization vector |
iv_len | the length of the IV in bytes |
Implements Botan::StreamCipher.
Definition at line 167 of file salsa20.cpp.
References Botan::load_le< uint32_t >(), name(), and valid_iv_length().
170 throw Invalid_IV_Length(
name(), length);
192 secure_vector<uint32_t> hsalsa(8);
193 hsalsa20(hsalsa.data(), m_state.data());
195 m_state[ 1] = hsalsa[0];
196 m_state[ 2] = hsalsa[1];
197 m_state[ 3] = hsalsa[2];
198 m_state[ 4] = hsalsa[3];
201 m_state[11] = hsalsa[4];
202 m_state[12] = hsalsa[5];
203 m_state[13] = hsalsa[6];
204 m_state[14] = hsalsa[7];
210 salsa20(m_buffer.data(), m_state.data());
212 m_state[9] += (m_state[8] == 0);
std::string name() const override
uint32_t load_le< uint32_t >(const uint8_t in[], size_t off)
bool valid_iv_length(size_t iv_len) const override
void Botan::SymmetricAlgorithm::set_key |
( |
const SymmetricKey & |
key | ) |
|
|
inlineinherited |
template<typename Alloc >
void Botan::SymmetricAlgorithm::set_key |
( |
const std::vector< uint8_t, Alloc > & |
key | ) |
|
|
inlineinherited |
Definition at line 72 of file sym_algo.h.
74 set_key(key.data(), key.size());
void set_key(const SymmetricKey &key)
void Botan::SymmetricAlgorithm::set_key |
( |
const uint8_t |
key[], |
|
|
size_t |
length |
|
) |
| |
|
inlineinherited |
Set the symmetric key of this object.
- Parameters
-
key | the to be set as a byte array. |
length | in bytes of key param |
Definition at line 82 of file sym_algo.h.
85 throw Invalid_Key_Length(
name(), length);
86 key_schedule(key, length);
bool valid_keylength(size_t length) const
virtual std::string name() const =0
bool Botan::Salsa20::valid_iv_length |
( |
size_t |
iv_len | ) |
const |
|
inlineoverridevirtual |
- Parameters
-
iv_len | the length of the IV in bytes |
- Returns
- if the length is valid for this algorithm
Reimplemented from Botan::StreamCipher.
Definition at line 25 of file salsa20.h.
Referenced by set_iv().
26 {
return (iv_len == 0 || iv_len == 8 || iv_len == 24); }
bool Botan::SymmetricAlgorithm::valid_keylength |
( |
size_t |
length | ) |
const |
|
inlineinherited |
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 57 of file sym_algo.h.
Referenced by Botan::aont_package(), and Botan::aont_unpackage().
bool valid_keylength(size_t length) const
virtual Key_Length_Specification key_spec() const =0
The documentation for this class was generated from the following files: