14ANONYMOUS_NAMESPACE_BEGIN
16using CryptoPP::word32;
17using CryptoPP::rotrConstant;
21 return rotrConstant<7>(x) ^ rotrConstant<18>(x) ^ (x >> 3);
26 return rotrConstant<17>(x) ^ rotrConstant<19>(x) ^ (x >> 10);
29ANONYMOUS_NAMESPACE_END
31NAMESPACE_BEGIN(CryptoPP)
41 tem = m_Q[a] + m_Q[256 + b] + m_Q[512 + c] + m_Q[768 + d];
53 tem = m_P[a] + m_P[256 + b] + m_P[512 + c] + m_P[768 + d];
57inline word32 HC256Policy::Generate()
59 word32 i, i3, i10, i12, i1023;
64 i10 = (i - 10) & 0x3ff;
65 i12 = (i - 12) & 0x3ff;
66 i1023 = (i - 1023) & 0x3ff;
69 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];
70 output = H1(m_P[i12]) ^ m_P[i];
73 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];
74 output = H2(m_Q[i12]) ^ m_Q[i];
76 m_ctr = (m_ctr + 1) & 0x7ff;
82 CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(keylen);
83 CRYPTOPP_ASSERT(keylen == 32);
85 for (
unsigned int i = 0; i < 8; i++)
88 for (
unsigned int i = 0; i < 32; i++)
90 m_key[i >> 2] = m_key[i >> 2] | userKey[i];
91 m_key[i >> 2] = rotlConstant<8>(m_key[i >> 2]);
97 while (iterationCount--)
112 xorbuf(output, input, BYTES_PER_ITERATION);
113 input += BYTES_PER_ITERATION;
116 output += BYTES_PER_ITERATION;
122 CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(length);
123 CRYPTOPP_ASSERT(length == 32);
127 for (
unsigned int i = 0; i < 8; i++)
130 for (
unsigned int i = 0; i < 32; i++)
132 m_iv[i >> 2] = m_iv[i >> 2] | iv[i];
133 m_iv[i >> 2] = rotlConstant<8>(m_iv[i >> 2]);
138 for (
unsigned int i = 0; i < 8; i++)
140 for (
unsigned int i = 8; i < 16; i++)
143 for (
unsigned int i = 16; i < 2560; i++)
144 W[i] = f2(W[i - 2]) + W[i - 7] + f1(W[i - 15]) + W[i - 16] + i;
146 for (
unsigned int i = 0; i < 1024; i++)
148 for (
unsigned int i = 0; i < 1024; i++)
149 m_Q[i] = W[i + 1536];
154 for (
unsigned int i = 0; i < 4096; i++)
void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
Resynchronize the cipher.
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
Operates the keystream.
void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length)
Key the cipher.
Interface for retrieving values given their names.
Library configuration file.
unsigned char byte
8-bit unsigned datatype
unsigned int word32
32-bit unsigned datatype
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
Classes for HC-256 stream cipher.
Utility functions for the Crypto++ library.
void PutWord(bool assumeAligned, ByteOrder order, byte *block, T value, const byte *xorBlock=NULLPTR)
Access a block of memory.
#define EnumToInt(v)
Integer value.
Classes and functions for secure memory allocations.
KeystreamOperation
Keystream operation flags.
@ INPUT_NULL
Input buffer is NULL.