File indexing completed on 2025-01-18 09:55:08
0001
0002
0003
0004
0005
0006 #ifndef CRYPTOPP_SALSA_H
0007 #define CRYPTOPP_SALSA_H
0008
0009 #include "strciphr.h"
0010 #include "secblock.h"
0011
0012
0013
0014 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM)
0015 # define CRYPTOPP_DISABLE_SALSA_ASM 1
0016 #endif
0017
0018 NAMESPACE_BEGIN(CryptoPP)
0019
0020
0021
0022
0023
0024
0025
0026
0027 void Salsa20_Core(word32* data, unsigned int rounds);
0028
0029
0030
0031 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
0032 {
0033 static std::string StaticAlgorithmName() {return "Salsa20";}
0034 };
0035
0036
0037
0038 class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
0039 {
0040 protected:
0041 Salsa20_Policy() : m_rounds(ROUNDS) {}
0042 void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length);
0043 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
0044 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
0045 bool CipherIsRandomAccess() const {return true;}
0046 void SeekToIteration(lword iterationCount);
0047
0048 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
0049 unsigned int GetAlignment() const;
0050 unsigned int GetOptimalBlockSize() const;
0051 #endif
0052
0053 std::string AlgorithmProvider() const;
0054
0055 CRYPTOPP_CONSTANT(ROUNDS = 20);
0056 FixedSizeAlignedSecBlock<word32, 16> m_state;
0057 int m_rounds;
0058 };
0059
0060
0061
0062
0063
0064
0065
0066
0067 struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation
0068 {
0069 typedef SymmetricCipherFinal<ConcretePolicyHolder<Salsa20_Policy, AdditiveCipherTemplate<> >, Salsa20_Info> Encryption;
0070 typedef Encryption Decryption;
0071 };
0072
0073
0074
0075 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
0076 {
0077 static std::string StaticAlgorithmName() {return "XSalsa20";}
0078 };
0079
0080
0081
0082 class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
0083 {
0084 public:
0085 void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length);
0086 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
0087
0088 protected:
0089 FixedSizeSecBlock<word32, 8> m_key;
0090 };
0091
0092
0093
0094
0095
0096 struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation
0097 {
0098 typedef SymmetricCipherFinal<ConcretePolicyHolder<XSalsa20_Policy, AdditiveCipherTemplate<> >, XSalsa20_Info> Encryption;
0099 typedef Encryption Decryption;
0100 };
0101
0102 NAMESPACE_END
0103
0104 #endif