00001
00002
00003
00004
00005
00006 #ifndef CRYPTOPP_SALSA_H
00007 #define CRYPTOPP_SALSA_H
00008
00009 #include "strciphr.h"
00010 #include "secblock.h"
00011
00012
00013
00014
00015 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM) || (CRYPTOPP_GCC_VERSION >= 40800)
00016 # define CRYPTOPP_DISABLE_SALSA_ASM
00017 #endif
00018
00019 NAMESPACE_BEGIN(CryptoPP)
00020
00021
00022
00023 struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
00024 {
00025 static const char *StaticAlgorithmName() {return "Salsa20";}
00026 };
00027
00028 class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
00029 {
00030 protected:
00031 void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length);
00032 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
00033 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
00034 bool CipherIsRandomAccess() const {return true;}
00035 void SeekToIteration(lword iterationCount);
00036 #if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) && !defined(CRYPTOPP_DISABLE_SALSA_ASM)
00037 unsigned int GetAlignment() const;
00038 unsigned int GetOptimalBlockSize() const;
00039 #endif
00040
00041 FixedSizeAlignedSecBlock<word32, 16> m_state;
00042 int m_rounds;
00043 };
00044
00045
00046
00047
00048
00049 struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation
00050 {
00051 typedef SymmetricCipherFinal<ConcretePolicyHolder<Salsa20_Policy, AdditiveCipherTemplate<> >, Salsa20_Info> Encryption;
00052 typedef Encryption Decryption;
00053 };
00054
00055
00056
00057 struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
00058 {
00059 static const char *StaticAlgorithmName() {return "XSalsa20";}
00060 };
00061
00062 class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
00063 {
00064 public:
00065 void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length);
00066 void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
00067
00068 protected:
00069 FixedSizeSecBlock<word32, 8> m_key;
00070 };
00071
00072
00073
00074
00075
00076 struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation
00077 {
00078 typedef SymmetricCipherFinal<ConcretePolicyHolder<XSalsa20_Policy, AdditiveCipherTemplate<> >, XSalsa20_Info> Encryption;
00079 typedef Encryption Decryption;
00080 };
00081
00082 NAMESPACE_END
00083
00084 #endif