10 NAMESPACE_BEGIN(CryptoPP)
12 void SEAL_TestInstantiations()
20 : H(5), Z(5), D(16), lastIndex(0xffffffff)
22 GetUserKey(BIG_ENDIAN_ORDER, H.begin(), 5, key, 20);
26 word32 Apply(word32 i);
32 word32 SEAL_Gamma::Apply(word32 i)
34 word32 shaIndex = i/5;
35 if (shaIndex != lastIndex)
48 m_insideCounter = m_outsideCounter = m_startCount = 0;
51 m_iterationsPerCount = L / 8192;
57 m_T[i] = gamma.Apply(i);
60 m_S[i] = gamma.Apply(0x1000+i);
64 for (i=0; i<m_R.size(); i++)
65 m_R[i] = gamma.Apply(0x2000+i);
72 m_outsideCounter = IV ? GetWord<word32>(
false, BIG_ENDIAN_ORDER, IV) : 0;
73 m_startCount = m_outsideCounter;
80 m_outsideCounter = m_startCount + (
unsigned int)(iterationCount / m_iterationsPerCount);
81 m_insideCounter = (
unsigned int)(iterationCount % m_iterationsPerCount);
87 word32 a, b, c, d, n1, n2, n3, n4;
90 for (
size_t iteration = 0; iteration < iterationCount; ++iteration)
92 #define Ttab(x) *(word32 *)((byte *)m_T.begin()+x)
94 a = m_outsideCounter ^ m_R[4*m_insideCounter];
95 b = rotrFixed(m_outsideCounter, 8U) ^ m_R[4*m_insideCounter+1];
96 c = rotrFixed(m_outsideCounter, 16U) ^ m_R[4*m_insideCounter+2];
97 d = rotrFixed(m_outsideCounter, 24U) ^ m_R[4*m_insideCounter+3];
99 for (
unsigned int j=0; j<2; j++)
103 a = rotrFixed(a, 9U);
107 b = rotrFixed(b, 9U);
111 c = rotrFixed(c, 9U);
115 d = rotrFixed(d, 9U);
118 n1 = d, n2 = b, n3 = a, n4 = c;
122 a = rotrFixed(a, 9U);
126 b = rotrFixed(b, 9U);
130 c = rotrFixed(c, 9U);
134 d = rotrFixed(d, 9U);
137 for (
unsigned int i=0; i<64; i++)
140 a = rotrFixed(a, 9U);
145 b = rotrFixed(b, 9U);
150 c = rotrFixed(c, 9U);
155 d = rotrFixed(d, 9U);
161 a = rotrFixed(a, 9U);
165 b = rotrFixed(b, 9U);
169 c = rotrFixed(c, 9U);
172 d = rotrFixed(d, 9U);
175 #define SEAL_OUTPUT(x) \
176 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, b + m_S[4*i+0]);\
177 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 1, c ^ m_S[4*i+1]);\
178 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 2, d + m_S[4*i+2]);\
179 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 3, a ^ m_S[4*i+3]);
181 CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(SEAL_OUTPUT, 4*4);
199 if (++m_insideCounter == m_iterationsPerCount)
206 a = b = c = d = n1 = n2 = n3 = n4 = 0;