Crypto++  5.6.4
Free C++ class library of cryptographic schemes
chacha.h
Go to the documentation of this file.
1 // chacha.h - written and placed in the public domain by Jeffrey Walton.
2 // Copyright assigned to the Crypto++ project.
3 // Based on Wei Dai's Salsa20 and Bernstein's reference ChaCha
4 // family implementation at http://cr.yp.to/chacha.html.
5 
6 //! \file chacha.h
7 //! \brief Classes for ChaCha8, ChaCha12 and ChaCha20 stream ciphers
8 //! \since Crypto++ 5.6.4
9 
10 #ifndef CRYPTOPP_CHACHA_H
11 #define CRYPTOPP_CHACHA_H
12 
13 #include "strciphr.h"
14 #include "secblock.h"
15 
16 NAMESPACE_BEGIN(CryptoPP)
17 
18 //! \class ChaCha_Info
19 //! \brief ChaCha stream cipher information
20 //! \since Crypto++ 5.6.4
21 template <unsigned int R>
22 struct ChaCha_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>, public FixedRounds<R>
23 {
24  CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {
25  return (R==8?"ChaCha8":(R==12?"ChaCha12":(R==20?"ChaCha20":"ChaCha")));
26  }
27 };
28 
29 //! \class ChaCha_Policy
30 //! \brief ChaCha stream cipher implementation
31 //! \since Crypto++ 5.6.4
32 template <unsigned int R>
33 class CRYPTOPP_NO_VTABLE ChaCha_Policy : public AdditiveCipherConcretePolicy<word32, 16>
34 {
35 protected:
36  CRYPTOPP_CONSTANT(ROUNDS=FixedRounds<R>::ROUNDS)
37 
38  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
39  void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
40  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
41  bool CipherIsRandomAccess() const {return false;} // TODO
42  void SeekToIteration(lword iterationCount);
43  unsigned int GetAlignment() const;
44  unsigned int GetOptimalBlockSize() const;
45 
47 };
48 
49 //! \class ChaCha8
50 //! \brief ChaCha8 stream cipher
51 //! \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
52 //! \since Crypto++ 5.6.4
54 {
56  typedef Encryption Decryption;
57 };
58 
59 //! \class ChaCha12
60 //! \brief ChaCha12 stream cipher
61 //! \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
62 //! \since Crypto++ 5.6.4
64 {
66  typedef Encryption Decryption;
67 };
68 
69 //! \class ChaCha20
70 //! \brief ChaCha20 stream cipher
71 //! \sa <a href="http://cr.yp.to/chacha/chacha-20080128.pdf">ChaCha, a variant of Salsa20</a> (2008.01.28).
72 //! \since Crypto++ 5.6.4
74 {
76  typedef Encryption Decryption;
77 };
78 
79 NAMESPACE_END
80 
81 #endif // CRYPTOPP_CHACHA_H
ChaCha stream cipher information.
Definition: chacha.h:22
unsigned int GetAlignment() const
Provides data alignment requirements.
Definition: strciphr.h:198
Base class for additive stream ciphers.
Definition: strciphr.h:188
ChaCha8 stream cipher.
Definition: chacha.h:53
Classes and functions for secure memory allocations.
ChaCha stream cipher implementation.
Definition: chacha.h:33
virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)=0
Operates the keystream.
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:524
Inherited by algorithms with fixed number of rounds.
Definition: seckey.h:47
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:177
const char * IV()
ConstByteArrayParameter, also accepts const byte * for backwards compatibility.
Definition: argnames.h:21
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:439
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:92
Crypto++ library namespace.
SymmetricCipher implementation.
Definition: strciphr.h:582
Base class for additive stream ciphers with SymmetricCipher interface.
Definition: strciphr.h:269
ChaCha12 stream cipher.
Definition: chacha.h:63
Interface for retrieving values given their names.
Definition: cryptlib.h:277
ChaCha20 stream cipher.
Definition: chacha.h:73