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

hc256.h
Go to the documentation of this file.
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
7 /// \file hc256.h
8 /// \brief Classes for HC-256 stream cipher
9 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The
10 /// eSTREAM Project | HC-256</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_HC256_H
15 #define CRYPTOPP_HC256_H
16
17 #include "strciphr.h"
18 #include "secblock.h"
19
20 NAMESPACE_BEGIN(CryptoPP)
21
22 /// \brief HC-256 stream cipher information
23 /// \since Crypto++ 8.0
24 struct HC256Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 32>
25 {
26 CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() { return "HC-256"; }
27 };
28
29 /// \brief HC-256 stream cipher implementation
30 /// \since Crypto++ 8.0
31 class HC256Policy : public AdditiveCipherConcretePolicy<word32, 4>, public HC256Info
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 word32 H1(word32 u);
41 word32 H2(word32 u);
42
43 void GenerateKeystream(word32* keystream);
44 word32 Generate();
45
46 private:
47 FixedSizeSecBlock<word32, 8> m_key;
48 FixedSizeSecBlock<word32, 8> m_iv;
49 word32 m_P[1024];
50 word32 m_Q[1024];
51 word32 m_ctr;
52 };
53
54 /// \brief HC-256 stream cipher
55 /// \details HC-256 is a stream cipher developed by Hongjun Wu. HC-256 is the
56 /// successor to HC-128 from the eSTREAM project.
57 /// \sa <A HREF="http://www.ecrypt.eu.org/stream/hc256.html">The
58 /// eSTREAM Project | HC-256</A> and
59 /// <A HREF="https://www.cryptopp.com/wiki/HC-128">Crypto++ Wiki | HC-128</A>.
60 /// \since Crypto++ 8.0
61 struct HC256 : public HC256Info, public SymmetricCipherDocumentation
62 {
63 typedef SymmetricCipherFinal<ConcretePolicyHolder<HC256Policy, AdditiveCipherTemplate<> >, HC256Info> Encryption;
64 typedef Encryption Decryption;
65 };
66
67 NAMESPACE_END
68
69 #endif // CRYPTOPP_HC256_H
FixedKeyLength
Inherited by keyed algorithms with fixed key length.
Definition: seckey.h:125
FixedSizeSecBlock< word32, 8 >
HC256Policy
HC-256 stream cipher implementation.
Definition: hc256.h:32
NameValuePairs
Interface for retrieving values given their names.
Definition: cryptlib.h:327
SimpleKeyingInterface
Interface for algorithms that take byte strings as keys.
Definition: cryptlib.h:647
SymmetricCipherFinal
SymmetricCipher implementation.
Definition: strciphr.h:684
word32
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:72
CryptoPP
Crypto++ library namespace.
secblock.h
Classes and functions for secure memory allocations.
strciphr.h
Classes for implementing stream ciphers.
KeystreamOperation
KeystreamOperation
Keystream operation flags.
Definition: strciphr.h:88
AdditiveCipherConcretePolicy
Base class for additive stream ciphers.
Definition: strciphr.h:202
HC256
HC-256 stream cipher.
Definition: hc256.h:62
HC256Info
HC-256 stream cipher information.
Definition: hc256.h:25
SymmetricCipherDocumentation
Provides Encryption and Decryption typedefs used by derived classes to implement a symmetric cipher.
Definition: seckey.h:414