hc256.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // hc256.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/hc256.html.
  6. /// \file hc256.h
  7. /// \brief Classes for HC-256 stream cipher
  8. /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The
  9. /// eSTREAM Project | HC-256</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_HC256_H
  13. #define CRYPTOPP_HC256_H
  14. #include "strciphr.h"
  15. #include "secblock.h"
  16. NAMESPACE_BEGIN(CryptoPP)
  17. /// \brief HC-256 stream cipher information
  18. /// \since Crypto++ 8.0
  19. struct HC256Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32>
  20. {
  21. CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-256"; }
  22. };
  23. /// \brief HC-256 stream cipher implementation
  24. /// \since Crypto++ 8.0
  25. class HC256Policy : public AdditiveCipherConcretePolicy<word32, 4>, public HC256Info
  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. word32 H1(word32 u);
  34. word32 H2(word32 u);
  35. void GenerateKeystream(word32* keystream);
  36. word32 Generate();
  37. private:
  38. FixedSizeSecBlock<word32, 8> m_key;
  39. FixedSizeSecBlock<word32, 8> m_iv;
  40. word32 m_P[1024];
  41. word32 m_Q[1024];
  42. word32 m_ctr;
  43. };
  44. /// \brief HC-256 stream cipher
  45. /// \details HC-256 is a stream cipher developed by Hongjun Wu. HC-256 is the
  46. /// successor to HC-128 from the eSTREAM project.
  47. /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The
  48. /// eSTREAM Project | HC-256</A> and
  49. /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
  50. /// \since Crypto++ 8.0
  51. struct HC256 : public HC256Info, public SymmetricCipherDocumentation
  52. {
  53. typedef SymmetricCipherFinal<ConcretePolicyHolder<HC256Policy, AdditiveCipherTemplate<> >, HC256Info> Encryption;
  54. typedef Encryption Decryption;
  55. };
  56. NAMESPACE_END
  57. #endif // CRYPTOPP_HC256_H