Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Botan::Salsa20 Class Referencefinal

`#include <salsa20.h>`

Inheritance diagram for Botan::Salsa20:

## Public Member Functions
void | cipher (const uint8_t in[], uint8_t out[], size_t length) override
void | cipher1 (uint8_t buf[], size_t len)
void | clear () override
StreamCipher * | clone () const override
template<typename Alloc >
void | decrypt (std::vector< uint8_t, Alloc > &inout)
size_t | default_iv_length () const override
template<typename Alloc >
void | encipher (std::vector< uint8_t, Alloc > &inout)
template<typename Alloc >
void | encrypt (std::vector< uint8_t, Alloc > &inout)
Key_Length_Specification | key_spec () const override
size_t | maximum_keylength () const
size_t | minimum_keylength () const
std::string | name () const override
virtual std::string | provider () const
void | seek (uint64_t offset) override
void | set_iv (const uint8_t iv[], size_t iv_len) override
template<typename Alloc >
void | set_key (const std::vector< uint8_t, Alloc > &key)
void | set_key (const SymmetricKey &key)
void | set_key (const uint8_t key[], size_t length)
bool | valid_iv_length (size_t iv_len) const override
bool | valid_keylength (size_t length) const
virtual void | write_keystream (uint8_t out[], size_t len)

## Static Public Member Functions
static std::unique_ptr< StreamCipher > | create (const std::string &algo_spec, const std::string &provider="")
static std::unique_ptr< StreamCipher > | create_or_throw (const std::string &algo_spec, const std::string &provider="")
static void | hsalsa20 (uint32_t output[8], const uint32_t input[16])
static std::vector< std::string > | providers (const std::string &algo_spec)
static void | salsa_core (uint8_t output[64], const uint32_t input[16], size_t rounds)

## Protected Member Functions
void | verify_key_set (bool cond) const

## Detailed Description

DJB's Salsa20 (and XSalsa20)

Definition at line 20 of file salsa20.h.

## Member Function Documentation

## ◆ cipher()

void Botan::Salsa20::cipher | ( | const uint8_t | in[],
|  | uint8_t | out[],
|  | size_t | len
| ) |  |
| override virtual

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 106 of file salsa20.cpp.

107 {
108 verify_key_set(m_state.empty() == false);
109
110 while(length >= m_buffer.size() - m_position)
111 {
112 const size_t available = m_buffer.size() - m_position;
113
114 xor_buf(out, in, &m_buffer[m_position], available);
115 salsa_core(m_buffer.data(), m_state.data(), 20);
116
117 ++m_state[8];
118 m_state[9] += (m_state[8] == 0);
119
120 length -= available;
121 in += available;
122 out += available;
123
124 m_position = 0;
125 }
126
127 xor_buf(out, in, &m_buffer[m_position], length);
128
129 m_position += length;
130 }
Botan::Salsa20::salsa_core
static void salsa_core(uint8_t output[64], const uint32_t input[16], size_t rounds)
Definition: salsa20.cpp:61
Botan::SymmetricAlgorithm::verify_key_set
void verify_key_set(bool cond) const
Definition: sym_algo.h:171
Botan::xor_buf
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:262

References salsa_core(), Botan::SymmetricAlgorithm::verify_key_set(), and Botan::xor_buf().

Referenced by Botan::Sodium::crypto_stream_salsa20_xor_ic(), and Botan::Sodium::crypto_stream_xsalsa20_xor_ic().

## ◆ cipher1()

void Botan::StreamCipher::cipher1 | ( | uint8_t | buf[],
|  | size_t | len
| ) |  |
| inline inherited

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 78 of file stream_cipher.h.

79 { cipher(buf, buf, len); }
Botan::StreamCipher::cipher
virtual void cipher(const uint8_t in[], uint8_t out[], size_t len)=0

Referenced by Botan::SIV_Encryption::finish().

## ◆ clear()

