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 BOTAN_FUTURE_INTERNAL_HEADER(salsa20.h)
14 
15 namespace Botan {
16 
17 /**
18 * DJB's Salsa20 (and XSalsa20)
19 */
20 class BOTAN_PUBLIC_API(2,0) Salsa20 final : public StreamCipher
21    {
22    public:
23       void cipher(const uint8_t in[], uint8_t out[], size_t length) override;
24 
25       void set_iv(const uint8_t iv[], size_t iv_len) override;
26 
27       bool valid_iv_length(size_t iv_len) const override;
28 
29       size_t default_iv_length() const override;
30 
31       Key_Length_Specification key_spec() const override;
32 
33       void clear() override;
34       std::string name() const override;
35       StreamCipher* clone() const override;
36 
37       static void salsa_core(uint8_t output[64], const uint32_t input[16], size_t rounds);
38       static void hsalsa20(uint32_t output[8], const uint32_t input[16]);
39 
40       void seek(uint64_t offset) override;
41    private:
42       void key_schedule(const uint8_t key[], size_t key_len) override;
43 
44       void initialize_state();
45 
46       secure_vector<uint32_t> m_key;
47       secure_vector<uint32_t> m_state;
48       secure_vector<uint8_t> m_buffer;
49       size_t m_position = 0;
50    };
51 
52 }
53 
54 #endif
55