Security Scol plugin
salsa.h
Go to the documentation of this file.
1// salsa.h - originally 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// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
13// error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232
14#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM)
15# define CRYPTOPP_DISABLE_SALSA_ASM 1
16#endif
17
18NAMESPACE_BEGIN(CryptoPP)
19
20
27void Salsa20_Core(word32* data, unsigned int rounds);
28
31struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
32{
33 static std::string StaticAlgorithmName() {return "Salsa20";}
34};
35
38class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
39{
40protected:
41 Salsa20_Policy() : m_rounds(ROUNDS) {}
42 void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
43 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
44 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
45 bool CipherIsRandomAccess() const {return true;}
46 void SeekToIteration(lword iterationCount);
47
48#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
49 unsigned int GetAlignment() const;
50 unsigned int GetOptimalBlockSize() const;
51#endif
52
53 std::string AlgorithmProvider() const;
54
55 CRYPTOPP_CONSTANT(ROUNDS = 20); // Default rounds
57 int m_rounds;
58};
59
72
75struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
76{
77 static std::string StaticAlgorithmName() {return "XSalsa20";}
78};
79
82class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
83{
84public:
85 void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
86 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
87
88protected:
90};
91
101
102NAMESPACE_END
103
104#endif
Inherited by keyed algorithms with fixed key length.
Definition seckey.h:125
Fixed size stack-based SecBlock with 16-byte alignment.
Definition secblock.h:1259
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for retrieving values given their names.
Definition cryptlib.h:322
Salsa20 stream cipher operation.
Definition salsa.h:39
bool CipherIsRandomAccess() const
Flag indicating random access.
Definition salsa.h:45
SymmetricCipher implementation.
Definition strciphr.h:684
Inherited by keyed algorithms with variable key length.
Definition seckey.h:166
XSalsa20 stream cipher operation.
Definition salsa.h:83
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:62
word64 lword
Large word type.
Definition config_int.h:158
Classes and functions for secure memory allocations.
Classes for implementing stream ciphers.
KeystreamOperation
Keystream operation flags.
Definition strciphr.h:88
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Definition strciphr.h:192
virtual unsigned int GetOptimalBlockSize() const
Provides number of ideal bytes to process.
Definition strciphr.h:123
virtual void SeekToIteration(lword iterationCount)
Seeks to a random position in the stream.
Definition strciphr.h:174
virtual void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length)=0
Key the cipher.
virtual void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
Resynchronize the cipher.
Definition strciphr.h:163
Base class for additive stream ciphers.
Definition strciphr.h:202
unsigned int GetAlignment() const
Provides data alignment requirements.
Definition strciphr.h:220
virtual void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)=0
Operates the keystream.
Salsa20 stream cipher information.
Definition salsa.h:32
Salsa20 stream cipher.
Definition salsa.h:68
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition seckey.h:414
XSalsa20 stream cipher information.
Definition salsa.h:76
XSalsa20 stream cipher.
Definition salsa.h:97