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