void Botan::Salsa20::clear | ( |  | ) |
| override virtual

Reset the state.

Implements Botan::SymmetricAlgorithm.

Definition at line 275 of file salsa20.cpp.

276 {
277 zap(m_key);
278 zap(m_state);
279 zap(m_buffer);
280 m_position = 0;
281 }
Botan::zap
void zap(std::vector< T, Alloc > &vec)
Definition: secmem.h:124

References Botan::zap().

## ◆ clone()

StreamCipher * Botan::Salsa20::clone | ( |  | ) | const
| override virtual

Returns
  a new object representing the same algorithm as *this

Implements Botan::StreamCipher.

Definition at line 262 of file salsa20.cpp.

263 {
264 return new Salsa20;
265 }

## ◆ create()

std::unique_ptr< StreamCipher > Botan::StreamCipher::create | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

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 38 of file stream_cipher.cpp.

40 {
41 const SCAN_Name req(algo_spec);
42
43#if defined(BOTAN_HAS_CTR_BE)
44 if((req.algo_name() == "CTR-BE" || req.algo_name() == "CTR") && req.arg_count_between(1,2))
45 {
46 if(provider.empty() || provider == "base")
47 {
48 auto cipher = BlockCipher::create(req.arg(0));
49 if(cipher)
50 {
51 size_t ctr_size = req.arg_as_integer(1, cipher->block_size());
52 return std::unique_ptr<StreamCipher>(new CTR_BE(cipher.release(), ctr_size));
53 }
54 }
55 }
56#endif
57
58#if defined(BOTAN_HAS_CHACHA)
59 if(req.algo_name() == "ChaCha")
60 {
61 if(provider.empty() || provider == "base")
62 return std::unique_ptr<StreamCipher>(new ChaCha(req.arg_as_integer(0, 20)));
63 }
64
65 if(req.algo_name() == "ChaCha20")
66 {
67 if(provider.empty() || provider == "base")
68 return std::unique_ptr<StreamCipher>(new ChaCha(20));
69 }
70#endif
71
72#if defined(BOTAN_HAS_SALSA20)
73 if(req.algo_name() == "Salsa20")
74 {
75 if(provider.empty() || provider == "base")
76 return std::unique_ptr<StreamCipher>(new Salsa20);
77 }
78#endif
79
80#if defined(BOTAN_HAS_SHAKE_CIPHER)
81 if(req.algo_name() == "SHAKE-128" || req.algo_name() == "SHAKE-128-XOF")
82 {
83 if(provider.empty() || provider == "base")
84 return std::unique_ptr<StreamCipher>(new SHAKE_128_Cipher);
85 }
86#endif
87
88#if defined(BOTAN_HAS_OFB)
89 if(req.algo_name() == "OFB" && req.arg_count() == 1)
90 {
91 if(provider.empty() || provider == "base")
92 {
93 if(auto c = BlockCipher::create(req.arg(0)))
94 return std::unique_ptr<StreamCipher>(new OFB(c.release()));
95 }
96 }
97#endif
98
99#if defined(BOTAN_HAS_RC4)
100
101 if(req.algo_name() == "RC4" ||
102 req.algo_name() == "ARC4" ||
103 req.algo_name() == "MARK-4")
104 {
105 const size_t skip = (req.algo_name() == "MARK-4") ? 256 : req.arg_as_integer(0, 0);
106
107 if(provider.empty() || provider == "base")
108 {
109 return std::unique_ptr<StreamCipher>(new RC4(skip));
110 }
111 }
112
113#endif
114
115 BOTAN_UNUSED(req);
116 BOTAN_UNUSED(provider);
117
118 return nullptr;
119 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142
Botan::BlockCipher::create
static std::unique_ptr< BlockCipher > create(const std::string &algo_spec, const std::string &provider="")
Definition: block_cipher.cpp:104
Botan::StreamCipher::provider
virtual std::string provider() const
Definition: stream_cipher.h:142

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), Botan::SCAN_Name::arg_count_between(), BOTAN_UNUSED, Botan::StreamCipher::cipher(), Botan::BlockCipher::create(), and Botan::StreamCipher::provider().

