Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:03

0001 // hc256.h - written and placed in the public domain by Jeffrey Walton

0002 //           based on public domain code by Hongjun Wu.

0003 //

0004 //           The reference materials and source files are available at

0005 //           The eSTREAM Project, http://www.ecrypt.eu.org/stream/hc256.html.

0006 
0007 /// \file hc256.h

0008 /// \brief Classes for HC-256 stream cipher

0009 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The

0010 ///   eSTREAM Project | HC-256</A> and

0011 ///   <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.

0012 /// \since Crypto++ 8.0

0013 
0014 #ifndef CRYPTOPP_HC256_H
0015 #define CRYPTOPP_HC256_H
0016 
0017 #include "strciphr.h"
0018 #include "secblock.h"
0019 
0020 NAMESPACE_BEGIN(CryptoPP)
0021 
0022 /// \brief HC-256 stream cipher information

0023 /// \since Crypto++ 8.0

0024 struct HC256Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32>
0025 {
0026     CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-256"; }
0027 };
0028 
0029 /// \brief HC-256 stream cipher implementation

0030 /// \since Crypto++ 8.0

0031 class HC256Policy : public AdditiveCipherConcretePolicy<word32, 4>, public HC256Info
0032 {
0033 protected:
0034     void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
0035     void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
0036     void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
0037     bool CanOperateKeystream() const { return true; }
0038     bool CipherIsRandomAccess() const { return false; }
0039 
0040     word32 H1(word32 u);
0041     word32 H2(word32 u);
0042 
0043     void GenerateKeystream(word32* keystream);
0044     word32 Generate();
0045 
0046 private:
0047     FixedSizeSecBlock<word32, 8> m_key;
0048     FixedSizeSecBlock<word32, 8> m_iv;
0049     word32 m_P[1024];
0050     word32 m_Q[1024];
0051     word32 m_ctr;
0052 };
0053 
0054 /// \brief HC-256 stream cipher

0055 /// \details HC-256 is a stream cipher developed by Hongjun Wu. HC-256 is the

0056 ///   successor to HC-128 from the eSTREAM project.

0057 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The

0058 ///   eSTREAM Project | HC-256</A> and

0059 ///   <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.

0060 /// \since Crypto++ 8.0

0061 struct HC256 : public HC256Info, public SymmetricCipherDocumentation
0062 {
0063     typedef SymmetricCipherFinal<ConcretePolicyHolder<HC256Policy, AdditiveCipherTemplate<> >, HC256Info> Encryption;
0064     typedef Encryption Decryption;
0065 };
0066 
0067 NAMESPACE_END
0068 
0069 #endif  // CRYPTOPP_HC256_H