Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // hc128.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/e2-hc128.html.

0006 
0007 /// \file hc128.h

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

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

0010 ///   eSTREAM Project | HC-128</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_HC128_H
0015 #define CRYPTOPP_HC128_H
0016 
0017 #include "strciphr.h"
0018 #include "secblock.h"
0019 
0020 NAMESPACE_BEGIN(CryptoPP)
0021 
0022 /// \brief HC-128 stream cipher information

0023 /// \since Crypto++ 8.0

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

0030 /// \since Crypto++ 8.0

0031 class HC128Policy : public AdditiveCipherConcretePolicy<word32, 16>, public HC128Info
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     void GenerateKeystream(word32* keystream);
0041     void SetupUpdate();
0042 
0043 private:
0044     FixedSizeSecBlock<word32, 16> m_X;
0045     FixedSizeSecBlock<word32, 16> m_Y;
0046     FixedSizeSecBlock<word32, 8> m_key;
0047     FixedSizeSecBlock<word32, 8> m_iv;
0048     word32 m_T[1024];
0049     word32 m_ctr;
0050 };
0051 
0052 /// \brief HC-128 stream cipher

0053 /// \details HC-128 is a stream cipher developed by Hongjun Wu. HC-128 is one of the

0054 ///   final four Profile 1 (software) ciphers selected for the eSTREAM portfolio.

0055 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-hc128.html">The

0056 ///   eSTREAM Project | HC-128</A> and

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

0058 /// \since Crypto++ 8.0

0059 struct HC128 : public HC128Info, public SymmetricCipherDocumentation
0060 {
0061     typedef SymmetricCipherFinal<ConcretePolicyHolder<HC128Policy, AdditiveCipherTemplate<> >, HC128Info> Encryption;
0062     typedef Encryption Decryption;
0063 };
0064 
0065 NAMESPACE_END
0066 
0067 #endif  // CRYPTOPP_HC128_H