Referenced by Botan::Cipher_Mode::create(), Botan::BlockCipher::create(), and Botan::StreamCipher::create_or_throw().

## ◆ create_or_throw()

std::unique_ptr< StreamCipher > Botan::StreamCipher::create_or_throw | ( | const std::string & | algo_spec,
|  | const std::string & | provider = `""`
| ) |  |
| static inherited

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.

125 {
126 if(auto sc = StreamCipher::create(algo, provider))
127 {
128 return sc;
129 }
130 throw Lookup_Error("Stream cipher", algo, provider);
131 }
Botan::StreamCipher::create
static std::unique_ptr< StreamCipher > create(const std::string &algo_spec, const std::string &provider="")
Definition: stream_cipher.cpp:38

References Botan::StreamCipher::create(), and Botan::StreamCipher::provider().

Referenced by Botan::ChaCha_RNG::ChaCha_RNG(), Botan::Sodium::crypto_secretbox_detached(), Botan::Sodium::crypto_secretbox_open_detached(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305_open(), Botan::Sodium::crypto_stream_chacha20(), Botan::Sodium::crypto_stream_chacha20_ietf(), Botan::Sodium::crypto_stream_chacha20_ietf_xor_ic(), Botan::Sodium::crypto_stream_chacha20_xor_ic(), Botan::Sodium::crypto_stream_xchacha20(), and Botan::Sodium::crypto_stream_xchacha20_xor_ic().

## ◆ decrypt()

template<typename Alloc >

void Botan::StreamCipher::decrypt | ( | std::vector< uint8_t, Alloc > & | inout | ) |
| inline inherited

Decrypt a message in place The message is decrypted in place.

Parameters

  inout | the plaintext / ciphertext

Definition at line 105 of file stream_cipher.h.

106 { cipher(inout.data(), inout.data(), inout.size()); }

## ◆ default_iv_length()

size_t Botan::Salsa20::default_iv_length | ( |  | ) | const
| override virtual

Return the default (preferred) nonce length If this function returns 0, then this cipher does not support nonces

Reimplemented from Botan::StreamCipher.

Definition at line 252 of file salsa20.cpp.

253 {
254 return 24;
255 }

## ◆ encipher()

template<typename Alloc >

void Botan::StreamCipher::encipher | ( | std::vector< uint8_t, Alloc > & | inout | ) |
| inline inherited

Encrypt a message The message is encrypted/decrypted in place.

Parameters

  inout | the plaintext / ciphertext

Definition at line 87 of file stream_cipher.h.

88 { cipher(inout.data(), inout.data(), inout.size()); }

## ◆ encrypt()

template<typename Alloc >

void Botan::StreamCipher::encrypt | ( | std::vector< uint8_t, Alloc > & | inout | ) |
| inline inherited

Encrypt a message The message is encrypted in place.

Parameters

  inout | the plaintext / ciphertext

Definition at line 96 of file stream_cipher.h.

97 { cipher(inout.data(), inout.data(), inout.size()); }

## ◆ hsalsa20()

void Botan::Salsa20::hsalsa20 | ( | uint32_t | output[8],
|  | const uint32_t | input[16]
| ) |  |
| static

Definition at line 27 of file salsa20.cpp.

28 {
29 uint32_t x00 = input[ 0], x01 = input[ 1], x02 = input[ 2], x03 = input[ 3],
30 x04 = input[ 4], x05 = input[ 5], x06 = input[ 6], x07 = input[ 7],
31 x08 = input[ 8], x09 = input[ 9], x10 = input[10], x11 = input[11],
32 x12 = input[12], x13 = input[13], x14 = input[14], x15 = input[15];
33
34 for(size_t i = 0; i != 10; ++i)
35 {
36 SALSA20_QUARTER_ROUND(x00, x04, x08, x12);
37 SALSA20_QUARTER_ROUND(x05, x09, x13, x01);
38 SALSA20_QUARTER_ROUND(x10, x14, x02, x06);
39 SALSA20_QUARTER_ROUND(x15, x03, x07, x11);
40
41 SALSA20_QUARTER_ROUND(x00, x01, x02, x03);
42 SALSA20_QUARTER_ROUND(x05, x06, x07, x04);
43 SALSA20_QUARTER_ROUND(x10, x11, x08, x09);
44 SALSA20_QUARTER_ROUND(x15, x12, x13, x14);
45 }
46
47 output[0] = x00;
48 output[1] = x05;
49 output[2] = x10;
50 output[3] = x15;
51 output[4] = x06;
52 output[5] = x07;
53 output[6] = x08;
54 output[7] = x09;
55 }
SALSA20_QUARTER_ROUND
#define SALSA20_QUARTER_ROUND(x1, x2, x3, x4)
Definition: salsa20.cpp:15

References SALSA20_QUARTER_ROUND.

Referenced by Botan::Sodium::crypto_core_hsalsa20(), and set_iv().

## ◆ key_spec()

Key_Length_Specification Botan::Salsa20::key_spec | ( |  | ) | const
| override virtual

Returns
  object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 257 of file salsa20.cpp.

258 {
259 return Key_Length_Specification(16, 32, 16);
260 }

## ◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength | ( |  | ) | const
| inline inherited

Returns
  maximum allowed key length

Definition at line 120 of file sym_algo.h.

121 {
122 return key_spec().maximum_keylength();
123 }
Botan::Key_Length_Specification::maximum_keylength
size_t maximum_keylength() const
Definition: sym_algo.h:70
Botan::SymmetricAlgorithm::key_spec
virtual Key_Length_Specification key_spec() const =0

## ◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength | ( |  | ) | const
| inline inherited

Returns
  minimum allowed key length

Definition at line 128 of file sym_algo.h.

129 {
130 return key_spec().minimum_keylength();
131 }
Botan::Key_Length_Specification::minimum_keylength
size_t minimum_keylength() const
Definition: sym_algo.h:62

Referenced by botan_block_cipher_get_keyspec(), and botan_mac_get_keyspec().

## ◆ name()

std::string Botan::Salsa20::name | ( |  | ) | const
| override virtual

Returns
  the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 267 of file salsa20.cpp.

268 {
269 return "Salsa20";
270 }

Referenced by set_iv().

## ◆ provider()

virtual std::string Botan::StreamCipher::provider | ( |  | ) | const
| inline virtual inherited

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 142 of file stream_cipher.h.

142{ return "base"; }

Referenced by Botan::StreamCipher::create(), and Botan::StreamCipher::create_or_throw().

## ◆ providers()

std::vector< std::string > Botan::StreamCipher::providers | ( | const std::string & | algo_spec | ) |
| static inherited

Returns
  list of available providers for this algorithm, empty if not available

Definition at line 133 of file stream_cipher.cpp.

134 {
135 return probe_providers_of<StreamCipher>(algo_spec, {"base"});
136 }

## ◆ salsa_core()

void Botan::Salsa20::salsa_core | ( | uint8_t | output[64],
|  | const uint32_t | input[16],
|  | size_t | rounds
| ) |  |
| static

Definition at line 61 of file salsa20.cpp.

62 {
63 BOTAN_ASSERT_NOMSG(rounds % 2 == 0);
64
65 uint32_t x00 = input[ 0], x01 = input[ 1], x02 = input[ 2], x03 = input[ 3],
66 x04 = input[ 4], x05 = input[ 5], x06 = input[ 6], x07 = input[ 7],
67 x08 = input[ 8], x09 = input[ 9], x10 = input[10], x11 = input[11],
68 x12 = input[12], x13 = input[13], x14 = input[14], x15 = input[15];
69
70 for(size_t i = 0; i != rounds / 2; ++i)
71 {
72 SALSA20_QUARTER_ROUND(x00, x04, x08, x12);
73 SALSA20_QUARTER_ROUND(x05, x09, x13, x01);
74 SALSA20_QUARTER_ROUND(x10, x14, x02, x06);
75 SALSA20_QUARTER_ROUND(x15, x03, x07, x11);
76
77 SALSA20_QUARTER_ROUND(x00, x01, x02, x03);
78 SALSA20_QUARTER_ROUND(x05, x06, x07, x04);
79 SALSA20_QUARTER_ROUND(x10, x11, x08, x09);
80 SALSA20_QUARTER_ROUND(x15, x12, x13, x14);
81 }
82
83 store_le(x00 + input[ 0], output + 4 * 0);
84 store_le(x01 + input[ 1], output + 4 * 1);
85 store_le(x02 + input[ 2], output + 4 * 2);
86 store_le(x03 + input[ 3], output + 4 * 3);
87 store_le(x04 + input[ 4], output + 4 * 4);
88 store_le(x05 + input[ 5], output + 4 * 5);
89 store_le(x06 + input[ 6], output + 4 * 6);
90 store_le(x07 + input[ 7], output + 4 * 7);
91 store_le(x08 + input[ 8], output + 4 * 8);
92 store_le(x09 + input[ 9], output + 4 * 9);
93 store_le(x10 + input[10], output + 4 * 10);
94 store_le(x11 + input[11], output + 4 * 11);
95 store_le(x12 + input[12], output + 4 * 12);
96 store_le(x13 + input[13], output + 4 * 13);
97 store_le(x14 + input[14], output + 4 * 14);
98 store_le(x15 + input[15], output + 4 * 15);
99 }
BOTAN_ASSERT_NOMSG
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:68
Botan::store_le
void store_le(uint16_t in, uint8_t out[2])
Definition: loadstor.h:454

References BOTAN_ASSERT_NOMSG, SALSA20_QUARTER_ROUND, and Botan::store_le().

Referenced by cipher(), seek(), and set_iv().

## ◆ seek()

void Botan::Salsa20::seek | ( | uint64_t | offset | ) |
| override virtual

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 283 of file salsa20.cpp.

284 {
285 verify_key_set(m_state.empty() == false);
286
287 // Find the block offset
288 const uint64_t counter = offset / 64;
289 uint8_t counter8[8];
290 store_le(counter, counter8);
291
292 m_state[8] = load_le<uint32_t>(counter8, 0);
293 m_state[9] += load_le<uint32_t>(counter8, 1);
294
295 salsa_core(m_buffer.data(), m_state.data(), 20);
296
297 ++m_state[8];
298 m_state[9] += (m_state[8] == 0);
299
300 m_position = offset % 64;
301 }
Botan::load_le< uint32_t >
uint32_t load_le< uint32_t >(const uint8_t in[], size_t off)
Definition: loadstor.h:198

References Botan::load_le< uint32_t >(), salsa_core(), Botan::store_le(), and Botan::SymmetricAlgorithm::verify_key_set().

Referenced by Botan::Sodium::crypto_stream_salsa20_xor_ic(), and Botan::Sodium::crypto_stream_xsalsa20_xor_ic().

## ◆ set_iv()

void Botan::Salsa20::set_iv | ( | const uint8_t | iv[],
|  | size_t | iv_len
| ) |  |
| override virtual

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 193 of file salsa20.cpp.

194 {
195 verify_key_set(m_state.empty() == false);
196
197 if(!valid_iv_length(length))
198 throw Invalid_IV_Length(name(), length);
199
200 initialize_state();
201
202 if(length == 0)
203 {
204 // Salsa20 null IV
205 m_state[6] = 0;
206 m_state[7] = 0;
207 }
208 else if(length == 8)
209 {
210 // Salsa20
211 m_state[6] = load_le<uint32_t>(iv, 0);
212 m_state[7] = load_le<uint32_t>(iv, 1);
213 }
214 else
215 {
216 // XSalsa20
217 m_state[6] = load_le<uint32_t>(iv, 0);
218 m_state[7] = load_le<uint32_t>(iv, 1);
219 m_state[8] = load_le<uint32_t>(iv, 2);
220 m_state[9] = load_le<uint32_t>(iv, 3);
221
222 secure_vector<uint32_t> hsalsa(8);
223 hsalsa20(hsalsa.data(), m_state.data());
224
225 m_state[ 1] = hsalsa[0];
226 m_state[ 2] = hsalsa[1];
227 m_state[ 3] = hsalsa[2];
228 m_state[ 4] = hsalsa[3];
229 m_state[ 6] = load_le<uint32_t>(iv, 4);
230 m_state[ 7] = load_le<uint32_t>(iv, 5);
231 m_state[11] = hsalsa[4];
232 m_state[12] = hsalsa[5];
233 m_state[13] = hsalsa[6];
234 m_state[14] = hsalsa[7];
235 }
236
237 m_state[8] = 0;
238 m_state[9] = 0;
239
240 salsa_core(m_buffer.data(), m_state.data(), 20);
241 ++m_state[8];
242 m_state[9] += (m_state[8] == 0);
243
244 m_position = 0;
245 }
Botan::Salsa20::hsalsa20
static void hsalsa20(uint32_t output[8], const uint32_t input[16])
Definition: salsa20.cpp:27
Botan::Salsa20::valid_iv_length
bool valid_iv_length(size_t iv_len) const override
Definition: salsa20.cpp:247
Botan::Salsa20::name
std::string name() const override
Definition: salsa20.cpp:267

References hsalsa20(), Botan::load_le< uint32_t >(), name(), salsa_core(), valid_iv_length(), and Botan::SymmetricAlgorithm::verify_key_set().

Referenced by Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), and Botan::Sodium::crypto_stream_xsalsa20_xor_ic().

