Fabcoin Core  0.16.2
P2P Digital Currency
salsa.h
Go to the documentation of this file.
1 // salsa.h - written and placed in the public domain by Wei Dai
2 
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 
20 
21 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
24 {
25  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Salsa20";}
26 };
27 
31 {
32 protected:
33  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
34  void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
35  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
36  bool CipherIsRandomAccess() const {return true;}
37  void SeekToIteration(lword iterationCount);
38 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) && !defined(CRYPTOPP_DISABLE_SALSA_ASM)
39  unsigned int GetAlignment() const;
40  unsigned int GetOptimalBlockSize() const;
41 #endif
42 
44  int m_rounds;
45 };
46 
52 {
54  typedef Encryption Decryption;
55 };
56 
59 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
60 {
61  CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "XSalsa20";}
62 };
63 
67 {
68 public:
69  void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
70  void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
71 
72 protected:
74 };
75 
81 {
83  typedef Encryption Decryption;
84 };
85 
87 
88 #endif
FixedSizeSecBlock< word32, 8 > m_key
Definition: salsa.h:73
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:127
uint8_t byte
Definition: Common.h:57
#define CRYPTOPP_STATIC_CONSTEXPR
Definition: config.h:892
unsigned int GetAlignment() const
Provides data alignment requirements.
Definition: strciphr.h:196
Base class for additive stream ciphers.
Definition: strciphr.h:186
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
int m_rounds
Definition: salsa.h:44
XSalsa20 stream cipher information.
Definition: salsa.h:59
Salsa20 stream cipher information.
Definition: salsa.h:23
Classes and functions for secure memory allocations.
XSalsa20 stream cipher.
Definition: salsa.h:80
XSalsa20 stream cipher operation.
Definition: salsa.h:66
SymmetricCipherFinal< ConcretePolicyHolder< Salsa20_Policy, AdditiveCipherTemplate<> >, Salsa20_Info > Encryption
Definition: salsa.h:53
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
SymmetricCipherFinal< ConcretePolicyHolder< XSalsa20_Policy, AdditiveCipherTemplate<> >, XSalsa20_Info > Encryption
Definition: salsa.h:82
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: salsa.h:25
Inherited by keyed algorithms with variable key length.
Definition: seckey.h:169
#define CRYPTOPP_NO_VTABLE
Definition: config.h:369
Classes for implementing stream ciphers.
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher...
Definition: seckey.h:424
Encryption Decryption
Definition: salsa.h:54
#define NAMESPACE_END
Definition: config.h:201
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:90
Encryption Decryption
Definition: salsa.h:83
Salsa20 stream cipher.
Definition: salsa.h:51
word64 lword
Definition: config.h:245
SymmetricCipher implementation.
Definition: strciphr.h:584
FixedSizeAlignedSecBlock< word32, 16 > m_state
Definition: salsa.h:43
bool CipherIsRandomAccess() const
Flag indicating random access.
Definition: salsa.h:36
CRYPTOPP_STATIC_CONSTEXPR const char * StaticAlgorithmName()
Definition: salsa.h:61
Salsa20 stream cipher operation.
Definition: salsa.h:30
Interface for retrieving values given their names.
Definition: cryptlib.h:279