Crypto++  5.6.5
Free C++ class library of cryptographic schemes
salsa.h
Go to the documentation of this file.
1 // salsa.h - originally written and placed in the public domain by Wei Dai
2 
3 /// \file salsa.h
4 /// \brief Classes for Salsa and Salsa20 stream ciphers
5 
6 #ifndef CRYPTOPP_SALSA_H
7 #define CRYPTOPP_SALSA_H
8 
9 #include "strciphr.h"
10 #include "secblock.h"
11 
12 // "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232
13 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
14 # define CRYPTOPP_DISABLE_SALSA_ASM
15 #endif
16 
17 NAMESPACE_BEGIN(CryptoPP)
18 
19 /// \class Salsa20_Info
20 /// \brief Salsa20 stream cipher information
21 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
22 {
23  static std::string StaticAlgorithmName() {return "Salsa20";}
24 };
25 
26 /// \class Salsa20_Policy
27 /// \brief Salsa20 stream cipher operation
28 class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
29 {
30 protected:
31  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
32  void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
33  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
34  bool CipherIsRandomAccess() const {return true;}
35  void SeekToIteration(lword iterationCount);
36 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
37  unsigned int GetAlignment() const;
38  unsigned int GetOptimalBlockSize() const;
39 #endif
40 
42  int m_rounds;
43 };
44 
45 /// \class Salsa20
46 /// \brief Salsa20 stream cipher
47 /// \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
48 /// \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
50 {
52  typedef Encryption Decryption;
53 };
54 
55 /// \class XSalsa20_Info
56 /// \brief XSalsa20 stream cipher information
57 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
58 {
59  static std::string StaticAlgorithmName() {return "XSalsa20";}
60 };
61 
62 /// \class XSalsa20_Policy
63 /// \brief XSalsa20 stream cipher operation
64 class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
65 {
66 public:
67  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
68  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
69 
70 protected:
72 };
73 
74 /// \class XSalsa20
75 /// \brief XSalsa20 stream cipher
76 /// \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
77 /// \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
79 {
81  typedef Encryption Decryption;
82 };
83 
84 NAMESPACE_END
85 
86 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:267
Base class for additive stream ciphers.
Definition: strciphr.h:185
XSalsa20 stream cipher information.
Definition: salsa.h:57
unsigned int GetAlignment() const
Provides data alignment requirements.
Definition: strciphr.h:195
Salsa20 stream cipher information.
Definition: salsa.h:21
Classes and functions for secure memory allocations.
XSalsa20 stream cipher.
Definition: salsa.h:78
XSalsa20 stream cipher operation.
Definition: salsa.h:64
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:609
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:309
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:599
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:90
Salsa20 stream cipher.
Definition: salsa.h:49
Crypto++ library namespace.
SymmetricCipher implementation.
Definition: strciphr.h:583
Salsa20 stream cipher operation.
Definition: salsa.h:28
Interface for retrieving values given their names.
Definition: cryptlib.h:294