## ◆ set_key() [1/3]

template<typename Alloc >

void Botan::SymmetricAlgorithm::set_key | ( | const std::vector< uint8_t, Alloc > & | key | ) |
| inline inherited

Definition at line 153 of file sym_algo.h.

154 {
155 set_key(key.data(), key.size());
156 }
Botan::SymmetricAlgorithm::set_key
void set_key(const SymmetricKey &key)
Definition: sym_algo.h:147

## ◆ set_key() [2/3]

void Botan::SymmetricAlgorithm::set_key | ( | const SymmetricKey & | key | ) |
| inline inherited

Set the symmetric key of this object.

Parameters

  key | the SymmetricKey to be set.

Definition at line 147 of file sym_algo.h.

148 {
149 set_key(key.begin(), key.length());
150 }

References Botan::OctetString::begin(), and Botan::OctetString::length().

Referenced by Botan::aont_package(), Botan::aont_unpackage(), botan_block_cipher_set_key(), botan_cipher_set_key(), botan_mac_set_key(), Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::FPE::fe1_decrypt(), Botan::FPE::fe1_encrypt(), and Botan::Sodium::randombytes_buf_deterministic().

## ◆ set_key() [3/3]

void Botan::SymmetricAlgorithm::set_key | ( | const uint8_t | key[],
|  | size_t | length
| ) |  |
| inherited

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 17 of file sym_algo.cpp.

