Crypto++  5.6.3
Free C++ class library of cryptographic schemes
salsa.h
Go to the documentation of this file.
1 // salsa.h - 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 // TODO: work around GCC 4.8+ issue with SSE2 ASM until the exact details are known
13 // and fix is released. Duplicate with "valgrind ./cryptest.exe tv salsa"
14 // "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232
15 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) || (CRYPTOPP_GCC_VERSION >= 40800)
16 # define CRYPTOPP_DISABLE_SALSA_ASM
17 #endif
18 
19 NAMESPACE_BEGIN(CryptoPP)
20 
21 //! \class Salsa20_Info
22 //! \brief Salsa block cipher information
23 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
24 {
25  static const char *StaticAlgorithmName() {return "Salsa20";}
26 };
27 
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) && !defined(CRYPTOPP_DISABLE_SALSA_ASM)
37  unsigned int GetAlignment() const;
38  unsigned int GetOptimalBlockSize() const;
39 #endif
40 
42  int m_rounds;
43 };
44 
45 // <a href="http://www.cryptolounge.org/wiki/Salsa20">Salsa20</a>, variable rounds: 8, 12 or 20 (default 20)
46 //! \class Salsa20
47 //! \brief Salsa20 block cipher information
48 //! \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
50 {
52  typedef Encryption Decryption;
53 };
54 
55 //! \class XSalsa20_Info
56 //! \brief XSalsa20 block cipher information
57 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
58 {
59  static const char *StaticAlgorithmName() {return "XSalsa20";}
60 };
61 
62 class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
63 {
64 public:
65  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
66  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
67 
68 protected:
70 };
71 
72 // <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>, variable rounds: 8, 12 or 20 (default 20)
73 //! \class XSalsa20
74 //! \brief XSalsa20 block cipher information
75 //! \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
77 {
79  typedef Encryption Decryption;
80 };
81 
82 NAMESPACE_END
83 
84 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:117
XSalsa20 block cipher information.
Definition: salsa.h:57
Salsa block cipher information.
Definition: salsa.h:23
Classes and functions for secure memory allocations.
XSalsa20 block cipher information.
Definition: salsa.h:76
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:514
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:157
const char * IV()
ConstByteArrayParameter, also accepts const byte * for backwards compatibility.
Definition: argnames.h:21
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:412
Salsa20 block cipher information.
Definition: salsa.h:49
Crypto++ library namespace.
Interface for retrieving values given their names.
Definition: cryptlib.h:277