Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

chacha.h
Go to the documentation of this file.
1 /*
2 * ChaCha20
3 * (C) 2014 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_CHACHA_H__
9 #define BOTAN_CHACHA_H__
10
11 #include <botan/stream_cipher.h>
12
13 namespace Botan {
14
15 /**
16 * DJB's ChaCha (http://cr.yp.to/chacha.html)
17 */
18 class BOTAN_DLL ChaCha final : public StreamCipher
19 {
20 public:
21 StreamCipher* clone() const override { return new ChaCha(m_rounds); }
22
23 /**
24 * @param rounds number of rounds
25 * @note Currently only 8, 12 or 20 rounds are supported, all others
26 * will throw an exception
27 */
28 ChaCha(size_t rounds = 20);
29
30 std::string provider() const override;
31
32 void cipher(const uint8_t in[], uint8_t out[], size_t length) override;
33
34 void set_iv(const uint8_t iv[], size_t iv_len) override;
35
36 /*
37 * ChaCha accepts 0, 8, or 12 byte IVs. The default IV is a 8 zero bytes.
38 * An IV of length 0 is treated the same as the default zero IV.
39 */
40 bool valid_iv_length(size_t iv_len) const override;
41
42 Key_Length_Specification key_spec() const override
43 {
44 return Key_Length_Specification(16, 32, 16);
45 }
46
47 void clear() override;
48
49 std::string name() const override;
50
51 void seek(uint64_t offset) override;
52
53 private:
54 void key_schedule(const uint8_t key[], size_t key_len) override;
55
56 void chacha_x4(uint8_t output[64*4], uint32_t state[16], size_t rounds);
57
58 #if defined(BOTAN_HAS_CHACHA_SSE2)
59 void chacha_sse2_x4(uint8_t output[64*4], uint32_t state[16], size_t rounds);
60 #endif
61
62 size_t m_rounds;
63 secure_vector<uint32_t> m_state;
64 secure_vector<uint8_t> m_buffer;
65 size_t m_position = 0;
66 };
67
68 }
69
70 #endif
Botan::ChaCha
Definition: chacha.h:18
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::ChaCha::clone
StreamCipher * clone() const override
Definition: chacha.h:21
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::StreamCipher
Definition: stream_cipher.h:19
Botan
Definition: alg_id.cpp:13
Botan::ChaCha::key_spec
Key_Length_Specification key_spec() const override
Definition: chacha.h:42