18 {
19 if(!valid_keylength(length))
20 throw Invalid_Key_Length(name(), length);
21 key_schedule(key, length);
22 }
Botan::SymmetricAlgorithm::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:138
Botan::SymmetricAlgorithm::name
virtual std::string name() const =0

References Botan::SymmetricAlgorithm::name(), and Botan::SymmetricAlgorithm::valid_keylength().

## ◆ valid_iv_length()

bool Botan::Salsa20::valid_iv_length | ( | size_t | iv_len | ) | const
| override virtual

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 247 of file salsa20.cpp.

248 {
249 return (iv_len == 0 || iv_len == 8 || iv_len == 24);
250 }

Referenced by set_iv().

## ◆ valid_keylength()

bool Botan::SymmetricAlgorithm::valid_keylength | ( | size_t | length | ) | const
| inline inherited

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 138 of file sym_algo.h.

139 {
140 return key_spec().valid_keylength(length);
141 }
Botan::Key_Length_Specification::valid_keylength
bool valid_keylength(size_t length) const
Definition: sym_algo.h:52

Referenced by Botan::aont_package(), Botan::aont_unpackage(), and Botan::SymmetricAlgorithm::set_key().

## ◆ verify_key_set()

void Botan::SymmetricAlgorithm::verify_key_set | ( | bool | cond | ) | const
| inline protected inherited

