15#define BYTES_PER_ITERATION 16
17#define WordType word32
19#define HC256_OUTPUT(x){\
20 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 0, keystream[0]);\
21 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 1, keystream[1]);\
22 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 2, keystream[2]);\
23 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 3, keystream[3]);}
25ANONYMOUS_NAMESPACE_BEGIN
27using CryptoPP::word32;
28using CryptoPP::rotrConstant;
32 return rotrConstant<7>(x) ^ rotrConstant<18>(x) ^ (x >> 3);
37 return rotrConstant<17>(x) ^ rotrConstant<19>(x) ^ (x >> 10);
40ANONYMOUS_NAMESPACE_END
52 tem = m_Q[a] + m_Q[256 + b] + m_Q[512 + c] + m_Q[768 + d];
64 tem = m_P[a] + m_P[256 + b] + m_P[512 + c] + m_P[768 + d];
68inline word32 HC256Policy::Generate()
70 word32 i, i3, i10, i12, i1023;
75 i10 = (i - 10) & 0x3ff;
76 i12 = (i - 12) & 0x3ff;
77 i1023 = (i - 1023) & 0x3ff;
80 m_P[i] = m_P[i] + m_P[i10] + (rotrConstant<10>(m_P[i3]) ^ rotrConstant<23>(m_P[i1023])) + m_Q[(m_P[i3] ^ m_P[i1023]) & 0x3ff];
81 output = H1(m_P[i12]) ^ m_P[i];
84 m_Q[i] = m_Q[i] + m_Q[i10] + (rotrConstant<10>(m_Q[i3]) ^ rotrConstant<23>(m_Q[i1023])) + m_P[(m_Q[i3] ^ m_Q[i1023]) & 0x3ff];
85 output = H2(m_Q[i12]) ^ m_Q[i];
87 m_ctr = (m_ctr + 1) & 0x7ff;
91void HC256Policy::GenerateKeystream(
word32 keystream[4])
93 keystream[0] = Generate();
94 keystream[1] = Generate();
95 keystream[2] = Generate();
96 keystream[3] = Generate();
99void HC256Policy::CipherSetKey(
const NameValuePairs ¶ms,
const byte *userKey,
size_t keylen)
101 CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(keylen);
104 for (
unsigned int i = 0; i < 8; i++)
107 for (
unsigned int i = 0; i < 32; i++)
109 m_key[i >> 2] = m_key[i >> 2] | userKey[i];
110 m_key[i >> 2] = rotlConstant<8>(m_key[i >> 2]);
114void HC256Policy::OperateKeystream(
KeystreamOperation operation,
byte *output,
const byte *input,
size_t iterationCount)
116 while (iterationCount--)
119 GenerateKeystream(keystream);
125void HC256Policy::CipherResynchronize(
byte *keystreamBuffer,
const byte *iv,
size_t length)
127 CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(length);
132 for (
unsigned int i = 0; i < 8; i++)
135 for (
unsigned int i = 0; i < 32; i++)
137 m_iv[i >> 2] = m_iv[i >> 2] | iv[i];
138 m_iv[i >> 2] = rotlConstant<8>(m_iv[i >> 2]);
143 for (
unsigned int i = 0; i < 8; i++)
145 for (
unsigned int i = 8; i < 16; i++)
148 for (
unsigned int i = 16; i < 2560; i++)
149 W[i] = f2(W[i - 2]) + W[i - 7] + f1(W[i - 15]) + W[i - 16] + i;
151 for (
unsigned int i = 0; i < 1024; i++)
153 for (
unsigned int i = 0; i < 1024; i++)
154 m_Q[i] = W[i + 1536];
159 for (
unsigned int i = 0; i < 4096; i++)
Fixed size stack-based SecBlock.
Interface for retrieving values given their names.
Library configuration file.
unsigned char byte
8-bit unsigned datatype
unsigned int word32
32-bit unsigned datatype
Classes for HC-256 stream cipher.
Utility functions for the Crypto++ library.
Crypto++ library namespace.
Classes and functions for secure memory allocations.
Classes for implementing stream ciphers.
#define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y)
Helper macro to implement OperateKeystream.
KeystreamOperation
Keystream operation flags.
static const int BYTES_PER_ITERATION
Number of bytes for an iteration.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.