Crypto++  6.1
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 /// \brief Salsa20 stream cipher information
20 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
21 {
22  static std::string StaticAlgorithmName() {return "Salsa20";}
23 };
24 
25 /// \brief Salsa20 stream cipher operation
26 class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
27 {
28 protected:
29  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
30  void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
31  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
32  bool CipherIsRandomAccess() const {return true;}
33  void SeekToIteration(lword iterationCount);
34 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
35  unsigned int GetAlignment() const;
36  unsigned int GetOptimalBlockSize() const;
37 #endif
38 
40  int m_rounds;
41 };
42 
43 /// \brief Salsa20 stream cipher
44 /// \details Salsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
45 /// \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
47 {
49  typedef Encryption Decryption;
50 };
51 
52 /// \brief XSalsa20 stream cipher information
53 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
54 {
55  static std::string StaticAlgorithmName() {return "XSalsa20";}
56 };
57 
58 /// \brief XSalsa20 stream cipher operation
59 class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
60 {
61 public:
62  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
63  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
64 
65 protected:
67 };
68 
69 /// \brief XSalsa20 stream cipher
70 /// \details XSalsa20 provides a variable number of rounds: 8, 12 or 20. The default number of rounds is 20.
71 /// \sa <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>
73 {
75  typedef Encryption Decryption;
76 };
77 
78 NAMESPACE_END
79 
80 #endif
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:147
Base class for additive stream ciphers.
Definition: strciphr.h:181
XSalsa20 stream cipher information.
Definition: salsa.h:53
unsigned int GetAlignment() const
Provides data alignment requirements.
Definition: strciphr.h:191
Salsa20 stream cipher information.
Definition: salsa.h:20
Classes and functions for secure memory allocations.
XSalsa20 stream cipher.
Definition: salsa.h:72
XSalsa20 stream cipher operation.
Definition: salsa.h:59
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:600
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:188
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:435
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
Salsa20 stream cipher.
Definition: salsa.h:46
Crypto++ library namespace.
SymmetricCipher implementation.
Definition: strciphr.h:571
Salsa20 stream cipher operation.
Definition: salsa.h:26
Interface for retrieving values given their names.
Definition: cryptlib.h:290