Botan  2.7.0
Crypto and TLS for C++11
salsa20.h
Go to the documentation of this file.
1 /*
2 * Salsa20 / XSalsa20
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_SALSA20_H_
9 #define BOTAN_SALSA20_H_
10 
11 #include <botan/stream_cipher.h>
12 
13 namespace Botan {
14 
15 /**
16 * DJB's Salsa20 (and XSalsa20)
17 */
18 class BOTAN_PUBLIC_API(2,0) Salsa20 final : public StreamCipher
19  {
20  public:
21  void cipher(const uint8_t in[], uint8_t out[], size_t length) override;
22 
23  void set_iv(const uint8_t iv[], size_t iv_len) override;
24 
25  bool valid_iv_length(size_t iv_len) const override
26  { return (iv_len == 0 || iv_len == 8 || iv_len == 24); }
27 
29  {
30  return Key_Length_Specification(16, 32, 16);
31  }
32 
33  void clear() override;
34  std::string name() const override;
35  StreamCipher* clone() const override { return new Salsa20; }
36 
37  static void salsa_core(uint8_t output[64], const uint32_t input[16], size_t rounds);
38 
39  void seek(uint64_t offset) override;
40  private:
41  void key_schedule(const uint8_t key[], size_t key_len) override;
42 
44  secure_vector<uint8_t> m_buffer;
45  size_t m_position = 0;
46  };
47 
48 }
49 
50 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
StreamCipher * clone() const override
Definition: salsa20.h:35
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
bool valid_iv_length(size_t iv_len) const override
Definition: salsa20.h:25
Key_Length_Specification key_spec() const override
Definition: salsa20.h:28