Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

  1. // salsa.h - written and placed in the public domain by Wei Dai
  2. #ifndef CRYPTOPP_SALSA_H
  3. #define CRYPTOPP_SALSA_H
  4. #include "strciphr.h"
  5. NAMESPACE_BEGIN(CryptoPP)
  6. //! _
  7. struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8>
  8. {
  9. static const char *StaticAlgorithmName() {return "Salsa20";}
  10. };
  11. class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16>
  12. {
  13. protected:
  14. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  15. void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
  16. void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
  17. bool CipherIsRandomAccess() const {return true;}
  18. void SeekToIteration(lword iterationCount);
  19. #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64
  20. unsigned int GetAlignment() const;
  21. unsigned int GetOptimalBlockSize() const;
  22. #endif
  23. FixedSizeAlignedSecBlock<word32, 16> m_state;
  24. int m_rounds;
  25. };
  26. /// <a href="http://www.cryptolounge.org/wiki/Salsa20">Salsa20</a>, variable rounds: 8, 12 or 20 (default 20)
  27. struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation
  28. {
  29. typedef SymmetricCipherFinal<ConcretePolicyHolder<Salsa20_Policy, AdditiveCipherTemplate<> >, Salsa20_Info> Encryption;
  30. typedef Encryption Decryption;
  31. };
  32. //! _
  33. struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24>
  34. {
  35. static const char *StaticAlgorithmName() {return "XSalsa20";}
  36. };
  37. class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy
  38. {
  39. public:
  40. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  41. void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
  42. protected:
  43. FixedSizeSecBlock<word32, 8> m_key;
  44. };
  45. /// <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>, variable rounds: 8, 12 or 20 (default 20)
  46. struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation
  47. {
  48. typedef SymmetricCipherFinal<ConcretePolicyHolder<XSalsa20_Policy, AdditiveCipherTemplate<> >, XSalsa20_Info> Encryption;
  49. typedef Encryption Decryption;
  50. };
  51. NAMESPACE_END
  52. #endif