14 ANONYMOUS_NAMESPACE_BEGIN
21 return rotrConstant<7>(x) ^ rotrConstant<18>(x) ^ (x >> 3);
26 return rotrConstant<17>(x) ^ rotrConstant<19>(x) ^ (x >> 10);
29 ANONYMOUS_NAMESPACE_END
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];
57 inline 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;
80 void HC256Policy::CipherSetKey(
const NameValuePairs ¶ms,
const byte *userKey,
size_t keylen)
82 CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(keylen);
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]);
95 void HC256Policy::OperateKeystream(
KeystreamOperation operation,
byte *output,
const byte *input,
size_t iterationCount)
97 while (iterationCount--)
120 void HC256Policy::CipherResynchronize(
byte *keystreamBuffer,
const byte *iv,
size_t length)
122 CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(length);
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++)