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 35 #elif CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 37 #ifdef CRYPTOPP_GENERATE_X64_MASM 38 Panama_SSE2_Pull PROC FRAME
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
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)
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 + 0
h]
314 movdqa xmm7, [rsp + 10
h]
318 Panama_SSE2_Pull ENDP
322 #endif // #ifdef CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 324 #ifndef CRYPTOPP_GENERATE_X64_MASM 330 word32 bstart = m_state[17];
331 word32 *
const aPtr = m_state;
334 #define bPtr ((byte *)(aPtr+20)) 339 #define a(i) aPtr[((i)*13+16) % 17] // 13 is inverse of 4 mod 17 340 #define c(i) cPtr[((i)*13+16) % 17] 342 #define b(i, j) b##i[(j)*2%8 + (j)/4] 345 #define US(i) {word32 t=b(0,i); b(0,i)=ConditionalByteReverse(B::ToEnum(), p[i])^t; b(25,(i+6)%8)^=t;} 346 #define UL(i) {word32 t=b(0,i); b(0,i)=a(i+1)^t; b(25,(i+6)%8)^=t;} 348 #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) 350 #define T(i,x) a(i) = c(i) ^ c((i+1)%17) ^ c((i+4)%17) ^ x 351 #define TS1S(i) T(i+1, ConditionalByteReverse(B::ToEnum(), p[i])) 352 #define TS1L(i) T(i+1, b(4,i)) 353 #define TS2(i) T(i+9, b(16,i)) 359 #define PANAMA_OUTPUT(x) \ 360 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 0, a(0+9));\ 361 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 1, a(1+9));\ 362 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 2, a(2+9));\ 363 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 3, a(3+9));\ 364 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 4, a(4+9));\ 365 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 5, a(5+9));\ 366 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 6, a(6+9));\ 367 CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, B::ToEnum(), 7, a(7+9)); 420 m_state[17] = bstart;
427 this->Iterate(length / this->BLOCKSIZE, input);
428 return length % this->BLOCKSIZE;
434 this->ThrowIfInvalidTruncatedSize(size);
436 this->PadLastBlock(this->BLOCKSIZE, 0x01);
438 HashEndianCorrectedBlock(this->m_data);
443 this->Iterate(1, NULL, buf.
BytePtr(), NULL);
467 this->Iterate(1, m_key);
468 if (iv && IsAligned<word32>(iv))
469 this->Iterate(1, (
const word32 *)(
void *)iv);
477 this->Iterate(1, buf);
480 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 482 Panama_SSE2_Pull(32, this->m_state, NULL, NULL);
491 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 502 #if (CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) 504 Panama_SSE2_Pull(iterationCount, this->m_state, (
word32 *)(
void *)output, (
const word32 *)(
void *)input);
507 this->Iterate(iterationCount, NULL, output, input, operation);
521 #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM
#define CRYPTOPP_BOOL_X64
Utility functions for the Crypto++ library.
void CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length)
Resynchronize the cipher.
#define NAMESPACE_BEGIN(x)
#define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY
#define CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(x, y)
Helper macro to implement OperateKeystream.
byte order is little-endian
void Iterate(size_t count, const word32 *p=NULL, byte *output=NULL, const byte *input=NULL, KeystreamOperation operation=WRITE_KEYSTREAM)
Classes and functions for secure memory allocations.
bool IsAlignedOn(const void *ptr, unsigned int alignment)
Determines whether ptr is aligned to a minimum value.
Classes for Panama hash and stream cipher.
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
unsigned int GetAlignment() const
Provides data alignment requirements.
#define CRYPTOPP_ASSERT(exp)
Functions for CPU features and intrinsics.
#define CRYPTOPP_NOINLINE
Panama stream cipher operation.
#define CRYPTOPP_BOOL_X32
uint8_t const size_t const size
#define CRYPTOPP_BOOL_X86
void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount)
Operates the keystream.
void * memcpy(void *a, const void *b, size_t c)
#define CRYPTOPP_UNUSED(x)
KeystreamOperation
Keystream operation flags.
void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length)
Key the cipher.
size_t HashMultipleBlocks(const word32 *input, size_t length)
Interface for retrieving values given their names.
byte * BytePtr()
Provides a byte pointer to the first element in the memory block.