1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
7 ; * Redistributions of source code must retain the above copyright
8 ; notice, this list of conditions and the following disclaimer.
9 ; * Redistributions in binary form must reproduce the above copyright
10 ; notice, this list of conditions and the following disclaimer in
11 ; the documentation and/or other materials provided with the
13 ; * Neither the name of Intel Corporation nor the names of its
14 ; contributors may be used to endorse or promote products derived
15 ; from this software without specific prior written permission.
17 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ; XTS encrypt function with 256-bit AES
30 ; input keys are not aligned
31 ; keys are expanded in parallel with the tweak encryption
32 ; plaintext and ciphertext are not aligned
33 ; second key is stored in the stack as aligned to 16 Bytes
34 ; first key is required only once, no need for storage of this key
36 %include "reg_sizes.asm"
39 %define TW rsp ; store 8 tweak values
40 %define keys rsp + 16*8 ; store 15 expanded keys
42 %ifidn __OUTPUT_FORMAT__, win64
43 %define _xmm rsp + 16*23 ; store xmm6:xmm15
46 %ifidn __OUTPUT_FORMAT__, elf64
47 %define _gpr rsp + 16*23 ; store rbx
48 %define VARIABLE_OFFSET 16*8 + 16*15 + 8*1 ; VARIABLE_OFFSET has to be an odd multiple of 8
50 %define _gpr rsp + 16*33 ; store rdi, rsi, rbx
51 %define VARIABLE_OFFSET 16*8 + 16*15 + 16*10 + 8*3 ; VARIABLE_OFFSET has to be an odd multiple of 8
54 %define GHASH_POLY 0x87
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 ;void XTS_AES_256_enc_sse(
58 ; UINT8 *k2, // key used for tweaking, 16*2 bytes
59 ; UINT8 *k1, // key used for "ECB" encryption, 16*2 bytes
60 ; UINT8 *TW_initial, // initial tweak value, 16 bytes
61 ; UINT64 N, // sector size, in bytes
62 ; const UINT8 *pt, // plaintext sector input data
63 ; UINT8 *ct); // ciphertext sector output data
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 ; arguments for input parameters
67 %ifidn __OUTPUT_FORMAT__, elf64
72 %xdefine ptr_plaintext r8
73 %xdefine ptr_ciphertext r9
79 %xdefine ptr_plaintext r10; [rsp + VARIABLE_OFFSET + 8*5]
80 %xdefine ptr_ciphertext r11; [rsp + VARIABLE_OFFSET + 8*6]
83 ; arguments for temp parameters
84 %ifidn __OUTPUT_FORMAT__, elf64
86 %define target_ptr_val rsi
87 %define ghash_poly_8b r10
88 %define ghash_poly_8b_temp r11
91 %define target_ptr_val rdx
92 %define ghash_poly_8b rdi
93 %define ghash_poly_8b_temp rsi
96 %define twtempl rax ; global temp registers used for tweak computation
100 ; produce the key for the next round
101 ; raw_key is the output of aeskeygenassist instruction
102 ; round_key value before this key_expansion_128 macro is current round key
103 ; round_key value after this key_expansion_128 macro is next round key
104 ; 2 macros will be used for key generation in a flip-flopped fashion
105 %macro key_expansion_256_flip 3
106 %define %%xraw_key %1
108 %define %%xround_key %3
109 pshufd %%xraw_key, %%xraw_key, 11111111b
110 shufps %%xtmp, %%xround_key, 00010000b
111 pxor %%xround_key, %%xtmp
112 shufps %%xtmp, %%xround_key, 10001100b
113 pxor %%xround_key, %%xtmp
114 pxor %%xround_key, %%xraw_key
117 %macro key_expansion_256_flop 3
118 %define %%xraw_key %1
120 %define %%xround_key %3
121 pshufd %%xraw_key, %%xraw_key, 10101010b
122 shufps %%xtmp, %%xround_key, 00010000b
123 pxor %%xround_key, %%xtmp
124 shufps %%xtmp, %%xround_key, 10001100b
125 pxor %%xround_key, %%xtmp
126 pxor %%xround_key, %%xraw_key
132 ; macro to encrypt the tweak value in parallel with key generation of both keys
137 %define %%xstate_tweak %3
140 %define %%xraw_key %6
142 %define %%ptr_key2 %8
143 %define %%ptr_key1 %9
144 %define %%ptr_expanded_keys %10
147 movdqu %%xkey2, [%%ptr_key2]
148 pxor %%xstate_tweak, %%xkey2 ; ARK for tweak encryption
150 movdqu %%xkey1, [%%ptr_key1]
151 movdqa [%%ptr_expanded_keys+16*0], %%xkey1
153 movdqu %%xkey2_2, [%%ptr_key2 + 16*1]
154 aesenc %%xstate_tweak, %%xkey2_2 ; round 1 for tweak encryption
156 movdqu %%xkey1_2, [%%ptr_key1 + 16*1]
157 movdqa [%%ptr_expanded_keys+16*1], %%xkey1_2
162 aeskeygenassist %%xraw_key, %%xkey2_2, 0x1 ; Generating round key 2 for key2
163 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
164 aeskeygenassist %%xraw_key, %%xkey1_2, 0x1 ; Generating round key 2 for key1
165 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
166 aesenc %%xstate_tweak, %%xkey2 ; round 2 for tweak encryption
167 movdqa [%%ptr_expanded_keys+16*2], %%xkey1
169 aeskeygenassist %%xraw_key, %%xkey2, 0x1 ; Generating round key 3 for key2
170 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
171 aeskeygenassist %%xraw_key, %%xkey1, 0x1 ; Generating round key 3 for key1
172 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
173 aesenc %%xstate_tweak, %%xkey2_2 ; round 3 for tweak encryption
174 movdqa [%%ptr_expanded_keys+16*3], %%xkey1_2
178 aeskeygenassist %%xraw_key, %%xkey2_2, 0x2 ; Generating round key 4 for key2
179 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
180 aeskeygenassist %%xraw_key, %%xkey1_2, 0x2 ; Generating round key 4 for key1
181 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
182 aesenc %%xstate_tweak, %%xkey2 ; round 4 for tweak encryption
183 movdqa [%%ptr_expanded_keys+16*4], %%xkey1
185 aeskeygenassist %%xraw_key, %%xkey2, 0x2 ; Generating round key 5 for key2
186 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
187 aeskeygenassist %%xraw_key, %%xkey1, 0x2 ; Generating round key 5 for key1
188 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
189 aesenc %%xstate_tweak, %%xkey2_2 ; round 5 for tweak encryption
190 movdqa [%%ptr_expanded_keys+16*5], %%xkey1_2
194 aeskeygenassist %%xraw_key, %%xkey2_2, 0x4 ; Generating round key 6 for key2
195 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
196 aeskeygenassist %%xraw_key, %%xkey1_2, 0x4 ; Generating round key 6 for key1
197 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
198 aesenc %%xstate_tweak, %%xkey2 ; round 6 for tweak encryption
199 movdqa [%%ptr_expanded_keys+16*6], %%xkey1
201 aeskeygenassist %%xraw_key, %%xkey2, 0x4 ; Generating round key 7 for key2
202 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
203 aeskeygenassist %%xraw_key, %%xkey1, 0x4 ; Generating round key 7 for key1
204 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
205 aesenc %%xstate_tweak, %%xkey2_2 ; round 7 for tweak encryption
206 movdqa [%%ptr_expanded_keys+16*7], %%xkey1_2
209 aeskeygenassist %%xraw_key, %%xkey2_2, 0x8 ; Generating round key 8 for key2
210 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
211 aeskeygenassist %%xraw_key, %%xkey1_2, 0x8 ; Generating round key 8 for key1
212 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
213 aesenc %%xstate_tweak, %%xkey2 ; round 8 for tweak encryption
214 movdqa [%%ptr_expanded_keys+16*8], %%xkey1
216 aeskeygenassist %%xraw_key, %%xkey2, 0x8 ; Generating round key 9 for key2
217 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
218 aeskeygenassist %%xraw_key, %%xkey1, 0x8 ; Generating round key 9 for key1
219 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
220 aesenc %%xstate_tweak, %%xkey2_2 ; round 9 for tweak encryption
221 movdqa [%%ptr_expanded_keys+16*9], %%xkey1_2
224 aeskeygenassist %%xraw_key, %%xkey2_2, 0x10 ; Generating round key 10 for key2
225 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
226 aeskeygenassist %%xraw_key, %%xkey1_2, 0x10 ; Generating round key 10 for key1
227 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
228 aesenc %%xstate_tweak, %%xkey2 ; round 10 for tweak encryption
229 movdqa [%%ptr_expanded_keys+16*10], %%xkey1
231 aeskeygenassist %%xraw_key, %%xkey2, 0x10 ; Generating round key 11 for key2
232 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
233 aeskeygenassist %%xraw_key, %%xkey1, 0x10 ; Generating round key 11 for key1
234 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
235 aesenc %%xstate_tweak, %%xkey2_2 ; round 11 for tweak encryption
236 movdqa [%%ptr_expanded_keys+16*11], %%xkey1_2
239 aeskeygenassist %%xraw_key, %%xkey2_2, 0x20 ; Generating round key 12 for key2
240 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
241 aeskeygenassist %%xraw_key, %%xkey1_2, 0x20 ; Generating round key 12 for key1
242 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
243 aesenc %%xstate_tweak, %%xkey2 ; round 12 for tweak encryption
244 movdqa [%%ptr_expanded_keys+16*12], %%xkey1
246 aeskeygenassist %%xraw_key, %%xkey2, 0x20 ; Generating round key 13 for key2
247 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey2_2
248 aeskeygenassist %%xraw_key, %%xkey1, 0x20 ; Generating round key 13 for key1
249 key_expansion_256_flop %%xraw_key, %%xtmp, %%xkey1_2
250 aesenc %%xstate_tweak, %%xkey2_2 ; round 13 for tweak encryption
251 movdqa [%%ptr_expanded_keys+16*13], %%xkey1_2
254 aeskeygenassist %%xraw_key, %%xkey2_2, 0x40 ; Generating round key 14 for key2
255 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey2
256 aeskeygenassist %%xraw_key, %%xkey1_2, 0x40 ; Generating round key 14 for key1
257 key_expansion_256_flip %%xraw_key, %%xtmp, %%xkey1
258 aesenclast %%xstate_tweak, %%xkey2 ; round 14 for tweak encryption
259 movdqa [%%ptr_expanded_keys+16*14], %%xkey1
261 movdqa [TW], %%xstate_tweak ; Store the encrypted Tweak value
265 ; generate initial tweak values
266 ; load initial plaintext values
269 %define %%ST1 %1 ; state 1
270 %define %%ST2 %2 ; state 2
271 %define %%ST3 %3 ; state 3
272 %define %%ST4 %4 ; state 4
273 %define %%ST5 %5 ; state 5
274 %define %%ST6 %6 ; state 6
275 %define %%ST7 %7 ; state 7
276 %define %%ST8 %8 ; state 8
278 %define %%TW1 %9 ; tweak 1
279 %define %%TW2 %10 ; tweak 2
280 %define %%TW3 %11 ; tweak 3
281 %define %%TW4 %12 ; tweak 4
282 %define %%TW5 %13 ; tweak 5
283 %define %%TW6 %14 ; tweak 6
284 %define %%TW7 %15 ; tweak 7
286 %define %%num_initial_blocks %16
289 ; generate next Tweak values
290 movdqa %%TW1, [TW+16*0]
291 mov twtempl, [TW+8*0]
292 mov twtemph, [TW+8*1]
293 movdqu %%ST1, [ptr_plaintext+16*0]
294 %if (%%num_initial_blocks>=2)
295 xor ghash_poly_8b_temp, ghash_poly_8b_temp
298 cmovc ghash_poly_8b_temp, ghash_poly_8b
299 xor twtempl, ghash_poly_8b_temp
300 mov [TW+8*2], twtempl
301 mov [TW+8*3], twtemph;
302 movdqa %%TW2, [TW+16*1]
303 movdqu %%ST2, [ptr_plaintext+16*1]
305 %if (%%num_initial_blocks>=3)
306 xor ghash_poly_8b_temp, ghash_poly_8b_temp
309 cmovc ghash_poly_8b_temp, ghash_poly_8b
310 xor twtempl, ghash_poly_8b_temp
311 mov [TW+8*4], twtempl
312 mov [TW+8*5], twtemph;
313 movdqa %%TW3, [TW+16*2]
314 movdqu %%ST3, [ptr_plaintext+16*2]
316 %if (%%num_initial_blocks>=4)
317 xor ghash_poly_8b_temp, ghash_poly_8b_temp
320 cmovc ghash_poly_8b_temp, ghash_poly_8b
321 xor twtempl, ghash_poly_8b_temp
322 mov [TW+8*6], twtempl
323 mov [TW+8*7], twtemph;
324 movdqa %%TW4, [TW+16*3]
325 movdqu %%ST4, [ptr_plaintext+16*3]
327 %if (%%num_initial_blocks>=5)
328 xor ghash_poly_8b_temp, ghash_poly_8b_temp
331 cmovc ghash_poly_8b_temp, ghash_poly_8b
332 xor twtempl, ghash_poly_8b_temp
333 mov [TW+8*8], twtempl
334 mov [TW+8*9], twtemph;
335 movdqa %%TW5, [TW+16*4]
336 movdqu %%ST5, [ptr_plaintext+16*4]
338 %if (%%num_initial_blocks>=6)
339 xor ghash_poly_8b_temp, ghash_poly_8b_temp
342 cmovc ghash_poly_8b_temp, ghash_poly_8b
343 xor twtempl, ghash_poly_8b_temp
344 mov [TW+8*10], twtempl
345 mov [TW+8*11], twtemph;
346 movdqa %%TW6, [TW+16*5]
347 movdqu %%ST6, [ptr_plaintext+16*5]
349 %if (%%num_initial_blocks>=7)
350 xor ghash_poly_8b_temp, ghash_poly_8b_temp
353 cmovc ghash_poly_8b_temp, ghash_poly_8b
354 xor twtempl, ghash_poly_8b_temp
355 mov [TW+8*12], twtempl
356 mov [TW+8*13], twtemph;
357 movdqa %%TW7, [TW+16*6]
358 movdqu %%ST7, [ptr_plaintext+16*6]
366 ; encrypt initial blocks of AES
367 ; 1, 2, 3, 4, 5, 6 or 7 blocks are encrypted
368 ; next 8 Tweak values are generated
369 %macro encrypt_initial 18
370 %define %%ST1 %1 ; state 1
371 %define %%ST2 %2 ; state 2
372 %define %%ST3 %3 ; state 3
373 %define %%ST4 %4 ; state 4
374 %define %%ST5 %5 ; state 5
375 %define %%ST6 %6 ; state 6
376 %define %%ST7 %7 ; state 7
377 %define %%ST8 %8 ; state 8
379 %define %%TW1 %9 ; tweak 1
380 %define %%TW2 %10 ; tweak 2
381 %define %%TW3 %11 ; tweak 3
382 %define %%TW4 %12 ; tweak 4
383 %define %%TW5 %13 ; tweak 5
384 %define %%TW6 %14 ; tweak 6
385 %define %%TW7 %15 ; tweak 7
386 %define %%T0 %16 ; Temp register
387 %define %%num_blocks %17
388 ; %%num_blocks blocks encrypted
389 ; %%num_blocks can be 1, 2, 3, 4, 5, 6, 7
391 %define %%lt128 %18 ; less than 128 bytes
395 %if (%%num_blocks>=2)
398 %if (%%num_blocks>=3)
401 %if (%%num_blocks>=4)
404 %if (%%num_blocks>=5)
407 %if (%%num_blocks>=6)
410 %if (%%num_blocks>=7)
418 %if (%%num_blocks>=2)
421 %if (%%num_blocks>=3)
424 %if (%%num_blocks>=4)
427 %if (%%num_blocks>=5)
430 %if (%%num_blocks>=6)
433 %if (%%num_blocks>=7)
439 xor ghash_poly_8b_temp, ghash_poly_8b_temp
445 movdqa %%T0, [keys + 16*1]
447 %if (%%num_blocks>=2)
450 %if (%%num_blocks>=3)
453 %if (%%num_blocks>=4)
456 %if (%%num_blocks>=5)
459 %if (%%num_blocks>=6)
462 %if (%%num_blocks>=7)
466 cmovc ghash_poly_8b_temp, ghash_poly_8b
467 xor twtempl, ghash_poly_8b_temp
468 mov [TW + 8*0], twtempl ; next Tweak1 generated
469 mov [TW + 8*1], twtemph
470 xor ghash_poly_8b_temp, ghash_poly_8b_temp
474 movdqa %%T0, [keys + 16*2]
476 %if (%%num_blocks>=2)
479 %if (%%num_blocks>=3)
482 %if (%%num_blocks>=4)
485 %if (%%num_blocks>=5)
488 %if (%%num_blocks>=6)
491 %if (%%num_blocks>=7)
498 cmovc ghash_poly_8b_temp, ghash_poly_8b
499 xor twtempl, ghash_poly_8b_temp
500 mov [TW + 8*2], twtempl ; next Tweak2 generated
504 movdqa %%T0, [keys + 16*3]
506 %if (%%num_blocks>=2)
509 %if (%%num_blocks>=3)
512 %if (%%num_blocks>=4)
515 %if (%%num_blocks>=5)
518 %if (%%num_blocks>=6)
521 %if (%%num_blocks>=7)
525 mov [TW + 8*3], twtemph
526 xor ghash_poly_8b_temp, ghash_poly_8b_temp
529 cmovc ghash_poly_8b_temp, ghash_poly_8b
533 movdqa %%T0, [keys + 16*4]
535 %if (%%num_blocks>=2)
538 %if (%%num_blocks>=3)
541 %if (%%num_blocks>=4)
544 %if (%%num_blocks>=5)
547 %if (%%num_blocks>=6)
550 %if (%%num_blocks>=7)
555 xor twtempl, ghash_poly_8b_temp
556 mov [TW + 8*4], twtempl ; next Tweak3 generated
557 mov [TW + 8*5], twtemph
558 xor ghash_poly_8b_temp, ghash_poly_8b_temp
563 movdqa %%T0, [keys + 16*5]
565 %if (%%num_blocks>=2)
568 %if (%%num_blocks>=3)
571 %if (%%num_blocks>=4)
574 %if (%%num_blocks>=5)
577 %if (%%num_blocks>=6)
580 %if (%%num_blocks>=7)
586 cmovc ghash_poly_8b_temp, ghash_poly_8b
587 xor twtempl, ghash_poly_8b_temp
588 mov [TW + 8*6], twtempl ; next Tweak4 generated
589 mov [TW + 8*7], twtemph
593 movdqa %%T0, [keys + 16*6]
595 %if (%%num_blocks>=2)
598 %if (%%num_blocks>=3)
601 %if (%%num_blocks>=4)
604 %if (%%num_blocks>=5)
607 %if (%%num_blocks>=6)
610 %if (%%num_blocks>=7)
615 xor ghash_poly_8b_temp, ghash_poly_8b_temp
618 cmovc ghash_poly_8b_temp, ghash_poly_8b
619 xor twtempl, ghash_poly_8b_temp
620 mov [TW + 8*8], twtempl ; next Tweak5 generated
621 mov [TW + 8*9], twtemph
625 movdqa %%T0, [keys + 16*7]
627 %if (%%num_blocks>=2)
630 %if (%%num_blocks>=3)
633 %if (%%num_blocks>=4)
636 %if (%%num_blocks>=5)
639 %if (%%num_blocks>=6)
642 %if (%%num_blocks>=7)
647 xor ghash_poly_8b_temp, ghash_poly_8b_temp
650 cmovc ghash_poly_8b_temp, ghash_poly_8b
651 xor twtempl, ghash_poly_8b_temp
652 mov [TW + 8*10], twtempl ; next Tweak6 generated
653 mov [TW + 8*11], twtemph
656 movdqa %%T0, [keys + 16*8]
658 %if (%%num_blocks>=2)
661 %if (%%num_blocks>=3)
664 %if (%%num_blocks>=4)
667 %if (%%num_blocks>=5)
670 %if (%%num_blocks>=6)
673 %if (%%num_blocks>=7)
678 xor ghash_poly_8b_temp, ghash_poly_8b_temp
681 cmovc ghash_poly_8b_temp, ghash_poly_8b
682 xor twtempl, ghash_poly_8b_temp
683 mov [TW + 8*12], twtempl ; next Tweak7 generated
684 mov [TW + 8*13], twtemph
687 movdqa %%T0, [keys + 16*9]
689 %if (%%num_blocks>=2)
692 %if (%%num_blocks>=3)
695 %if (%%num_blocks>=4)
698 %if (%%num_blocks>=5)
701 %if (%%num_blocks>=6)
704 %if (%%num_blocks>=7)
709 xor ghash_poly_8b_temp, ghash_poly_8b_temp
712 cmovc ghash_poly_8b_temp, ghash_poly_8b
713 xor twtempl, ghash_poly_8b_temp
714 mov [TW + 8*14], twtempl ; next Tweak8 generated
715 mov [TW + 8*15], twtemph
718 movdqa %%T0, [keys + 16*10]
720 %if (%%num_blocks>=2)
723 %if (%%num_blocks>=3)
726 %if (%%num_blocks>=4)
729 %if (%%num_blocks>=5)
732 %if (%%num_blocks>=6)
735 %if (%%num_blocks>=7)
739 movdqa %%T0, [keys + 16*11]
741 %if (%%num_blocks>=2)
744 %if (%%num_blocks>=3)
747 %if (%%num_blocks>=4)
750 %if (%%num_blocks>=5)
753 %if (%%num_blocks>=6)
756 %if (%%num_blocks>=7)
761 movdqa %%T0, [keys + 16*12]
763 %if (%%num_blocks>=2)
766 %if (%%num_blocks>=3)
769 %if (%%num_blocks>=4)
772 %if (%%num_blocks>=5)
775 %if (%%num_blocks>=6)
778 %if (%%num_blocks>=7)
783 movdqa %%T0, [keys + 16*13]
785 %if (%%num_blocks>=2)
788 %if (%%num_blocks>=3)
791 %if (%%num_blocks>=4)
794 %if (%%num_blocks>=5)
797 %if (%%num_blocks>=6)
800 %if (%%num_blocks>=7)
805 movdqa %%T0, [keys + 16*14]
806 aesenclast %%ST1, %%T0
807 %if (%%num_blocks>=2)
808 aesenclast %%ST2, %%T0
810 %if (%%num_blocks>=3)
811 aesenclast %%ST3, %%T0
813 %if (%%num_blocks>=4)
814 aesenclast %%ST4, %%T0
816 %if (%%num_blocks>=5)
817 aesenclast %%ST5, %%T0
819 %if (%%num_blocks>=6)
820 aesenclast %%ST6, %%T0
822 %if (%%num_blocks>=7)
823 aesenclast %%ST7, %%T0
828 %if (%%num_blocks>=2)
831 %if (%%num_blocks>=3)
834 %if (%%num_blocks>=4)
837 %if (%%num_blocks>=5)
840 %if (%%num_blocks>=6)
843 %if (%%num_blocks>=7)
849 ; load next Tweak values
850 movdqa %%TW1, [TW + 16*0]
851 movdqa %%TW2, [TW + 16*1]
852 movdqa %%TW3, [TW + 16*2]
853 movdqa %%TW4, [TW + 16*3]
854 movdqa %%TW5, [TW + 16*4]
855 movdqa %%TW6, [TW + 16*5]
856 movdqa %%TW7, [TW + 16*6]
863 ; Encrypt 8 blocks in parallel
864 ; generate next 8 tweak values
865 %macro encrypt_by_eight 18
866 %define %%ST1 %1 ; state 1
867 %define %%ST2 %2 ; state 2
868 %define %%ST3 %3 ; state 3
869 %define %%ST4 %4 ; state 4
870 %define %%ST5 %5 ; state 5
871 %define %%ST6 %6 ; state 6
872 %define %%ST7 %7 ; state 7
873 %define %%ST8 %8 ; state 8
874 %define %%TW1 %9 ; tweak 1
875 %define %%TW2 %10 ; tweak 2
876 %define %%TW3 %11 ; tweak 3
877 %define %%TW4 %12 ; tweak 4
878 %define %%TW5 %13 ; tweak 5
879 %define %%TW6 %14 ; tweak 6
880 %define %%TW7 %15 ; tweak 7
881 %define %%TW8 %16 ; tweak 8
882 %define %%T0 %17 ; Temp register
883 %define %%last_eight %18
906 %if (0 == %%last_eight)
907 xor ghash_poly_8b_temp, ghash_poly_8b_temp
910 cmovc ghash_poly_8b_temp, ghash_poly_8b
913 movdqa %%T0, [keys + 16*1]
922 %if (0 == %%last_eight)
923 xor twtempl, ghash_poly_8b_temp
924 mov [TW + 8*0], twtempl
925 mov [TW + 8*1], twtemph
926 xor ghash_poly_8b_temp, ghash_poly_8b_temp
929 movdqa %%T0, [keys + 16*2]
938 %if (0 == %%last_eight)
941 cmovc ghash_poly_8b_temp, ghash_poly_8b
942 xor twtempl, ghash_poly_8b_temp
946 movdqa %%T0, [keys + 16*3]
955 %if (0 == %%last_eight)
956 mov [TW + 8*2], twtempl
957 mov [TW + 8*3], twtemph
958 xor ghash_poly_8b_temp, ghash_poly_8b_temp
962 movdqa %%T0, [keys + 16*4]
971 %if (0 == %%last_eight)
973 cmovc ghash_poly_8b_temp, ghash_poly_8b
974 xor twtempl, ghash_poly_8b_temp
975 mov [TW + 8*4], twtempl
978 movdqa %%T0, [keys + 16*5]
987 %if (0 == %%last_eight)
988 mov [TW + 8*5], twtemph
989 xor ghash_poly_8b_temp, ghash_poly_8b_temp
994 movdqa %%T0, [keys + 16*6]
1003 %if (0 == %%last_eight)
1004 cmovc ghash_poly_8b_temp, ghash_poly_8b
1005 xor twtempl, ghash_poly_8b_temp
1006 mov [TW + 8*6], twtempl
1007 mov [TW + 8*7], twtemph
1010 movdqa %%T0, [keys + 16*7]
1019 %if (0 == %%last_eight)
1020 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1022 adc twtemph, twtemph
1023 cmovc ghash_poly_8b_temp, ghash_poly_8b
1026 movdqa %%T0, [keys + 16*8]
1035 %if (0 == %%last_eight)
1036 xor twtempl, ghash_poly_8b_temp
1037 mov [TW + 8*8], twtempl
1038 mov [TW + 8*9], twtemph
1039 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1042 movdqa %%T0, [keys + 16*9]
1051 %if (0 == %%last_eight)
1053 adc twtemph, twtemph
1054 cmovc ghash_poly_8b_temp, ghash_poly_8b
1055 xor twtempl, ghash_poly_8b_temp
1058 movdqa %%T0, [keys + 16*10]
1067 %if (0 == %%last_eight)
1068 mov [TW + 8*10], twtempl
1069 mov [TW + 8*11], twtemph
1070 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1074 movdqa %%T0, [keys + 16*11]
1083 %if (0 == %%last_eight)
1084 adc twtemph, twtemph
1085 cmovc ghash_poly_8b_temp, ghash_poly_8b
1086 xor twtempl, ghash_poly_8b_temp
1087 mov [TW + 8*12], twtempl
1090 movdqa %%T0, [keys + 16*12]
1099 %if (0 == %%last_eight)
1100 mov [TW + 8*13], twtemph
1101 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1103 adc twtemph, twtemph
1106 movdqa %%T0, [keys + 16*13]
1115 %if (0 == %%last_eight)
1116 cmovc ghash_poly_8b_temp, ghash_poly_8b
1117 xor twtempl, ghash_poly_8b_temp
1118 ; mov [TW + 8*14], twtempl
1119 ; mov [TW + 8*15], twtemph
1122 movdqa %%T0, [keys + 16*14]
1123 aesenclast %%ST1, %%T0
1124 aesenclast %%ST2, %%T0
1125 aesenclast %%ST3, %%T0
1126 aesenclast %%ST4, %%T0
1127 aesenclast %%ST5, %%T0
1128 aesenclast %%ST6, %%T0
1129 aesenclast %%ST7, %%T0
1130 aesenclast %%ST8, %%T0
1142 mov [TW + 8*14], twtempl
1143 mov [TW + 8*15], twtemph
1144 ; load next Tweak values
1145 movdqa %%TW1, [TW + 16*0]
1146 movdqa %%TW2, [TW + 16*1]
1147 movdqa %%TW3, [TW + 16*2]
1148 movdqa %%TW4, [TW + 16*3]
1149 movdqa %%TW5, [TW + 16*4]
1150 movdqa %%TW6, [TW + 16*5]
1151 movdqa %%TW7, [TW + 16*6]
1158 global XTS_AES_256_enc_sse:function
1159 XTS_AES_256_enc_sse:
1161 sub rsp, VARIABLE_OFFSET
1163 mov [_gpr + 8*0], rbx
1164 %ifidn __OUTPUT_FORMAT__, win64
1165 mov [_gpr + 8*1], rdi
1166 mov [_gpr + 8*2], rsi
1168 movdqa [_xmm + 16*0], xmm6
1169 movdqa [_xmm + 16*1], xmm7
1170 movdqa [_xmm + 16*2], xmm8
1171 movdqa [_xmm + 16*3], xmm9
1172 movdqa [_xmm + 16*4], xmm10
1173 movdqa [_xmm + 16*5], xmm11
1174 movdqa [_xmm + 16*6], xmm12
1175 movdqa [_xmm + 16*7], xmm13
1176 movdqa [_xmm + 16*8], xmm14
1177 movdqa [_xmm + 16*9], xmm15
1180 mov ghash_poly_8b, GHASH_POLY ; load 0x87 to ghash_poly_8b
1183 movdqu xmm1, [T_val] ; read initial Tweak value
1184 pxor xmm4, xmm4 ; for key expansion
1185 encrypt_T xmm0, xmm5, xmm1, xmm2, xmm6, xmm3, xmm4, ptr_key2, ptr_key1, keys
1188 %ifidn __OUTPUT_FORMAT__, win64
1189 mov ptr_plaintext, [rsp + VARIABLE_OFFSET + 8*5] ; plaintext pointer
1190 mov ptr_ciphertext, [rsp + VARIABLE_OFFSET + 8*6] ; ciphertext pointer
1195 mov target_ptr_val, N_val
1196 and target_ptr_val, -16 ; target_ptr_val = target_ptr_val - (target_ptr_val mod 16)
1197 sub target_ptr_val, 128 ; adjust target_ptr_val because last 4 blocks will not be stitched with Tweak calculations
1198 jl _less_than_128_bytes
1200 add target_ptr_val, ptr_ciphertext
1205 jz _initial_num_blocks_is_0
1208 je _initial_num_blocks_is_4
1213 je _initial_num_blocks_is_6
1216 je _initial_num_blocks_is_5
1221 je _initial_num_blocks_is_3
1224 je _initial_num_blocks_is_2
1227 je _initial_num_blocks_is_1
1229 _initial_num_blocks_is_7:
1230 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 7
1231 add ptr_plaintext, 16*7
1232 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 7, 0
1234 movdqu [ptr_ciphertext+16*0], xmm1
1235 movdqu [ptr_ciphertext+16*1], xmm2
1236 movdqu [ptr_ciphertext+16*2], xmm3
1237 movdqu [ptr_ciphertext+16*3], xmm4
1238 movdqu [ptr_ciphertext+16*4], xmm5
1239 movdqu [ptr_ciphertext+16*5], xmm6
1240 movdqu [ptr_ciphertext+16*6], xmm7
1241 add ptr_ciphertext, 16*7
1243 cmp ptr_ciphertext, target_ptr_val
1247 _initial_num_blocks_is_6:
1248 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 6
1249 add ptr_plaintext, 16*6
1250 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 6, 0
1252 movdqu [ptr_ciphertext+16*0], xmm1
1253 movdqu [ptr_ciphertext+16*1], xmm2
1254 movdqu [ptr_ciphertext+16*2], xmm3
1255 movdqu [ptr_ciphertext+16*3], xmm4
1256 movdqu [ptr_ciphertext+16*4], xmm5
1257 movdqu [ptr_ciphertext+16*5], xmm6
1258 add ptr_ciphertext, 16*6
1260 cmp ptr_ciphertext, target_ptr_val
1264 _initial_num_blocks_is_5:
1265 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 5
1266 add ptr_plaintext, 16*5
1267 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 5, 0
1269 movdqu [ptr_ciphertext+16*0], xmm1
1270 movdqu [ptr_ciphertext+16*1], xmm2
1271 movdqu [ptr_ciphertext+16*2], xmm3
1272 movdqu [ptr_ciphertext+16*3], xmm4
1273 movdqu [ptr_ciphertext+16*4], xmm5
1274 add ptr_ciphertext, 16*5
1276 cmp ptr_ciphertext, target_ptr_val
1280 _initial_num_blocks_is_4:
1281 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 4
1282 add ptr_plaintext, 16*4
1283 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 4, 0
1285 movdqu [ptr_ciphertext+16*0], xmm1
1286 movdqu [ptr_ciphertext+16*1], xmm2
1287 movdqu [ptr_ciphertext+16*2], xmm3
1288 movdqu [ptr_ciphertext+16*3], xmm4
1289 add ptr_ciphertext, 16*4
1291 cmp ptr_ciphertext, target_ptr_val
1297 _initial_num_blocks_is_3:
1298 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 3
1299 add ptr_plaintext, 16*3
1300 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 3, 0
1302 movdqu [ptr_ciphertext+16*0], xmm1
1303 movdqu [ptr_ciphertext+16*1], xmm2
1304 movdqu [ptr_ciphertext+16*2], xmm3
1305 add ptr_ciphertext, 16*3
1307 cmp ptr_ciphertext, target_ptr_val
1311 _initial_num_blocks_is_2:
1312 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 2
1313 add ptr_plaintext, 16*2
1314 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 2, 0
1316 movdqu [ptr_ciphertext], xmm1
1317 movdqu [ptr_ciphertext+16], xmm2
1318 add ptr_ciphertext, 16*2
1320 cmp ptr_ciphertext, target_ptr_val
1325 _initial_num_blocks_is_1:
1326 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 1
1327 add ptr_plaintext, 16*1
1328 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 1, 0
1330 movdqu [ptr_ciphertext], xmm1
1331 add ptr_ciphertext, 16
1333 cmp ptr_ciphertext, target_ptr_val
1338 _initial_num_blocks_is_0:
1339 mov twtempl, [TW+8*0]
1340 mov twtemph, [TW+8*1]
1341 movdqa xmm9, [TW+16*0]
1343 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1345 adc twtemph, twtemph
1346 cmovc ghash_poly_8b_temp, ghash_poly_8b
1347 xor twtempl, ghash_poly_8b_temp
1348 mov [TW+8*2], twtempl
1349 mov [TW+8*3], twtemph
1350 movdqa xmm10, [TW+16*1]
1352 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1354 adc twtemph, twtemph
1355 cmovc ghash_poly_8b_temp, ghash_poly_8b
1356 xor twtempl, ghash_poly_8b_temp
1357 mov [TW+8*4], twtempl
1358 mov [TW+8*5], twtemph
1359 movdqa xmm11, [TW+16*2]
1362 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1364 adc twtemph, twtemph
1365 cmovc ghash_poly_8b_temp, ghash_poly_8b
1366 xor twtempl, ghash_poly_8b_temp
1367 mov [TW+8*6], twtempl
1368 mov [TW+8*7], twtemph
1369 movdqa xmm12, [TW+16*3]
1372 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1374 adc twtemph, twtemph
1375 cmovc ghash_poly_8b_temp, ghash_poly_8b
1376 xor twtempl, ghash_poly_8b_temp
1377 mov [TW+8*8], twtempl
1378 mov [TW+8*9], twtemph
1379 movdqa xmm13, [TW+16*4]
1381 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1383 adc twtemph, twtemph
1384 cmovc ghash_poly_8b_temp, ghash_poly_8b
1385 xor twtempl, ghash_poly_8b_temp
1386 mov [TW+8*10], twtempl
1387 mov [TW+8*11], twtemph
1388 movdqa xmm14, [TW+16*5]
1390 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1392 adc twtemph, twtemph
1393 cmovc ghash_poly_8b_temp, ghash_poly_8b
1394 xor twtempl, ghash_poly_8b_temp
1395 mov [TW+8*12], twtempl
1396 mov [TW+8*13], twtemph
1397 movdqa xmm15, [TW+16*6]
1399 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1401 adc twtemph, twtemph
1402 cmovc ghash_poly_8b_temp, ghash_poly_8b
1403 xor twtempl, ghash_poly_8b_temp
1404 mov [TW+8*14], twtempl
1405 mov [TW+8*15], twtemph
1406 ;movdqa xmm16, [TW+16*7]
1408 cmp ptr_ciphertext, target_ptr_val
1412 movdqu xmm1, [ptr_plaintext+16*0]
1413 movdqu xmm2, [ptr_plaintext+16*1]
1414 movdqu xmm3, [ptr_plaintext+16*2]
1415 movdqu xmm4, [ptr_plaintext+16*3]
1416 movdqu xmm5, [ptr_plaintext+16*4]
1417 movdqu xmm6, [ptr_plaintext+16*5]
1418 movdqu xmm7, [ptr_plaintext+16*6]
1419 movdqu xmm8, [ptr_plaintext+16*7]
1421 add ptr_plaintext, 128
1423 encrypt_by_eight xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, [TW+16*7], xmm0, 0
1426 movdqu [ptr_ciphertext+16*0], xmm1
1427 movdqu [ptr_ciphertext+16*1], xmm2
1428 movdqu [ptr_ciphertext+16*2], xmm3
1429 movdqu [ptr_ciphertext+16*3], xmm4
1430 movdqu [ptr_ciphertext+16*4], xmm5
1431 movdqu [ptr_ciphertext+16*5], xmm6
1432 movdqu [ptr_ciphertext+16*6], xmm7
1433 movdqu [ptr_ciphertext+16*7], xmm8
1434 add ptr_ciphertext, 128
1436 cmp ptr_ciphertext, target_ptr_val
1441 movdqu xmm1, [ptr_plaintext+16*0]
1442 movdqu xmm2, [ptr_plaintext+16*1]
1443 movdqu xmm3, [ptr_plaintext+16*2]
1444 movdqu xmm4, [ptr_plaintext+16*3]
1445 movdqu xmm5, [ptr_plaintext+16*4]
1446 movdqu xmm6, [ptr_plaintext+16*5]
1447 movdqu xmm7, [ptr_plaintext+16*6]
1448 movdqu xmm8, [ptr_plaintext+16*7]
1449 encrypt_by_eight xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, [TW+16*7], xmm0, 1
1452 movdqu [ptr_ciphertext+16*0], xmm1
1453 movdqu [ptr_ciphertext+16*1], xmm2
1454 movdqu [ptr_ciphertext+16*2], xmm3
1455 movdqu [ptr_ciphertext+16*3], xmm4
1456 movdqu [ptr_ciphertext+16*4], xmm5
1457 movdqu [ptr_ciphertext+16*5], xmm6
1458 movdqu [ptr_ciphertext+16*6], xmm7
1461 and N_val, 15 ; N_val = N_val mod 16
1464 ; start cipher stealing
1466 ; generate next Tweak value
1467 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1469 adc twtemph, twtemph
1470 cmovc ghash_poly_8b_temp, ghash_poly_8b
1471 xor twtempl, ghash_poly_8b_temp
1473 mov [TW + 8], twtemph
1477 ; shift xmm8 to the left by 16-N_val bytes
1478 lea twtempl, [pshufb_shf_table]
1479 movdqu xmm0, [twtempl+N_val]
1483 movdqu xmm3, [ptr_plaintext + 112 + N_val] ; state register is temporarily xmm3 to eliminate a move
1484 movdqu [ptr_ciphertext + 112 + N_val], xmm8
1486 ; shift xmm3 to the right by 16-N_val bytes
1487 lea twtempl, [pshufb_shf_table +16]
1489 movdqu xmm0, [twtempl]
1493 pblendvb xmm3, xmm2 ;xmm0 is implicit
1497 pxor xmm8, xmm3 ; state register is xmm8, instead of a move from xmm3 to xmm8, destination register of pxor instruction is swapped
1500 ;encrypt last block with cipher stealing
1501 pxor xmm8, [keys] ; ARK
1502 aesenc xmm8, [keys + 16*1] ; round 1
1503 aesenc xmm8, [keys + 16*2] ; round 2
1504 aesenc xmm8, [keys + 16*3] ; round 3
1505 aesenc xmm8, [keys + 16*4] ; round 4
1506 aesenc xmm8, [keys + 16*5] ; round 5
1507 aesenc xmm8, [keys + 16*6] ; round 6
1508 aesenc xmm8, [keys + 16*7] ; round 7
1509 aesenc xmm8, [keys + 16*8] ; round 8
1510 aesenc xmm8, [keys + 16*9] ; round 9
1511 aesenc xmm8, [keys + 16*10] ; round 9
1512 aesenc xmm8, [keys + 16*11] ; round 9
1513 aesenc xmm8, [keys + 16*12] ; round 9
1514 aesenc xmm8, [keys + 16*13] ; round 9
1515 aesenclast xmm8, [keys + 16*14] ; round 10
1521 ; store last ciphertext value
1522 movdqu [ptr_ciphertext+16*7], xmm8
1526 mov rbx, [_gpr + 8*0]
1527 %ifidn __OUTPUT_FORMAT__, win64
1528 mov rdi, [_gpr + 8*1]
1529 mov rsi, [_gpr + 8*2]
1532 movdqa xmm6, [_xmm + 16*0]
1533 movdqa xmm7, [_xmm + 16*1]
1534 movdqa xmm8, [_xmm + 16*2]
1535 movdqa xmm9, [_xmm + 16*3]
1536 movdqa xmm10, [_xmm + 16*4]
1537 movdqa xmm11, [_xmm + 16*5]
1538 movdqa xmm12, [_xmm + 16*6]
1539 movdqa xmm13, [_xmm + 16*7]
1540 movdqa xmm14, [_xmm + 16*8]
1541 movdqa xmm15, [_xmm + 16*9]
1544 add rsp, VARIABLE_OFFSET
1552 _less_than_128_bytes:
1572 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 7
1573 sub ptr_plaintext, 16*1
1574 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 7, 1
1576 movdqu [ptr_ciphertext+16*0], xmm1
1577 movdqu [ptr_ciphertext+16*1], xmm2
1578 movdqu [ptr_ciphertext+16*2], xmm3
1579 movdqu [ptr_ciphertext+16*3], xmm4
1580 movdqu [ptr_ciphertext+16*4], xmm5
1581 movdqu [ptr_ciphertext+16*5], xmm6
1583 sub ptr_ciphertext, 16*1
1586 and N_val, 15 ; N_val = N_val mod 16
1590 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 6
1591 sub ptr_plaintext, 16*2
1592 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 6, 1
1594 movdqu [ptr_ciphertext+16*0], xmm1
1595 movdqu [ptr_ciphertext+16*1], xmm2
1596 movdqu [ptr_ciphertext+16*2], xmm3
1597 movdqu [ptr_ciphertext+16*3], xmm4
1598 movdqu [ptr_ciphertext+16*4], xmm5
1600 sub ptr_ciphertext, 16*2
1603 and N_val, 15 ; N_val = N_val mod 16
1607 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 5
1608 sub ptr_plaintext, 16*3
1609 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 5, 1
1611 movdqu [ptr_ciphertext+16*0], xmm1
1612 movdqu [ptr_ciphertext+16*1], xmm2
1613 movdqu [ptr_ciphertext+16*2], xmm3
1614 movdqu [ptr_ciphertext+16*3], xmm4
1616 sub ptr_ciphertext, 16*3
1619 and N_val, 15 ; N_val = N_val mod 16
1623 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 4
1624 sub ptr_plaintext, 16*4
1625 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 4, 1
1627 movdqu [ptr_ciphertext+16*0], xmm1
1628 movdqu [ptr_ciphertext+16*1], xmm2
1629 movdqu [ptr_ciphertext+16*2], xmm3
1631 sub ptr_ciphertext, 16*4
1634 and N_val, 15 ; N_val = N_val mod 16
1638 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 3
1639 sub ptr_plaintext, 16*5
1640 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 3, 1
1642 movdqu [ptr_ciphertext+16*0], xmm1
1643 movdqu [ptr_ciphertext+16*1], xmm2
1645 sub ptr_ciphertext, 16*5
1648 and N_val, 15 ; N_val = N_val mod 16
1653 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 2
1654 sub ptr_plaintext, 16*6
1655 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 2, 1
1657 movdqu [ptr_ciphertext], xmm1
1659 sub ptr_ciphertext, 16*6
1662 and N_val, 15 ; N_val = N_val mod 16
1668 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 1
1670 sub ptr_plaintext, 16*7
1671 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 1, 1
1674 sub ptr_ciphertext, 16*7
1677 and N_val, 15 ; N_val = N_val mod 16
1685 ; use these values for shift constants for the pshufb instruction
1686 ; different alignments result in values as shown:
1687 ; dq 0x8887868584838281, 0x008f8e8d8c8b8a89 ; shl 15 (16-1) / shr1
1688 ; dq 0x8988878685848382, 0x01008f8e8d8c8b8a ; shl 14 (16-3) / shr2
1689 ; dq 0x8a89888786858483, 0x0201008f8e8d8c8b ; shl 13 (16-4) / shr3
1690 ; dq 0x8b8a898887868584, 0x030201008f8e8d8c ; shl 12 (16-4) / shr4
1691 ; dq 0x8c8b8a8988878685, 0x04030201008f8e8d ; shl 11 (16-5) / shr5
1692 ; dq 0x8d8c8b8a89888786, 0x0504030201008f8e ; shl 10 (16-6) / shr6
1693 ; dq 0x8e8d8c8b8a898887, 0x060504030201008f ; shl 9 (16-7) / shr7
1694 ; dq 0x8f8e8d8c8b8a8988, 0x0706050403020100 ; shl 8 (16-8) / shr8
1695 ; dq 0x008f8e8d8c8b8a89, 0x0807060504030201 ; shl 7 (16-9) / shr9
1696 ; dq 0x01008f8e8d8c8b8a, 0x0908070605040302 ; shl 6 (16-10) / shr10
1697 ; dq 0x0201008f8e8d8c8b, 0x0a09080706050403 ; shl 5 (16-11) / shr11
1698 ; dq 0x030201008f8e8d8c, 0x0b0a090807060504 ; shl 4 (16-12) / shr12
1699 ; dq 0x04030201008f8e8d, 0x0c0b0a0908070605 ; shl 3 (16-13) / shr13
1700 ; dq 0x0504030201008f8e, 0x0d0c0b0a09080706 ; shl 2 (16-14) / shr14
1701 ; dq 0x060504030201008f, 0x0e0d0c0b0a090807 ; shl 1 (16-15) / shr15
1702 dq 0x8786858483828100, 0x8f8e8d8c8b8a8988
1703 dq 0x0706050403020100, 0x000e0d0c0b0a0908
1706 dq 0x8080808080808080, 0x8080808080808080