7 #ifndef CRYPTOPP_GENERATE_X64_MASM 16 #if CRYPTOPP_MSC_VERSION 17 # pragma warning(disable: 4731) 23 memset(m_state, 0, m_state.SizeInBytes());
24 #if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 25 m_state[17] = HasSSSE3();
29 #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM 31 #ifdef CRYPTOPP_X64_MASM_AVAILABLE 33 void Panama_SSE2_Pull(
size_t count, word32 *state, word32 *z,
const word32 *y);
35 #elif CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 37 #ifdef CRYPTOPP_GENERATE_X64_MASM 38 Panama_SSE2_Pull PROC FRAME
45 void CRYPTOPP_NOINLINE Panama_SSE2_Pull(
size_t count, word32 *state, word32 *z,
const word32 *y)
47 #if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY) 53 AS2( mov AS_REG_1, count)
54 AS2( mov AS_REG_2, state)
61 #define REG_loopEnd r8d
62 #elif CRYPTOPP_BOOL_X86
63 #define REG_loopEnd [esp]
64 #elif defined(CRYPTOPP_GENERATE_X64_MASM)
65 #define REG_loopEnd rdi
67 #define REG_loopEnd r8
72 AS2( mov AS_REG_6d, [AS_REG_2+4*17])
73 AS2( add AS_REG_1, AS_REG_6)
76 AS2( mov REG_loopEnd, AS_REG_1)
83 AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_2+0*16])
84 AS2( movdqa xmm1, XMMWORD_PTR [AS_REG_2+1*16])
85 AS2( movdqa xmm2, XMMWORD_PTR [AS_REG_2+2*16])
86 AS2( movdqa xmm3, XMMWORD_PTR [AS_REG_2+3*16])
87 AS2( mov eax, dword ptr [AS_REG_2+4*16])
91 #
if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE
92 AS2( test AS_REG_6, 1)
95 AS2( movdqa xmm6, xmm2)
96 AS2( movss xmm6, xmm3)
97 ASS( pshufd xmm5, xmm6, 0, 3, 2, 1)
99 AS2( movdqa xmm7, xmm3)
100 AS2( movss xmm7, xmm6)
101 ASS( pshufd xmm6, xmm7, 0, 3, 2, 1)
102 #
if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE
105 AS2( movdqa xmm5, xmm3)
106 AS3( palignr xmm5, xmm2, 4)
108 AS3( palignr xmm6, xmm3, 4)
112 AS2( movd AS_REG_1d, xmm2)
114 AS2( movd AS_REG_7d, xmm3)
115 AS2( or AS_REG_1d, AS_REG_7d)
116 AS2( xor eax, AS_REG_1d)
118 #define SSE2_Index(i) ASM_MOD(((i)*13+16), 17)
121 AS2( movd AS_REG_1d, xmm7)\
122 AS2( rol AS_REG_1d, ASM_MOD((ASM_MOD(5*i,17)*(ASM_MOD(5*i,17)+1)/2), 32))\
123 AS2( mov [AS_REG_2+SSE2_Index(ASM_MOD(5*(i), 17))*4], AS_REG_1d)
125 #define pi4(x, y, z, a, b, c, d) \
126 AS2( pcmpeqb xmm7, xmm7)\
131 ASS( pshuflw xmm7, xmm7, 1, 0, 3, 2)\
133 AS2( punpckhqdq xmm7, xmm7)\
135 ASS( pshuflw xmm7, xmm7, 1, 0, 3, 2)\
138 pi4(xmm1, xmm2, xmm3, 1, 5, 9, 13)
139 pi4(xmm0, xmm1, xmm2, 2, 6, 10, 14)
140 pi4(xmm6, xmm0, xmm1, 3, 7, 11, 15)
141 pi4(xmm5, xmm6, xmm0, 4, 8, 12, 16)
144 AS2( movdqa xmm4, xmm3)
145 AS2( punpcklqdq xmm3, xmm2)
146 AS2( punpckhdq xmm4, xmm2)
147 AS2( movdqa xmm2, xmm1)
148 AS2( punpcklqdq xmm1, xmm0)
149 AS2( punpckhdq xmm2, xmm0)
152 AS2( test AS_REG_3, AS_REG_3)
154 AS2( movdqa xmm6, xmm4)
155 AS2( punpcklqdq xmm4, xmm2)
156 AS2( punpckhqdq xmm6, xmm2)
157 AS2( test AS_REG_4, 15)
159 AS2( test AS_REG_4, AS_REG_4)
161 AS2( pxor xmm4, [AS_REG_4])
162 AS2( pxor xmm6, [AS_REG_4+16])
163 AS2( add AS_REG_4, 32)
166 AS2( movdqu xmm0, [AS_REG_4])
167 AS2( movdqu xmm2, [AS_REG_4+16])
168 AS2( pxor xmm4, xmm0)
169 AS2( pxor xmm6, xmm2)
170 AS2( add AS_REG_4, 32)
172 AS2( test AS_REG_3, 15)
174 AS2( movdqa XMMWORD_PTR [AS_REG_3], xmm4)
175 AS2( movdqa XMMWORD_PTR [AS_REG_3+16], xmm6)
176 AS2( add AS_REG_3, 32)
179 AS2( movdqu XMMWORD_PTR [AS_REG_3], xmm4)
180 AS2( movdqu XMMWORD_PTR [AS_REG_3+16], xmm6)
181 AS2( add AS_REG_3, 32)
185 AS2( lea AS_REG_1, [AS_REG_6 + 32])
186 AS2( and AS_REG_1, 31*32)
187 AS2( lea AS_REG_7, [AS_REG_6 + (32-24)*32])
188 AS2( and AS_REG_7, 31*32)
190 AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+0*8])
191 AS2( pxor xmm3, xmm0)
192 ASS( pshufd xmm0, xmm0, 2, 3, 0, 1)
193 AS2( movdqa XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+0*8], xmm3)
194 AS2( pxor xmm0, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+2*8])
195 AS2( movdqa XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+2*8], xmm0)
197 AS2( movdqa xmm4, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+2*8])
198 AS2( pxor xmm1, xmm4)
199 AS2( movdqa XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+2*8], xmm1)
200 AS2( pxor xmm4, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+0*8])
201 AS2( movdqa XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+0*8], xmm4)
204 AS2( movdqa xmm3, XMMWORD_PTR [AS_REG_2+3*16])
205 AS2( movdqa xmm2, XMMWORD_PTR [AS_REG_2+2*16])
206 AS2( movdqa xmm1, XMMWORD_PTR [AS_REG_2+1*16])
207 AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_2+0*16])
209 #
if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE
210 AS2( test AS_REG_6, 1)
214 AS2( movdqa xmm7, xmm3)
215 AS2( movss xmm7, xmm6)
216 AS2( movdqa xmm6, xmm2)
217 AS2( movss xmm6, xmm3)
218 AS2( movdqa xmm5, xmm1)
219 AS2( movss xmm5, xmm2)
220 AS2( movdqa xmm4, xmm0)
221 AS2( movss xmm4, xmm1)
222 ASS( pshufd xmm7, xmm7, 0, 3, 2, 1)
223 ASS( pshufd xmm6, xmm6, 0, 3, 2, 1)
224 ASS( pshufd xmm5, xmm5, 0, 3, 2, 1)
225 ASS( pshufd xmm4, xmm4, 0, 3, 2, 1)
226 #
if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE
230 AS3( palignr xmm7, xmm3, 4)
231 AS2( movq xmm6, xmm3)
232 AS3( palignr xmm6, xmm2, 4)
233 AS2( movq xmm5, xmm2)
234 AS3( palignr xmm5, xmm1, 4)
235 AS2( movq xmm4, xmm1)
236 AS3( palignr xmm4, xmm0, 4)
241 AS2( movd AS_REG_1d, xmm0)
242 AS2( xor eax, AS_REG_1d)
243 AS2( movd AS_REG_1d, xmm3)
244 AS2( xor eax, AS_REG_1d)
246 AS2( pxor xmm3, xmm2)
247 AS2( pxor xmm2, xmm1)
248 AS2( pxor xmm1, xmm0)
249 AS2( pxor xmm0, xmm7)
250 AS2( pxor xmm3, xmm7)
251 AS2( pxor xmm2, xmm6)
252 AS2( pxor xmm1, xmm5)
253 AS2( pxor xmm0, xmm4)
256 AS2( lea AS_REG_1, [AS_REG_6 + (32-4)*32])
257 AS2( and AS_REG_1, 31*32)
258 AS2( lea AS_REG_7, [AS_REG_6 + 16*32])
259 AS2( and AS_REG_7, 31*32)
261 AS2( movdqa xmm4, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+0*16])
262 AS2( movdqa xmm5, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+0*16])
263 AS2( movdqa xmm6, xmm4)
264 AS2( punpcklqdq xmm4, xmm5)
265 AS2( punpckhqdq xmm6, xmm5)
266 AS2( pxor xmm3, xmm4)
267 AS2( pxor xmm2, xmm6)
269 AS2( movdqa xmm4, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_1+1*16])
270 AS2( movdqa xmm5, XMMWORD_PTR [AS_REG_2+20*4+AS_REG_7+1*16])
271 AS2( movdqa xmm6, xmm4)
272 AS2( punpcklqdq xmm4, xmm5)
273 AS2( punpckhqdq xmm6, xmm5)
274 AS2( pxor xmm1, xmm4)
275 AS2( pxor xmm0, xmm6)
278 AS2( add AS_REG_6, 32)
279 AS2( cmp AS_REG_6, REG_loopEnd)
283 AS2( mov [AS_REG_2+4*16], eax)
284 AS2( movdqa XMMWORD_PTR [AS_REG_2+3*16], xmm3)
285 AS2( movdqa XMMWORD_PTR [AS_REG_2+2*16], xmm2)
286 AS2( movdqa XMMWORD_PTR [AS_REG_2+1*16], xmm1)
287 AS2( movdqa XMMWORD_PTR [AS_REG_2+0*16], xmm0)
289 #
if CRYPTOPP_BOOL_X32
292 #elif CRYPTOPP_BOOL_X86
298 #
if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
302 #
if CRYPTOPP_BOOL_X64
303 :
"D" (count),
"S" (state),
"d" (z),
"c" (y)
304 :
"%r8",
"%r9",
"r10",
"%eax",
"memory",
"cc",
"%xmm0",
"%xmm1",
"%xmm2",
"%xmm3",
"%xmm4",
"%xmm5",
"%xmm6",
"%xmm7" 306 :
"c" (count),
"d" (state),
"S" (z),
"D" (y)
307 :
"%eax",
"memory",
"cc" 312 #ifdef CRYPTOPP_GENERATE_X64_MASM 313 movdqa xmm6, [rsp + 0h]
314 movdqa xmm7, [rsp + 10h]
318 Panama_SSE2_Pull ENDP
322 #endif // #ifdef CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 324 #ifndef CRYPTOPP_GENERATE_X64_MASM 327 void Panama<B>::Iterate(
size_t count,
const word32 *p, byte *output,
const byte *input, KeystreamOperation operation)
329 word32 bstart = m_state[17];
330 word32 *
const aPtr = m_state;
333 #define bPtr ((byte *)(aPtr+20)) 338 #define a(i) aPtr[((i)*13+16) % 17] // 13 is inverse of 4 mod 17 339 #define c(i) cPtr[((i)*13+16) % 17] 341 #define b(i, j) b##i[(j)*2%8 + (j)/4] 344 #define US(i) {word32 t=b(0,i); b(0,i)=ConditionalByteReverse(B::ToEnum(), p[i])^t; b(25,(i+6)%8)^=t;} 345 #define UL(i) {word32 t=b(0,i); b(0,i)=a(i+1)^t; b(25,(i+6)%8)^=t;} 347 #define GP(i) c(5*i%17) = rotlFixed(a(i) ^ (a((i+1)%17) | ~a((i+2)%17)), ((5*i%17)*((5*i%17)+1)/2)%32) 349 #define T(i,x) a(i) = c(i) ^ c((i+1)%17) ^ c((i+4)%17) ^ x 350 #define TS1S(i) T(i+1, ConditionalByteReverse(B::ToEnum(), p[i])) 351 #define TS1L(i) T(i+1, b(4,i)) 352 #define TS2(i) T(i+9, b(16,i)) 358 #define PANAMA_OUTPUT(x) \ 359 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, a(0+9));\ 360 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 1, a(1+9));\ 361 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 2, a(2+9));\ 362 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 3, a(3+9));\ 363 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 4, a(4+9));\ 364 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 5, a(5+9));\ 365 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 6, a(6+9));\ 366 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 7, a(7+9)); 368 typedef word32 WordType;
369 CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(PANAMA_OUTPUT, 4*8);
372 word32 *
const b16 = (word32 *)(bPtr+((bstart+16*32) & 31*32));
373 word32 *
const b4 = (word32 *)(bPtr+((bstart+(32-4)*32) & 31*32));
375 word32 *
const b0 = (word32 *)(bPtr+((bstart) & 31*32));
376 word32 *
const b25 = (word32 *)(bPtr+((bstart+(32-25)*32) & 31*32));
380 US(0); US(1); US(2); US(3); US(4); US(5); US(6); US(7);
384 UL(0); UL(1); UL(2); UL(3); UL(4); UL(5); UL(6); UL(7);
409 TS1S(0); TS1S(1); TS1S(2); TS1S(3); TS1S(4); TS1S(5); TS1S(6); TS1S(7);
414 TS1L(0); TS1L(1); TS1L(2); TS1L(3); TS1L(4); TS1L(5); TS1L(6); TS1L(7);
417 TS2(0); TS2(1); TS2(2); TS2(3); TS2(4); TS2(5); TS2(6); TS2(7);
419 m_state[17] = bstart;
424 size_t PanamaHash<B>::HashMultipleBlocks(
const word32 *input,
size_t length)
426 this->Iterate(length / this->BLOCKSIZE, input);
427 return length % this->BLOCKSIZE;
433 this->ThrowIfInvalidTruncatedSize(size);
435 this->PadLastBlock(this->BLOCKSIZE, 0x01);
437 HashEndianCorrectedBlock(this->m_data);
442 this->Iterate(1, NULL, buf.
BytePtr(), NULL);
444 memcpy(hash, buf, size);
453 CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(length);
455 memcpy(m_key, key, 32);
461 CRYPTOPP_UNUSED(keystreamBuffer); CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(length);
464 this->Iterate(1, m_key);
465 if (iv && IsAligned<word32>(iv))
466 this->Iterate(1, (
const word32 *)iv);
474 this->Iterate(1, buf);
477 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 478 if (B::ToEnum() == LITTLE_ENDIAN_ORDER && HasSSE2() && !IsP4())
479 Panama_SSE2_Pull(32, this->m_state, NULL, NULL);
488 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 489 if (B::ToEnum() == LITTLE_ENDIAN_ORDER && HasSSE2())
499 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 500 if (B::ToEnum() == LITTLE_ENDIAN_ORDER && HasSSE2())
501 Panama_SSE2_Pull(iterationCount, this->m_state, (word32 *)output, (
const word32 *)input);
504 this->Iterate(iterationCount, NULL, output, input, operation);
518 #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM Utility functions for the Crypto++ library.
Classes and functions for secure memory allocations.
Classes for Panama stream cipher.
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
Classes, functions, intrinsics and features for X86, X32 nd X64 assembly.
base class, do not use directly
Crypto++ library namespace.
Namespace containing weak and wounded algorithms.
Interface for retrieving values given their names.
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.