Team Fortress 2 Source Code as on 22/4/2020
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.

50 lines
1.5 KiB

  1. // seal.h - written and placed in the public domain by Wei Dai
  2. //! \file seal.h
  3. //! \brief Classes for SEAL stream cipher
  4. #ifndef CRYPTOPP_SEAL_H
  5. #define CRYPTOPP_SEAL_H
  6. #include "strciphr.h"
  7. #include "secblock.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. //! _
  10. template <class B = BigEndian>
  11. struct SEAL_Info : public FixedKeyLength<20, SimpleKeyingInterface::INTERNALLY_GENERATED_IV, 4>
  12. {
  13. static const char *StaticAlgorithmName() {return B::ToEnum() == LITTLE_ENDIAN_ORDER ? "SEAL-3.0-LE" : "SEAL-3.0-BE";}
  14. };
  15. template <class B = BigEndian>
  16. class CRYPTOPP_NO_VTABLE SEAL_Policy : public AdditiveCipherConcretePolicy<word32, 256>, public SEAL_Info<B>
  17. {
  18. protected:
  19. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  20. void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
  21. void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length);
  22. bool CipherIsRandomAccess() const {return true;}
  23. void SeekToIteration(lword iterationCount);
  24. private:
  25. FixedSizeSecBlock<word32, 512> m_T;
  26. FixedSizeSecBlock<word32, 256> m_S;
  27. SecBlock<word32> m_R;
  28. word32 m_startCount, m_iterationsPerCount;
  29. word32 m_outsideCounter, m_insideCounter;
  30. };
  31. //! <a href="http://www.weidai.com/scan-mirror/cs.html#SEAL-3.0-BE">SEAL</a>
  32. template <class B = BigEndian>
  33. struct SEAL : public SEAL_Info<B>, public SymmetricCipherDocumentation
  34. {
  35. typedef SymmetricCipherFinal<ConcretePolicyHolder<SEAL_Policy<B>, AdditiveCipherTemplate<> >, SEAL_Info<B> > Encryption;
  36. typedef Encryption Decryption;
  37. };
  38. NAMESPACE_END
  39. #endif