Definition at line 171 of file sym_algo.h.

172 {
173 if(cond == false)
174 throw_key_not_set_error();
175 }

Referenced by Botan::ChaCha::cipher(), Botan::CTR_BE::cipher(), Botan::RC4::cipher(), cipher(), Botan::SHAKE_128_Cipher::cipher(), Botan::AES_128::decrypt_n(), Botan::AES_192::decrypt_n(), Botan::AES_256::decrypt_n(), Botan::ARIA_128::decrypt_n(), Botan::ARIA_192::decrypt_n(), Botan::ARIA_256::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::Camellia_128::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::CAST_256::decrypt_n(), Botan::DES::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::DESX::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::KASUMI::decrypt_n(), Botan::Lion::decrypt_n(), Botan::MISTY1::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::SM4::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::XTEA::decrypt_n(), Botan::AES_128::encrypt_n(), Botan::AES_192::encrypt_n(), Botan::AES_256::encrypt_n(), Botan::ARIA_128::encrypt_n(), Botan::ARIA_192::encrypt_n(), Botan::ARIA_256::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::CAST_256::encrypt_n(), Botan::DES::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::DESX::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::KASUMI::encrypt_n(), Botan::Lion::encrypt_n(), Botan::MISTY1::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::SM4::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::XTEA::encrypt_n(), Botan::OCB_Encryption::finish(), Botan::OCB_Decryption::finish(), Botan::GHASH::ghash_update(), Botan::CFB_Encryption::process(), Botan::CFB_Decryption::process(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), seek(), Botan::OCB_Mode::set_associated_data(), Botan::ChaCha::set_iv(), set_iv(), Botan::GHASH::update(), Botan::GHASH::update_associated_data(), and Botan::ChaCha::write_keystream().

## ◆ write_keystream()

virtual void Botan::StreamCipher::write_keystream | ( | uint8_t | out[],
|  | size_t | len
| ) |  |
| inline virtual inherited

Write keystream bytes to a buffer

Parameters

  out | the byte array to hold the keystream
  len | the length of out in bytes

Reimplemented in Botan::ChaCha.

Definition at line 66 of file stream_cipher.h.

67 {
68 clear_mem(out, len);
69 cipher1(out, len);
70 }
Botan::StreamCipher::cipher1
void cipher1(uint8_t buf[], size_t len)
Definition: stream_cipher.h:78
Botan::clear_mem
void clear_mem(T *ptr, size_t n)
Definition: mem_ops.h:115

References Botan::clear_mem().

Referenced by Botan::Sodium::crypto_stream_salsa20(), and Botan::Sodium::crypto_stream_xsalsa20().

The documentation for this class was generated from the following files:

- src/lib/stream/salsa20/salsa20.h
- src/lib/stream/salsa20/salsa20.cpp