hc128.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // hc128.h - written and placed in the public domain by Jeffrey Walton
  2. // based on public domain code by Hongjun Wu.
  3. //
  4. // The reference materials and source files are available at
  5. // The eSTREAM Project, http://www.ecrypt.eu.org/stream/e2-hc128.html.
  6. /// \file hc128.h
  7. /// \brief Classes for HC-128 stream cipher
  8. /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-hc128.html">The
  9. /// eSTREAM Project | HC-128</A> and
  10. /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
  11. /// \since Crypto++ 8.0
  12. #ifndef CRYPTOPP_HC128_H
  13. #define CRYPTOPP_HC128_H
  14. #include "strciphr.h"
  15. #include "secblock.h"
  16. NAMESPACE_BEGIN(CryptoPP)
  17. /// \brief HC-128 stream cipher information
  18. /// \since Crypto++ 8.0
  19. struct HC128Info : public FixedKeyLength<16, SimpleKeyingInterface::UNIQUE_IV, 16>
  20. {
  21. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-128"; }
  22. };
  23. /// \brief HC-128 stream cipher implementation
  24. /// \since Crypto++ 8.0
  25. class HC128Policy : public AdditiveCipherConcretePolicy<word32, 16>, public HC128Info
  26. {
  27. protected:
  28. void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
  29. void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
  30. void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
  31. bool CanOperateKeystream() const { return true; }
  32. bool CipherIsRandomAccess() const { return false; }
  33. void GenerateKeystream(word32* keystream);
  34. void SetupUpdate();
  35. private:
  36. FixedSizeSecBlock<word32, 16> m_X;
  37. FixedSizeSecBlock<word32, 16> m_Y;
  38. FixedSizeSecBlock<word32, 8> m_key;
  39. FixedSizeSecBlock<word32, 8> m_iv;
  40. word32 m_T[1024];
  41. word32 m_ctr;
  42. };
  43. /// \brief HC-128 stream cipher
  44. /// \details HC-128 is a stream cipher developed by Hongjun Wu. HC-128 is one of the
  45. /// final four Profile 1 (software) ciphers selected for the eSTREAM portfolio.
  46. /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-hc128.html">The
  47. /// eSTREAM Project | HC-128</A> and
  48. /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
  49. /// \since Crypto++ 8.0
  50. struct HC128 : public HC128Info, public SymmetricCipherDocumentation
  51. {
  52. typedef SymmetricCipherFinal<ConcretePolicyHolder<HC128Policy, AdditiveCipherTemplate<> >, HC128Info> Encryption;
  53. typedef Encryption Decryption;
  54. };
  55. NAMESPACE_END
  56. #endif // CRYPTOPP_HC128_H