• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

salsa.h

00001 // salsa.h - written and placed in the public domain by Wei Dai
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 &params, 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 /// <a href="http://www.cryptolounge.org/wiki/Salsa20">Salsa20</a>, variable rounds: 8, 12 or 20 (default 20)
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 &params, 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 /// <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>, variable rounds: 8, 12 or 20 (default 20)
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

Generated on Mon Aug 9 2010 15:56:36 for Crypto++ by  doxygen 1.7.1