seal.h 1.9 KB

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