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 decrypt function with 256-bit AES
30 ; expanded keys are not aligned
31 ; plaintext and ciphertext are not aligned
32 ; second key is stored in the stack as aligned to 16 Bytes
33 ; first key is required only once, no need for storage of this key
35 %include "reg_sizes.asm"
38 %define TW rsp ; store 8 tweak values
39 %define keys rsp + 16*8 ; store 15 expanded keys
41 %ifidn __OUTPUT_FORMAT__, win64
42 %define _xmm rsp + 16*23 ; store xmm6:xmm15
45 %ifidn __OUTPUT_FORMAT__, elf64
46 %define _gpr rsp + 16*23 ; store rbx
47 %define VARIABLE_OFFSET 16*8 + 16*15 + 8*1 ; VARIABLE_OFFSET has to be an odd multiple of 8
49 %define _gpr rsp + 16*33 ; store rdi, rsi, rbx
50 %define VARIABLE_OFFSET 16*8 + 16*15 + 16*10 + 8*3 ; VARIABLE_OFFSET has to be an odd multiple of 8
53 %define GHASH_POLY 0x87
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 ;void XTS_AES_256_dec_expanded_key_avx(
57 ; UINT8 *k2, // key used for tweaking, 16*15 bytes
58 ; UINT8 *k1, // key used for "ECB" encryption, 16*15 bytes
59 ; UINT8 *TW_initial, // initial tweak value, 16 bytes
60 ; UINT64 N, // sector size, in bytes
61 ; const UINT8 *ct, // ciphertext sector input data
62 ; UINT8 *pt); // plaintext sector output data
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 ; arguments for input parameters
66 %ifidn __OUTPUT_FORMAT__, elf64
71 %xdefine ptr_plaintext r8
72 %xdefine ptr_ciphertext r9
78 %xdefine ptr_plaintext r10; [rsp + VARIABLE_OFFSET + 8*5]
79 %xdefine ptr_ciphertext r11; [rsp + VARIABLE_OFFSET + 8*6]
82 ; arguments for temp parameters
83 %ifidn __OUTPUT_FORMAT__, elf64
85 %define target_ptr_val rsi
86 %define ghash_poly_8b r10
87 %define ghash_poly_8b_temp r11
90 %define target_ptr_val rdx
91 %define ghash_poly_8b rdi
92 %define ghash_poly_8b_temp rsi
95 %define twtempl rax ; global temp registers used for tweak computation
99 ; macro to encrypt the tweak value
103 %define %%xstate_tweak %2
105 %define %%xraw_key %4
107 %define %%ptr_key2 %6
108 %define %%ptr_key1 %7
109 %define %%ptr_expanded_keys %8
111 vmovdqu %%xkey2, [%%ptr_key2]
112 vpxor %%xstate_tweak, %%xkey2 ; ARK for tweak encryption
114 vmovdqu %%xkey1, [%%ptr_key1 + 16*14]
115 vmovdqa [%%ptr_expanded_keys+16*14], %%xkey1 ; store round keys in stack
117 vmovdqu %%xkey2, [%%ptr_key2 + 16*1]
118 vaesenc %%xstate_tweak, %%xkey2 ; round 1 for tweak encryption
120 vmovdqu %%xkey1, [%%ptr_key1 + 16*13]
121 vmovdqa [%%ptr_expanded_keys+16*13], %%xkey1 ; store round keys in stack
124 vmovdqu %%xkey2, [%%ptr_key2 + 16*2]
125 vaesenc %%xstate_tweak, %%xkey2 ; round 2 for tweak encryption
127 vmovdqu %%xkey1, [%%ptr_key1 + 16*12]
128 vmovdqa [%%ptr_expanded_keys+16*12], %%xkey1 ; store round keys in stack
130 vmovdqu %%xkey2, [%%ptr_key2 + 16*3]
131 vaesenc %%xstate_tweak, %%xkey2 ; round 3 for tweak encryption
133 vmovdqu %%xkey1, [%%ptr_key1 + 16*11]
134 vmovdqa [%%ptr_expanded_keys+16*11], %%xkey1 ; store round keys in stack
136 vmovdqu %%xkey2, [%%ptr_key2 + 16*4]
137 vaesenc %%xstate_tweak, %%xkey2 ; round 4 for tweak encryption
139 vmovdqu %%xkey1, [%%ptr_key1 + 16*10]
140 vmovdqa [%%ptr_expanded_keys+16*10], %%xkey1 ; store round keys in stack
142 vmovdqu %%xkey2, [%%ptr_key2 + 16*5]
143 vaesenc %%xstate_tweak, %%xkey2 ; round 5 for tweak encryption
145 vmovdqu %%xkey1, [%%ptr_key1 + 16*9]
146 vmovdqa [%%ptr_expanded_keys+16*9], %%xkey1 ; store round keys in stack
148 vmovdqu %%xkey2, [%%ptr_key2 + 16*6]
149 vaesenc %%xstate_tweak, %%xkey2 ; round 6 for tweak encryption
151 vmovdqu %%xkey1, [%%ptr_key1 + 16*8]
152 vmovdqa [%%ptr_expanded_keys+16*8], %%xkey1 ; store round keys in stack
154 vmovdqu %%xkey2, [%%ptr_key2 + 16*7]
155 vaesenc %%xstate_tweak, %%xkey2 ; round 7 for tweak encryption
157 vmovdqu %%xkey1, [%%ptr_key1 + 16*7]
158 vmovdqa [%%ptr_expanded_keys+16*7], %%xkey1 ; store round keys in stack
161 vmovdqu %%xkey2, [%%ptr_key2 + 16*8]
162 vaesenc %%xstate_tweak, %%xkey2 ; round 8 for tweak encryption
164 vmovdqu %%xkey1, [%%ptr_key1 + 16*6]
165 vmovdqa [%%ptr_expanded_keys+16*6], %%xkey1 ; store round keys in stack
168 vmovdqu %%xkey2, [%%ptr_key2 + 16*9]
169 vaesenc %%xstate_tweak, %%xkey2 ; round 9 for tweak encryption
171 vmovdqu %%xkey1, [%%ptr_key1 + 16*5]
172 vmovdqa [%%ptr_expanded_keys+16*5], %%xkey1 ; store round keys in stack
175 vmovdqu %%xkey2, [%%ptr_key2 + 16*10]
176 vaesenc %%xstate_tweak, %%xkey2 ; round 10 for tweak encryption
178 vmovdqu %%xkey1, [%%ptr_key1 + 16*4]
179 vmovdqa [%%ptr_expanded_keys+16*4], %%xkey1 ; store round keys in stack
182 vmovdqu %%xkey2, [%%ptr_key2 + 16*11]
183 vaesenc %%xstate_tweak, %%xkey2 ; round 11 for tweak encryption
185 vmovdqu %%xkey1, [%%ptr_key1 + 16*3]
186 vmovdqa [%%ptr_expanded_keys+16*3], %%xkey1 ; store round keys in stack
188 vmovdqu %%xkey2, [%%ptr_key2 + 16*12]
189 vaesenc %%xstate_tweak, %%xkey2 ; round 12 for tweak encryption
191 vmovdqu %%xkey1, [%%ptr_key1 + 16*2]
192 vmovdqa [%%ptr_expanded_keys+16*2], %%xkey1 ; store round keys in stack
194 vmovdqu %%xkey2, [%%ptr_key2 + 16*13]
195 vaesenc %%xstate_tweak, %%xkey2 ; round 13 for tweak encryption
197 vmovdqu %%xkey1, [%%ptr_key1 + 16*1]
198 vmovdqa [%%ptr_expanded_keys+16*1], %%xkey1 ; store round keys in stack
200 vmovdqu %%xkey2, [%%ptr_key2 + 16*14]
201 vaesenclast %%xstate_tweak, %%xkey2 ; round 14 for tweak encryption
203 vmovdqu %%xkey1, [%%ptr_key1 + 16*0]
204 vmovdqa [%%ptr_expanded_keys+16*0], %%xkey1 ; store round keys in stack
206 vmovdqa [TW], %%xstate_tweak ; Store the encrypted Tweak value
210 ; generate initial tweak values
211 ; load initial plaintext values
214 %define %%ST1 %1 ; state 1
215 %define %%ST2 %2 ; state 2
216 %define %%ST3 %3 ; state 3
217 %define %%ST4 %4 ; state 4
218 %define %%ST5 %5 ; state 5
219 %define %%ST6 %6 ; state 6
220 %define %%ST7 %7 ; state 7
221 %define %%ST8 %8 ; state 8
223 %define %%TW1 %9 ; tweak 1
224 %define %%TW2 %10 ; tweak 2
225 %define %%TW3 %11 ; tweak 3
226 %define %%TW4 %12 ; tweak 4
227 %define %%TW5 %13 ; tweak 5
228 %define %%TW6 %14 ; tweak 6
229 %define %%TW7 %15 ; tweak 7
231 %define %%num_initial_blocks %16
234 ; generate next Tweak values
235 vmovdqa %%TW1, [TW+16*0]
236 mov twtempl, [TW+8*0]
237 mov twtemph, [TW+8*1]
238 vmovdqu %%ST1, [ptr_plaintext+16*0]
239 %if (%%num_initial_blocks>=2)
240 xor ghash_poly_8b_temp, ghash_poly_8b_temp
243 cmovc ghash_poly_8b_temp, ghash_poly_8b
244 xor twtempl, ghash_poly_8b_temp
245 mov [TW+8*2], twtempl
246 mov [TW+8*3], twtemph;
247 vmovdqa %%TW2, [TW+16*1]
248 vmovdqu %%ST2, [ptr_plaintext+16*1]
250 %if (%%num_initial_blocks>=3)
251 xor ghash_poly_8b_temp, ghash_poly_8b_temp
254 cmovc ghash_poly_8b_temp, ghash_poly_8b
255 xor twtempl, ghash_poly_8b_temp
256 mov [TW+8*4], twtempl
257 mov [TW+8*5], twtemph;
258 vmovdqa %%TW3, [TW+16*2]
259 vmovdqu %%ST3, [ptr_plaintext+16*2]
261 %if (%%num_initial_blocks>=4)
262 xor ghash_poly_8b_temp, ghash_poly_8b_temp
265 cmovc ghash_poly_8b_temp, ghash_poly_8b
266 xor twtempl, ghash_poly_8b_temp
267 mov [TW+8*6], twtempl
268 mov [TW+8*7], twtemph;
269 vmovdqa %%TW4, [TW+16*3]
270 vmovdqu %%ST4, [ptr_plaintext+16*3]
272 %if (%%num_initial_blocks>=5)
273 xor ghash_poly_8b_temp, ghash_poly_8b_temp
276 cmovc ghash_poly_8b_temp, ghash_poly_8b
277 xor twtempl, ghash_poly_8b_temp
278 mov [TW+8*8], twtempl
279 mov [TW+8*9], twtemph;
280 vmovdqa %%TW5, [TW+16*4]
281 vmovdqu %%ST5, [ptr_plaintext+16*4]
283 %if (%%num_initial_blocks>=6)
284 xor ghash_poly_8b_temp, ghash_poly_8b_temp
287 cmovc ghash_poly_8b_temp, ghash_poly_8b
288 xor twtempl, ghash_poly_8b_temp
289 mov [TW+8*10], twtempl
290 mov [TW+8*11], twtemph;
291 vmovdqa %%TW6, [TW+16*5]
292 vmovdqu %%ST6, [ptr_plaintext+16*5]
294 %if (%%num_initial_blocks>=7)
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*12], twtempl
301 mov [TW+8*13], twtemph;
302 vmovdqa %%TW7, [TW+16*6]
303 vmovdqu %%ST7, [ptr_plaintext+16*6]
311 ; encrypt initial blocks of AES
312 ; 1, 2, 3, 4, 5, 6 or 7 blocks are encrypted
313 ; next 8 Tweak values are generated
314 %macro encrypt_initial 18
315 %define %%ST1 %1 ; state 1
316 %define %%ST2 %2 ; state 2
317 %define %%ST3 %3 ; state 3
318 %define %%ST4 %4 ; state 4
319 %define %%ST5 %5 ; state 5
320 %define %%ST6 %6 ; state 6
321 %define %%ST7 %7 ; state 7
322 %define %%ST8 %8 ; state 8
324 %define %%TW1 %9 ; tweak 1
325 %define %%TW2 %10 ; tweak 2
326 %define %%TW3 %11 ; tweak 3
327 %define %%TW4 %12 ; tweak 4
328 %define %%TW5 %13 ; tweak 5
329 %define %%TW6 %14 ; tweak 6
330 %define %%TW7 %15 ; tweak 7
331 %define %%T0 %16 ; Temp register
332 %define %%num_blocks %17
333 ; %%num_blocks blocks encrypted
334 ; %%num_blocks can be 1, 2, 3, 4, 5, 6, 7
336 %define %%lt128 %18 ; less than 128 bytes
340 %if (%%num_blocks>=2)
343 %if (%%num_blocks>=3)
346 %if (%%num_blocks>=4)
349 %if (%%num_blocks>=5)
352 %if (%%num_blocks>=6)
355 %if (%%num_blocks>=7)
363 %if (%%num_blocks>=2)
366 %if (%%num_blocks>=3)
369 %if (%%num_blocks>=4)
372 %if (%%num_blocks>=5)
375 %if (%%num_blocks>=6)
378 %if (%%num_blocks>=7)
384 xor ghash_poly_8b_temp, ghash_poly_8b_temp
390 vmovdqa %%T0, [keys + 16*1]
392 %if (%%num_blocks>=2)
395 %if (%%num_blocks>=3)
398 %if (%%num_blocks>=4)
401 %if (%%num_blocks>=5)
404 %if (%%num_blocks>=6)
407 %if (%%num_blocks>=7)
411 cmovc ghash_poly_8b_temp, ghash_poly_8b
412 xor twtempl, ghash_poly_8b_temp
413 mov [TW + 8*0], twtempl ; next Tweak1 generated
414 mov [TW + 8*1], twtemph
415 xor ghash_poly_8b_temp, ghash_poly_8b_temp
419 vmovdqa %%T0, [keys + 16*2]
421 %if (%%num_blocks>=2)
424 %if (%%num_blocks>=3)
427 %if (%%num_blocks>=4)
430 %if (%%num_blocks>=5)
433 %if (%%num_blocks>=6)
436 %if (%%num_blocks>=7)
443 cmovc ghash_poly_8b_temp, ghash_poly_8b
444 xor twtempl, ghash_poly_8b_temp
445 mov [TW + 8*2], twtempl ; next Tweak2 generated
449 vmovdqa %%T0, [keys + 16*3]
451 %if (%%num_blocks>=2)
454 %if (%%num_blocks>=3)
457 %if (%%num_blocks>=4)
460 %if (%%num_blocks>=5)
463 %if (%%num_blocks>=6)
466 %if (%%num_blocks>=7)
470 mov [TW + 8*3], twtemph
471 xor ghash_poly_8b_temp, ghash_poly_8b_temp
474 cmovc ghash_poly_8b_temp, ghash_poly_8b
478 vmovdqa %%T0, [keys + 16*4]
480 %if (%%num_blocks>=2)
483 %if (%%num_blocks>=3)
486 %if (%%num_blocks>=4)
489 %if (%%num_blocks>=5)
492 %if (%%num_blocks>=6)
495 %if (%%num_blocks>=7)
500 xor twtempl, ghash_poly_8b_temp
501 mov [TW + 8*4], twtempl ; next Tweak3 generated
502 mov [TW + 8*5], twtemph
503 xor ghash_poly_8b_temp, ghash_poly_8b_temp
508 vmovdqa %%T0, [keys + 16*5]
510 %if (%%num_blocks>=2)
513 %if (%%num_blocks>=3)
516 %if (%%num_blocks>=4)
519 %if (%%num_blocks>=5)
522 %if (%%num_blocks>=6)
525 %if (%%num_blocks>=7)
531 cmovc ghash_poly_8b_temp, ghash_poly_8b
532 xor twtempl, ghash_poly_8b_temp
533 mov [TW + 8*6], twtempl ; next Tweak4 generated
534 mov [TW + 8*7], twtemph
538 vmovdqa %%T0, [keys + 16*6]
540 %if (%%num_blocks>=2)
543 %if (%%num_blocks>=3)
546 %if (%%num_blocks>=4)
549 %if (%%num_blocks>=5)
552 %if (%%num_blocks>=6)
555 %if (%%num_blocks>=7)
560 xor ghash_poly_8b_temp, ghash_poly_8b_temp
563 cmovc ghash_poly_8b_temp, ghash_poly_8b
564 xor twtempl, ghash_poly_8b_temp
565 mov [TW + 8*8], twtempl ; next Tweak5 generated
566 mov [TW + 8*9], twtemph
570 vmovdqa %%T0, [keys + 16*7]
572 %if (%%num_blocks>=2)
575 %if (%%num_blocks>=3)
578 %if (%%num_blocks>=4)
581 %if (%%num_blocks>=5)
584 %if (%%num_blocks>=6)
587 %if (%%num_blocks>=7)
592 xor ghash_poly_8b_temp, ghash_poly_8b_temp
595 cmovc ghash_poly_8b_temp, ghash_poly_8b
596 xor twtempl, ghash_poly_8b_temp
597 mov [TW + 8*10], twtempl ; next Tweak6 generated
598 mov [TW + 8*11], twtemph
601 vmovdqa %%T0, [keys + 16*8]
603 %if (%%num_blocks>=2)
606 %if (%%num_blocks>=3)
609 %if (%%num_blocks>=4)
612 %if (%%num_blocks>=5)
615 %if (%%num_blocks>=6)
618 %if (%%num_blocks>=7)
623 xor ghash_poly_8b_temp, ghash_poly_8b_temp
626 cmovc ghash_poly_8b_temp, ghash_poly_8b
627 xor twtempl, ghash_poly_8b_temp
628 mov [TW + 8*12], twtempl ; next Tweak7 generated
629 mov [TW + 8*13], twtemph
632 vmovdqa %%T0, [keys + 16*9]
634 %if (%%num_blocks>=2)
637 %if (%%num_blocks>=3)
640 %if (%%num_blocks>=4)
643 %if (%%num_blocks>=5)
646 %if (%%num_blocks>=6)
649 %if (%%num_blocks>=7)
654 xor ghash_poly_8b_temp, ghash_poly_8b_temp
657 cmovc ghash_poly_8b_temp, ghash_poly_8b
658 xor twtempl, ghash_poly_8b_temp
659 mov [TW + 8*14], twtempl ; next Tweak8 generated
660 mov [TW + 8*15], twtemph
663 vmovdqa %%T0, [keys + 16*10]
665 %if (%%num_blocks>=2)
668 %if (%%num_blocks>=3)
671 %if (%%num_blocks>=4)
674 %if (%%num_blocks>=5)
677 %if (%%num_blocks>=6)
680 %if (%%num_blocks>=7)
684 vmovdqa %%T0, [keys + 16*11]
686 %if (%%num_blocks>=2)
689 %if (%%num_blocks>=3)
692 %if (%%num_blocks>=4)
695 %if (%%num_blocks>=5)
698 %if (%%num_blocks>=6)
701 %if (%%num_blocks>=7)
706 vmovdqa %%T0, [keys + 16*12]
708 %if (%%num_blocks>=2)
711 %if (%%num_blocks>=3)
714 %if (%%num_blocks>=4)
717 %if (%%num_blocks>=5)
720 %if (%%num_blocks>=6)
723 %if (%%num_blocks>=7)
728 vmovdqa %%T0, [keys + 16*13]
730 %if (%%num_blocks>=2)
733 %if (%%num_blocks>=3)
736 %if (%%num_blocks>=4)
739 %if (%%num_blocks>=5)
742 %if (%%num_blocks>=6)
745 %if (%%num_blocks>=7)
750 vmovdqa %%T0, [keys + 16*14]
751 vaesdeclast %%ST1, %%T0
752 %if (%%num_blocks>=2)
753 vaesdeclast %%ST2, %%T0
755 %if (%%num_blocks>=3)
756 vaesdeclast %%ST3, %%T0
758 %if (%%num_blocks>=4)
759 vaesdeclast %%ST4, %%T0
761 %if (%%num_blocks>=5)
762 vaesdeclast %%ST5, %%T0
764 %if (%%num_blocks>=6)
765 vaesdeclast %%ST6, %%T0
767 %if (%%num_blocks>=7)
768 vaesdeclast %%ST7, %%T0
773 %if (%%num_blocks>=2)
776 %if (%%num_blocks>=3)
779 %if (%%num_blocks>=4)
782 %if (%%num_blocks>=5)
785 %if (%%num_blocks>=6)
788 %if (%%num_blocks>=7)
794 ; load next Tweak values
795 vmovdqa %%TW1, [TW + 16*0]
796 vmovdqa %%TW2, [TW + 16*1]
797 vmovdqa %%TW3, [TW + 16*2]
798 vmovdqa %%TW4, [TW + 16*3]
799 vmovdqa %%TW5, [TW + 16*4]
800 vmovdqa %%TW6, [TW + 16*5]
801 vmovdqa %%TW7, [TW + 16*6]
808 ; Encrypt 8 blocks in parallel
809 ; generate next 8 tweak values
810 %macro encrypt_by_eight 18
811 %define %%ST1 %1 ; state 1
812 %define %%ST2 %2 ; state 2
813 %define %%ST3 %3 ; state 3
814 %define %%ST4 %4 ; state 4
815 %define %%ST5 %5 ; state 5
816 %define %%ST6 %6 ; state 6
817 %define %%ST7 %7 ; state 7
818 %define %%ST8 %8 ; state 8
819 %define %%TW1 %9 ; tweak 1
820 %define %%TW2 %10 ; tweak 2
821 %define %%TW3 %11 ; tweak 3
822 %define %%TW4 %12 ; tweak 4
823 %define %%TW5 %13 ; tweak 5
824 %define %%TW6 %14 ; tweak 6
825 %define %%TW7 %15 ; tweak 7
826 %define %%TW8 %16 ; tweak 8
827 %define %%T0 %17 ; Temp register
828 %define %%last_eight %18
851 %if (0 == %%last_eight)
852 xor ghash_poly_8b_temp, ghash_poly_8b_temp
855 cmovc ghash_poly_8b_temp, ghash_poly_8b
858 vmovdqa %%T0, [keys + 16*1]
867 %if (0 == %%last_eight)
868 xor twtempl, ghash_poly_8b_temp
869 mov [TW + 8*0], twtempl
870 mov [TW + 8*1], twtemph
871 xor ghash_poly_8b_temp, ghash_poly_8b_temp
874 vmovdqa %%T0, [keys + 16*2]
883 %if (0 == %%last_eight)
886 cmovc ghash_poly_8b_temp, ghash_poly_8b
887 xor twtempl, ghash_poly_8b_temp
891 vmovdqa %%T0, [keys + 16*3]
900 %if (0 == %%last_eight)
901 mov [TW + 8*2], twtempl
902 mov [TW + 8*3], twtemph
903 xor ghash_poly_8b_temp, ghash_poly_8b_temp
907 vmovdqa %%T0, [keys + 16*4]
916 %if (0 == %%last_eight)
918 cmovc ghash_poly_8b_temp, ghash_poly_8b
919 xor twtempl, ghash_poly_8b_temp
920 mov [TW + 8*4], twtempl
923 vmovdqa %%T0, [keys + 16*5]
932 %if (0 == %%last_eight)
933 mov [TW + 8*5], twtemph
934 xor ghash_poly_8b_temp, ghash_poly_8b_temp
939 vmovdqa %%T0, [keys + 16*6]
948 %if (0 == %%last_eight)
949 cmovc ghash_poly_8b_temp, ghash_poly_8b
950 xor twtempl, ghash_poly_8b_temp
951 mov [TW + 8*6], twtempl
952 mov [TW + 8*7], twtemph
955 vmovdqa %%T0, [keys + 16*7]
964 %if (0 == %%last_eight)
965 xor ghash_poly_8b_temp, ghash_poly_8b_temp
968 cmovc ghash_poly_8b_temp, ghash_poly_8b
971 vmovdqa %%T0, [keys + 16*8]
980 %if (0 == %%last_eight)
981 xor twtempl, ghash_poly_8b_temp
982 mov [TW + 8*8], twtempl
983 mov [TW + 8*9], twtemph
984 xor ghash_poly_8b_temp, ghash_poly_8b_temp
987 vmovdqa %%T0, [keys + 16*9]
996 %if (0 == %%last_eight)
999 cmovc ghash_poly_8b_temp, ghash_poly_8b
1000 xor twtempl, ghash_poly_8b_temp
1003 vmovdqa %%T0, [keys + 16*10]
1012 %if (0 == %%last_eight)
1013 mov [TW + 8*10], twtempl
1014 mov [TW + 8*11], twtemph
1015 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1019 vmovdqa %%T0, [keys + 16*11]
1028 %if (0 == %%last_eight)
1029 adc twtemph, twtemph
1030 cmovc ghash_poly_8b_temp, ghash_poly_8b
1031 xor twtempl, ghash_poly_8b_temp
1032 mov [TW + 8*12], twtempl
1035 vmovdqa %%T0, [keys + 16*12]
1044 %if (0 == %%last_eight)
1045 mov [TW + 8*13], twtemph
1046 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1048 adc twtemph, twtemph
1051 vmovdqa %%T0, [keys + 16*13]
1060 %if (0 == %%last_eight)
1061 cmovc ghash_poly_8b_temp, ghash_poly_8b
1062 xor twtempl, ghash_poly_8b_temp
1063 ; mov [TW + 8*14], twtempl
1064 ; mov [TW + 8*15], twtemph
1067 vmovdqa %%T0, [keys + 16*14]
1068 vaesdeclast %%ST1, %%T0
1069 vaesdeclast %%ST2, %%T0
1070 vaesdeclast %%ST3, %%T0
1071 vaesdeclast %%ST4, %%T0
1072 vaesdeclast %%ST5, %%T0
1073 vaesdeclast %%ST6, %%T0
1074 vaesdeclast %%ST7, %%T0
1075 vaesdeclast %%ST8, %%T0
1087 mov [TW + 8*14], twtempl
1088 mov [TW + 8*15], twtemph
1089 ; load next Tweak values
1090 vmovdqa %%TW1, [TW + 16*0]
1091 vmovdqa %%TW2, [TW + 16*1]
1092 vmovdqa %%TW3, [TW + 16*2]
1093 vmovdqa %%TW4, [TW + 16*3]
1094 vmovdqa %%TW5, [TW + 16*4]
1095 vmovdqa %%TW6, [TW + 16*5]
1096 vmovdqa %%TW7, [TW + 16*6]
1103 global XTS_AES_256_dec_expanded_key_avx:function
1104 XTS_AES_256_dec_expanded_key_avx:
1106 sub rsp, VARIABLE_OFFSET
1108 mov [_gpr + 8*0], rbx
1109 %ifidn __OUTPUT_FORMAT__, win64
1110 mov [_gpr + 8*1], rdi
1111 mov [_gpr + 8*2], rsi
1113 vmovdqa [_xmm + 16*0], xmm6
1114 vmovdqa [_xmm + 16*1], xmm7
1115 vmovdqa [_xmm + 16*2], xmm8
1116 vmovdqa [_xmm + 16*3], xmm9
1117 vmovdqa [_xmm + 16*4], xmm10
1118 vmovdqa [_xmm + 16*5], xmm11
1119 vmovdqa [_xmm + 16*6], xmm12
1120 vmovdqa [_xmm + 16*7], xmm13
1121 vmovdqa [_xmm + 16*8], xmm14
1122 vmovdqa [_xmm + 16*9], xmm15
1125 mov ghash_poly_8b, GHASH_POLY ; load 0x87 to ghash_poly_8b
1128 vmovdqu xmm1, [T_val] ; read initial Tweak value
1129 vpxor xmm4, xmm4 ; for key expansion
1130 encrypt_T xmm0, xmm1, xmm2, xmm3, xmm4, ptr_key2, ptr_key1, keys
1133 %ifidn __OUTPUT_FORMAT__, win64
1134 mov ptr_plaintext, [rsp + VARIABLE_OFFSET + 8*5] ; plaintext pointer
1135 mov ptr_ciphertext, [rsp + VARIABLE_OFFSET + 8*6] ; ciphertext pointer
1140 mov target_ptr_val, N_val
1141 and target_ptr_val, -16 ; target_ptr_val = target_ptr_val - (target_ptr_val mod 16)
1142 sub target_ptr_val, 128 ; adjust target_ptr_val because last 4 blocks will not be stitched with Tweak calculations
1143 jl _less_than_128_bytes
1145 add target_ptr_val, ptr_ciphertext
1150 jz _initial_num_blocks_is_0
1153 je _initial_num_blocks_is_4
1158 je _initial_num_blocks_is_6
1161 je _initial_num_blocks_is_5
1166 je _initial_num_blocks_is_3
1169 je _initial_num_blocks_is_2
1172 je _initial_num_blocks_is_1
1174 _initial_num_blocks_is_7:
1175 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 7
1176 add ptr_plaintext, 16*7
1177 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 7, 0
1179 vmovdqu [ptr_ciphertext+16*0], xmm1
1180 vmovdqu [ptr_ciphertext+16*1], xmm2
1181 vmovdqu [ptr_ciphertext+16*2], xmm3
1182 vmovdqu [ptr_ciphertext+16*3], xmm4
1183 vmovdqu [ptr_ciphertext+16*4], xmm5
1184 vmovdqu [ptr_ciphertext+16*5], xmm6
1185 vmovdqu [ptr_ciphertext+16*6], xmm7
1186 add ptr_ciphertext, 16*7
1188 cmp ptr_ciphertext, target_ptr_val
1192 _initial_num_blocks_is_6:
1193 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 6
1194 add ptr_plaintext, 16*6
1195 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 6, 0
1197 vmovdqu [ptr_ciphertext+16*0], xmm1
1198 vmovdqu [ptr_ciphertext+16*1], xmm2
1199 vmovdqu [ptr_ciphertext+16*2], xmm3
1200 vmovdqu [ptr_ciphertext+16*3], xmm4
1201 vmovdqu [ptr_ciphertext+16*4], xmm5
1202 vmovdqu [ptr_ciphertext+16*5], xmm6
1203 add ptr_ciphertext, 16*6
1205 cmp ptr_ciphertext, target_ptr_val
1209 _initial_num_blocks_is_5:
1210 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 5
1211 add ptr_plaintext, 16*5
1212 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 5, 0
1214 vmovdqu [ptr_ciphertext+16*0], xmm1
1215 vmovdqu [ptr_ciphertext+16*1], xmm2
1216 vmovdqu [ptr_ciphertext+16*2], xmm3
1217 vmovdqu [ptr_ciphertext+16*3], xmm4
1218 vmovdqu [ptr_ciphertext+16*4], xmm5
1219 add ptr_ciphertext, 16*5
1221 cmp ptr_ciphertext, target_ptr_val
1225 _initial_num_blocks_is_4:
1226 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 4
1227 add ptr_plaintext, 16*4
1228 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 4, 0
1230 vmovdqu [ptr_ciphertext+16*0], xmm1
1231 vmovdqu [ptr_ciphertext+16*1], xmm2
1232 vmovdqu [ptr_ciphertext+16*2], xmm3
1233 vmovdqu [ptr_ciphertext+16*3], xmm4
1234 add ptr_ciphertext, 16*4
1236 cmp ptr_ciphertext, target_ptr_val
1242 _initial_num_blocks_is_3:
1243 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 3
1244 add ptr_plaintext, 16*3
1245 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 3, 0
1247 vmovdqu [ptr_ciphertext+16*0], xmm1
1248 vmovdqu [ptr_ciphertext+16*1], xmm2
1249 vmovdqu [ptr_ciphertext+16*2], xmm3
1250 add ptr_ciphertext, 16*3
1252 cmp ptr_ciphertext, target_ptr_val
1256 _initial_num_blocks_is_2:
1257 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 2
1258 add ptr_plaintext, 16*2
1259 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 2, 0
1261 vmovdqu [ptr_ciphertext], xmm1
1262 vmovdqu [ptr_ciphertext+16], xmm2
1263 add ptr_ciphertext, 16*2
1265 cmp ptr_ciphertext, target_ptr_val
1270 _initial_num_blocks_is_1:
1271 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 1
1272 add ptr_plaintext, 16*1
1273 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 1, 0
1275 vmovdqu [ptr_ciphertext], xmm1
1276 add ptr_ciphertext, 16
1278 cmp ptr_ciphertext, target_ptr_val
1283 _initial_num_blocks_is_0:
1284 mov twtempl, [TW+8*0]
1285 mov twtemph, [TW+8*1]
1286 vmovdqa xmm9, [TW+16*0]
1288 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1290 adc twtemph, twtemph
1291 cmovc ghash_poly_8b_temp, ghash_poly_8b
1292 xor twtempl, ghash_poly_8b_temp
1293 mov [TW+8*2], twtempl
1294 mov [TW+8*3], twtemph
1295 vmovdqa xmm10, [TW+16*1]
1297 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1299 adc twtemph, twtemph
1300 cmovc ghash_poly_8b_temp, ghash_poly_8b
1301 xor twtempl, ghash_poly_8b_temp
1302 mov [TW+8*4], twtempl
1303 mov [TW+8*5], twtemph
1304 vmovdqa xmm11, [TW+16*2]
1307 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1309 adc twtemph, twtemph
1310 cmovc ghash_poly_8b_temp, ghash_poly_8b
1311 xor twtempl, ghash_poly_8b_temp
1312 mov [TW+8*6], twtempl
1313 mov [TW+8*7], twtemph
1314 vmovdqa xmm12, [TW+16*3]
1317 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1319 adc twtemph, twtemph
1320 cmovc ghash_poly_8b_temp, ghash_poly_8b
1321 xor twtempl, ghash_poly_8b_temp
1322 mov [TW+8*8], twtempl
1323 mov [TW+8*9], twtemph
1324 vmovdqa xmm13, [TW+16*4]
1326 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1328 adc twtemph, twtemph
1329 cmovc ghash_poly_8b_temp, ghash_poly_8b
1330 xor twtempl, ghash_poly_8b_temp
1331 mov [TW+8*10], twtempl
1332 mov [TW+8*11], twtemph
1333 vmovdqa xmm14, [TW+16*5]
1335 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1337 adc twtemph, twtemph
1338 cmovc ghash_poly_8b_temp, ghash_poly_8b
1339 xor twtempl, ghash_poly_8b_temp
1340 mov [TW+8*12], twtempl
1341 mov [TW+8*13], twtemph
1342 vmovdqa xmm15, [TW+16*6]
1344 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1346 adc twtemph, twtemph
1347 cmovc ghash_poly_8b_temp, ghash_poly_8b
1348 xor twtempl, ghash_poly_8b_temp
1349 mov [TW+8*14], twtempl
1350 mov [TW+8*15], twtemph
1351 ;vmovdqa xmm16, [TW+16*7]
1353 cmp ptr_ciphertext, target_ptr_val
1357 vmovdqu xmm1, [ptr_plaintext+16*0]
1358 vmovdqu xmm2, [ptr_plaintext+16*1]
1359 vmovdqu xmm3, [ptr_plaintext+16*2]
1360 vmovdqu xmm4, [ptr_plaintext+16*3]
1361 vmovdqu xmm5, [ptr_plaintext+16*4]
1362 vmovdqu xmm6, [ptr_plaintext+16*5]
1363 vmovdqu xmm7, [ptr_plaintext+16*6]
1364 vmovdqu xmm8, [ptr_plaintext+16*7]
1366 add ptr_plaintext, 128
1368 encrypt_by_eight xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, [TW+16*7], xmm0, 0
1371 vmovdqu [ptr_ciphertext+16*0], xmm1
1372 vmovdqu [ptr_ciphertext+16*1], xmm2
1373 vmovdqu [ptr_ciphertext+16*2], xmm3
1374 vmovdqu [ptr_ciphertext+16*3], xmm4
1375 vmovdqu [ptr_ciphertext+16*4], xmm5
1376 vmovdqu [ptr_ciphertext+16*5], xmm6
1377 vmovdqu [ptr_ciphertext+16*6], xmm7
1378 vmovdqu [ptr_ciphertext+16*7], xmm8
1379 add ptr_ciphertext, 128
1381 cmp ptr_ciphertext, target_ptr_val
1386 and N_val, 15 ; N_val = N_val mod 16
1389 ; generate next Tweak value
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 vmovdqa xmm1, [TW + 16*7]
1396 vmovdqa [TW + 16*0], xmm1 ; swap tweak values for cipher stealing for decrypt
1398 mov [TW + 16*7], twtempl
1399 mov [TW + 16*7+8], twtemph
1402 vmovdqu xmm1, [ptr_plaintext+16*0]
1403 vmovdqu xmm2, [ptr_plaintext+16*1]
1404 vmovdqu xmm3, [ptr_plaintext+16*2]
1405 vmovdqu xmm4, [ptr_plaintext+16*3]
1406 vmovdqu xmm5, [ptr_plaintext+16*4]
1407 vmovdqu xmm6, [ptr_plaintext+16*5]
1408 vmovdqu xmm7, [ptr_plaintext+16*6]
1409 vmovdqu xmm8, [ptr_plaintext+16*7]
1410 encrypt_by_eight xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, [TW+16*7], xmm0, 1
1413 vmovdqu [ptr_ciphertext+16*0], xmm1
1414 vmovdqu [ptr_ciphertext+16*1], xmm2
1415 vmovdqu [ptr_ciphertext+16*2], xmm3
1416 vmovdqu [ptr_ciphertext+16*3], xmm4
1417 vmovdqu [ptr_ciphertext+16*4], xmm5
1418 vmovdqu [ptr_ciphertext+16*5], xmm6
1419 vmovdqu [ptr_ciphertext+16*6], xmm7
1425 vmovdqu xmm1, [ptr_plaintext+16*0]
1426 vmovdqu xmm2, [ptr_plaintext+16*1]
1427 vmovdqu xmm3, [ptr_plaintext+16*2]
1428 vmovdqu xmm4, [ptr_plaintext+16*3]
1429 vmovdqu xmm5, [ptr_plaintext+16*4]
1430 vmovdqu xmm6, [ptr_plaintext+16*5]
1431 vmovdqu xmm7, [ptr_plaintext+16*6]
1432 vmovdqu xmm8, [ptr_plaintext+16*7]
1433 encrypt_by_eight xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, [TW+16*7], xmm0, 1
1436 vmovdqu [ptr_ciphertext+16*0], xmm1
1437 vmovdqu [ptr_ciphertext+16*1], xmm2
1438 vmovdqu [ptr_ciphertext+16*2], xmm3
1439 vmovdqu [ptr_ciphertext+16*3], xmm4
1440 vmovdqu [ptr_ciphertext+16*4], xmm5
1441 vmovdqu [ptr_ciphertext+16*5], xmm6
1442 vmovdqu [ptr_ciphertext+16*6], xmm7
1448 ; start cipher stealing
1453 ; shift xmm8 to the left by 16-N_val bytes
1454 lea twtempl, [vpshufb_shf_table]
1455 vmovdqu xmm0, [twtempl+N_val]
1459 vmovdqu xmm3, [ptr_plaintext + 112 + N_val] ; state register is temporarily xmm3 to eliminate a move
1460 vmovdqu [ptr_ciphertext + 112 + N_val], xmm8
1462 ; shift xmm3 to the right by 16-N_val bytes
1463 lea twtempl, [vpshufb_shf_table +16]
1465 vmovdqu xmm0, [twtempl]
1469 vpblendvb xmm3, xmm3, xmm2, xmm0 ;xmm0 is implicit
1473 vpxor xmm8, xmm3 ; state register is xmm8, instead of a move from xmm3 to xmm8, destination register of vpxor instruction is swapped
1476 ;encrypt last block with cipher stealing
1477 vpxor xmm8, [keys] ; ARK
1478 vaesdec xmm8, [keys + 16*1] ; round 1
1479 vaesdec xmm8, [keys + 16*2] ; round 2
1480 vaesdec xmm8, [keys + 16*3] ; round 3
1481 vaesdec xmm8, [keys + 16*4] ; round 4
1482 vaesdec xmm8, [keys + 16*5] ; round 5
1483 vaesdec xmm8, [keys + 16*6] ; round 6
1484 vaesdec xmm8, [keys + 16*7] ; round 7
1485 vaesdec xmm8, [keys + 16*8] ; round 8
1486 vaesdec xmm8, [keys + 16*9] ; round 9
1487 vaesdec xmm8, [keys + 16*10] ; round 9
1488 vaesdec xmm8, [keys + 16*11] ; round 9
1489 vaesdec xmm8, [keys + 16*12] ; round 9
1490 vaesdec xmm8, [keys + 16*13] ; round 9
1491 vaesdeclast xmm8, [keys + 16*14] ; round 10
1497 ; store last ciphertext value
1498 vmovdqu [ptr_ciphertext+16*7], xmm8
1502 mov rbx, [_gpr + 8*0]
1503 %ifidn __OUTPUT_FORMAT__, win64
1504 mov rdi, [_gpr + 8*1]
1505 mov rsi, [_gpr + 8*2]
1508 vmovdqa xmm6, [_xmm + 16*0]
1509 vmovdqa xmm7, [_xmm + 16*1]
1510 vmovdqa xmm8, [_xmm + 16*2]
1511 vmovdqa xmm9, [_xmm + 16*3]
1512 vmovdqa xmm10, [_xmm + 16*4]
1513 vmovdqa xmm11, [_xmm + 16*5]
1514 vmovdqa xmm12, [_xmm + 16*6]
1515 vmovdqa xmm13, [_xmm + 16*7]
1516 vmovdqa xmm14, [_xmm + 16*8]
1517 vmovdqa xmm15, [_xmm + 16*9]
1520 add rsp, VARIABLE_OFFSET
1528 _less_than_128_bytes:
1551 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 7
1553 sub ptr_plaintext, 16*1
1555 and N_val, 15 ; N_val = N_val mod 16
1559 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1561 adc twtemph, twtemph
1562 cmovc ghash_poly_8b_temp, ghash_poly_8b
1563 xor twtempl, ghash_poly_8b_temp
1564 mov [TW+8*2], twtempl
1565 mov [TW+8*3], twtemph
1567 vmovdqa [TW + 16*0] , xmm15
1568 vmovdqa xmm15, [TW+16*1]
1570 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 7, 1
1572 vmovdqu [ptr_ciphertext+16*0], xmm1
1573 vmovdqu [ptr_ciphertext+16*1], xmm2
1574 vmovdqu [ptr_ciphertext+16*2], xmm3
1575 vmovdqu [ptr_ciphertext+16*3], xmm4
1576 vmovdqu [ptr_ciphertext+16*4], xmm5
1577 vmovdqu [ptr_ciphertext+16*5], xmm6
1579 sub ptr_ciphertext, 16*1
1584 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 7, 1
1586 vmovdqu [ptr_ciphertext+16*0], xmm1
1587 vmovdqu [ptr_ciphertext+16*1], xmm2
1588 vmovdqu [ptr_ciphertext+16*2], xmm3
1589 vmovdqu [ptr_ciphertext+16*3], xmm4
1590 vmovdqu [ptr_ciphertext+16*4], xmm5
1591 vmovdqu [ptr_ciphertext+16*5], xmm6
1593 sub ptr_ciphertext, 16*1
1603 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 6
1605 sub ptr_plaintext, 16*2
1607 and N_val, 15 ; N_val = N_val mod 16
1611 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1613 adc twtemph, twtemph
1614 cmovc ghash_poly_8b_temp, ghash_poly_8b
1615 xor twtempl, ghash_poly_8b_temp
1616 mov [TW+8*2], twtempl
1617 mov [TW+8*3], twtemph
1619 vmovdqa [TW + 16*0] , xmm14
1620 vmovdqa xmm14, [TW+16*1]
1622 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 6, 1
1624 vmovdqu [ptr_ciphertext+16*0], xmm1
1625 vmovdqu [ptr_ciphertext+16*1], xmm2
1626 vmovdqu [ptr_ciphertext+16*2], xmm3
1627 vmovdqu [ptr_ciphertext+16*3], xmm4
1628 vmovdqu [ptr_ciphertext+16*4], xmm5
1630 sub ptr_ciphertext, 16*2
1635 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 6, 1
1637 vmovdqu [ptr_ciphertext+16*0], xmm1
1638 vmovdqu [ptr_ciphertext+16*1], xmm2
1639 vmovdqu [ptr_ciphertext+16*2], xmm3
1640 vmovdqu [ptr_ciphertext+16*3], xmm4
1641 vmovdqu [ptr_ciphertext+16*4], xmm5
1643 sub ptr_ciphertext, 16*2
1652 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 5
1654 sub ptr_plaintext, 16*3
1656 and N_val, 15 ; N_val = N_val mod 16
1660 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1662 adc twtemph, twtemph
1663 cmovc ghash_poly_8b_temp, ghash_poly_8b
1664 xor twtempl, ghash_poly_8b_temp
1665 mov [TW+8*2], twtempl
1666 mov [TW+8*3], twtemph
1668 vmovdqa [TW + 16*0] , xmm13
1669 vmovdqa xmm13, [TW+16*1]
1671 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 5, 1
1673 vmovdqu [ptr_ciphertext+16*0], xmm1
1674 vmovdqu [ptr_ciphertext+16*1], xmm2
1675 vmovdqu [ptr_ciphertext+16*2], xmm3
1676 vmovdqu [ptr_ciphertext+16*3], xmm4
1678 sub ptr_ciphertext, 16*3
1683 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 5, 1
1685 vmovdqu [ptr_ciphertext+16*0], xmm1
1686 vmovdqu [ptr_ciphertext+16*1], xmm2
1687 vmovdqu [ptr_ciphertext+16*2], xmm3
1688 vmovdqu [ptr_ciphertext+16*3], xmm4
1690 sub ptr_ciphertext, 16*3
1699 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 4
1701 sub ptr_plaintext, 16*4
1703 and N_val, 15 ; N_val = N_val mod 16
1707 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1709 adc twtemph, twtemph
1710 cmovc ghash_poly_8b_temp, ghash_poly_8b
1711 xor twtempl, ghash_poly_8b_temp
1712 mov [TW+8*2], twtempl
1713 mov [TW+8*3], twtemph
1715 vmovdqa [TW + 16*0] , xmm12
1716 vmovdqa xmm12, [TW+16*1]
1718 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 4, 1
1720 vmovdqu [ptr_ciphertext+16*0], xmm1
1721 vmovdqu [ptr_ciphertext+16*1], xmm2
1722 vmovdqu [ptr_ciphertext+16*2], xmm3
1724 sub ptr_ciphertext, 16*4
1729 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 4, 1
1731 vmovdqu [ptr_ciphertext+16*0], xmm1
1732 vmovdqu [ptr_ciphertext+16*1], xmm2
1733 vmovdqu [ptr_ciphertext+16*2], xmm3
1735 sub ptr_ciphertext, 16*4
1743 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 3
1745 sub ptr_plaintext, 16*5
1747 and N_val, 15 ; N_val = N_val mod 16
1751 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1753 adc twtemph, twtemph
1754 cmovc ghash_poly_8b_temp, ghash_poly_8b
1755 xor twtempl, ghash_poly_8b_temp
1756 mov [TW+8*2], twtempl
1757 mov [TW+8*3], twtemph
1759 vmovdqa [TW + 16*0] , xmm11
1760 vmovdqa xmm11, [TW+16*1]
1762 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 3, 1
1764 vmovdqu [ptr_ciphertext+16*0], xmm1
1765 vmovdqu [ptr_ciphertext+16*1], xmm2
1767 sub ptr_ciphertext, 16*5
1772 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 3, 1
1774 vmovdqu [ptr_ciphertext+16*0], xmm1
1775 vmovdqu [ptr_ciphertext+16*1], xmm2
1777 sub ptr_ciphertext, 16*5
1787 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 2
1789 sub ptr_plaintext, 16*6
1791 and N_val, 15 ; N_val = N_val mod 16
1795 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1797 adc twtemph, twtemph
1798 cmovc ghash_poly_8b_temp, ghash_poly_8b
1799 xor twtempl, ghash_poly_8b_temp
1800 mov [TW+8*2], twtempl
1801 mov [TW+8*3], twtemph
1803 vmovdqa [TW + 16*0] , xmm10
1804 vmovdqa xmm10, [TW+16*1]
1806 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 2, 1
1808 vmovdqu [ptr_ciphertext], xmm1
1810 sub ptr_ciphertext, 16*6
1815 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 2, 1
1817 vmovdqu [ptr_ciphertext], xmm1
1819 sub ptr_ciphertext, 16*6
1836 initialize xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, 1
1838 sub ptr_plaintext, 16*7
1840 and N_val, 15 ; N_val = N_val mod 16
1844 xor ghash_poly_8b_temp, ghash_poly_8b_temp
1846 adc twtemph, twtemph
1847 cmovc ghash_poly_8b_temp, ghash_poly_8b
1848 xor twtempl, ghash_poly_8b_temp
1849 mov [TW+8*2], twtempl
1850 mov [TW+8*3], twtemph
1852 vmovdqa [TW + 16*0] , xmm9
1853 vmovdqa xmm9, [TW+16*1]
1855 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 1, 1
1858 sub ptr_ciphertext, 16*7
1863 encrypt_initial xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm0, 1, 1
1866 sub ptr_ciphertext, 16*7
1874 ; use these values for shift constants for the vpshufb instruction
1875 ; different alignments result in values as shown:
1876 ; dq 0x8887868584838281, 0x008f8e8d8c8b8a89 ; shl 15 (16-1) / shr1
1877 ; dq 0x8988878685848382, 0x01008f8e8d8c8b8a ; shl 14 (16-3) / shr2
1878 ; dq 0x8a89888786858483, 0x0201008f8e8d8c8b ; shl 13 (16-4) / shr3
1879 ; dq 0x8b8a898887868584, 0x030201008f8e8d8c ; shl 12 (16-4) / shr4
1880 ; dq 0x8c8b8a8988878685, 0x04030201008f8e8d ; shl 11 (16-5) / shr5
1881 ; dq 0x8d8c8b8a89888786, 0x0504030201008f8e ; shl 10 (16-6) / shr6
1882 ; dq 0x8e8d8c8b8a898887, 0x060504030201008f ; shl 9 (16-7) / shr7
1883 ; dq 0x8f8e8d8c8b8a8988, 0x0706050403020100 ; shl 8 (16-8) / shr8
1884 ; dq 0x008f8e8d8c8b8a89, 0x0807060504030201 ; shl 7 (16-9) / shr9
1885 ; dq 0x01008f8e8d8c8b8a, 0x0908070605040302 ; shl 6 (16-10) / shr10
1886 ; dq 0x0201008f8e8d8c8b, 0x0a09080706050403 ; shl 5 (16-11) / shr11
1887 ; dq 0x030201008f8e8d8c, 0x0b0a090807060504 ; shl 4 (16-12) / shr12
1888 ; dq 0x04030201008f8e8d, 0x0c0b0a0908070605 ; shl 3 (16-13) / shr13
1889 ; dq 0x0504030201008f8e, 0x0d0c0b0a09080706 ; shl 2 (16-14) / shr14
1890 ; dq 0x060504030201008f, 0x0e0d0c0b0a090807 ; shl 1 (16-15) / shr15
1891 dq 0x8786858483828100, 0x8f8e8d8c8b8a8988
1892 dq 0x0706050403020100, 0x000e0d0c0b0a0908
1895 dq 0x8080808080808080, 0x8080808080808080