Crypto++ 8.6 Free C++ class library of cryptographic schemes

hc128.h
Go to the documentation of this file.
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
7 /// \file hc128.h
8 /// \brief Classes for HC-128 stream cipher
9 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-hc128.html">The
10 /// eSTREAM Project | HC-128</A> and
11 /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
12 /// \since Crypto++ 8.0
13
14 #ifndef CRYPTOPP_HC128_H
15 #define CRYPTOPP_HC128_H
16
17 #include "strciphr.h"
18 #include "secblock.h"
19
20 NAMESPACE_BEGIN(CryptoPP)
21
22 /// \brief HC-128 stream cipher information
23 /// \since Crypto++ 8.0
24 struct HC128Info : public FixedKeyLength<16, SimpleKeyingInterface::UNIQUE_IV, 16>
25 {
26 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-128"; }
27 };
28
29 /// \brief HC-128 stream cipher implementation
30 /// \since Crypto++ 8.0
31 class HC128Policy : public AdditiveCipherConcretePolicy<word32, 16>, public HC128Info
32 {
33 protected:
34 void CipherSetKey(const NameValuePairs &params, const byte *key, size_t length);
35 void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount);
36 void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length);
37 bool CanOperateKeystream() const { return true; }
38 bool CipherIsRandomAccess() const { return false; }
39
40 void GenerateKeystream(word32* keystream);
41 void SetupUpdate();
42
43 private:
44 FixedSizeSecBlock<word32, 16> m_X;
45 FixedSizeSecBlock<word32, 16> m_Y;
46 FixedSizeSecBlock<word32, 8> m_key;
47 FixedSizeSecBlock<word32, 8> m_iv;
48 word32 m_T[1024];
49 word32 m_ctr;
50 };
51
52 /// \brief HC-128 stream cipher
53 /// \details HC-128 is a stream cipher developed by Hongjun Wu. HC-128 is one of the
54 /// final four Profile 1 (software) ciphers selected for the eSTREAM portfolio.
55 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/e2-hc128.html">The
56 /// eSTREAM Project | HC-128</A> and
57 /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
58 /// \since Crypto++ 8.0
59 struct HC128 : public HC128Info, public SymmetricCipherDocumentation
60 {
61 typedef SymmetricCipherFinal<ConcretePolicyHolder<HC128Policy, AdditiveCipherTemplate<> >, HC128Info> Encryption;
62 typedef Encryption Decryption;
63 };
64
65 NAMESPACE_END
66
67 #endif // CRYPTOPP_HC128_H
SymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition: seckey.h:413
SymmetricCipherFinal
SymmetricCipher implementation.
Definition: strciphr.h:674
AdditiveCipherConcretePolicy
Base class for additive stream ciphers.
Definition: strciphr.h:201
secblock.h
Classes and functions for secure memory allocations.
SimpleKeyingInterface
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:641
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:124
HC128Policy
HC-128 stream cipher implementation.
Definition: hc128.h:31
KeystreamOperation
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
FixedSizeSecBlock< word32, 16 >
HC128
HC-128 stream cipher.
Definition: hc128.h:59
CryptoPP
Crypto++ library namespace.
HC128Info
HC-128 stream cipher information.
Definition: hc128.h:24
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:321
strciphr.h
Classes for implementing stream ciphers.